Skip to content

Commit

Permalink
start documenting the organization model
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanBulmer committed Jul 20, 2024
1 parent c6f99f7 commit 7e745cf
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
4 changes: 2 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codr/models",
"version": "0.1.3",
"version": "0.1.4",
"exports": "./mod.ts",
"fmt": {
"lineWidth": 80,
Expand All @@ -10,7 +10,7 @@
"singleQuote": false
},
"publish": {
"exclude": [".github/*", "*.test.ts", ".gitignore"]
"exclude": [".github/*", "tests/*.test.ts", ".gitignore"]
},
"imports": {
"@std/assert": "jsr:@std/assert@^1.0.0",
Expand Down
25 changes: 24 additions & 1 deletion src/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
// export files from here.
/**
* @module
*
* This module consists of class entities used to collect, transform, and
* process data in Codr.
*
* @example
* ```ts
* import { Organization } from "@codr/models";
* import { ObjectId } from "bson";
*
* const org = new Organization ({
* name: "Demo Organization",
* domains: ["localhost:3000"],
* flags: {
* isActive: true,
* isDeleted: false,
* isDemo: true,
* },
* slug: "demo",
* createdBy: new ObjectId(),
* })
* ```
*/

// export * as Types from "./types/mod.ts";
export * from "./models/mod.ts";
26 changes: 25 additions & 1 deletion src/models/Organization.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
import type { AtLeast } from "../types/mod.ts";
import { Base, type IBase } from "./Base.ts";

/**
* Flags used in the {@link IOrganization} interface.
*/
interface OrganizationFlags {
/** Whether or not the organization is active */
isActive: boolean;
/** Whether or not the organization is soft deleted */
isDeleted: boolean;
/** Whether or not the organization is a demo organization */
isDemo: boolean;
}

/**
* Parameters for building an {@link Organization} entity.
*/
export interface IOrganization extends IBase<"Organization"> {
domains: string[]; // to restrict signin to a specified domain
/** A list of domains (and ports) linked to the Organziation */
domains: string[];
/** Flags options for the organization */
flags: OrganizationFlags;
/** Name of the organization */
name: string;
/** Slug for generating subdomains for the organization */
slug: string;
}

/**
* A class the represents an organization.
*/
export class Organization extends Base<"Organization"> {
readonly domains: string[];
readonly flags: OrganizationFlags;
readonly name: string;
readonly slug: string;

/**
* Create an Organization entity.
* @param params An object of required and optional parameters referenced from the {@link IOrganization} interface.
*/
constructor({
flags = {
isActive: true,
Expand Down Expand Up @@ -50,6 +70,10 @@ export class Organization extends Base<"Organization"> {
this.slug = slug;
}

/**
* Transforms the organization class object to a json object. Useful for saving the entity to the database.
* @returns a json representation of the organization.
*/
toJSON(): Omit<IOrganization, "kind"> {
const json = super.toJSON();
return {
Expand Down
4 changes: 2 additions & 2 deletions tests/organization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Deno.test("Create organziation", function createOrganization() {
const createdBy: ObjectId = new ObjectId();
const org = new Organization({
domains: ["localhost:3000"],
name: "Demo Account",
name: "Demo Organization",
flags: {
isActive: true,
isDeleted: false,
Expand All @@ -16,7 +16,7 @@ Deno.test("Create organziation", function createOrganization() {
createdBy,
});

assertEquals(org.toJSON().name, "Demo Account");
assertEquals(org.toJSON().name, "Demo Organization");
assertEquals(org.toJSON().slug, "demo");
assertEquals(org.toJSON().createdBy.toString(), createdBy.toString());
assertEquals(org.toJSON().flags.isActive, true);
Expand Down

0 comments on commit 7e745cf

Please sign in to comment.