Skip to content

Commit 7e745cf

Browse files
author
DylanBulmer
committed
start documenting the organization model
1 parent c6f99f7 commit 7e745cf

4 files changed

Lines changed: 53 additions & 6 deletions

File tree

deno.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codr/models",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"exports": "./mod.ts",
55
"fmt": {
66
"lineWidth": 80,
@@ -10,7 +10,7 @@
1010
"singleQuote": false
1111
},
1212
"publish": {
13-
"exclude": [".github/*", "*.test.ts", ".gitignore"]
13+
"exclude": [".github/*", "tests/*.test.ts", ".gitignore"]
1414
},
1515
"imports": {
1616
"@std/assert": "jsr:@std/assert@^1.0.0",

src/mod.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
1-
// export files from here.
1+
/**
2+
* @module
3+
*
4+
* This module consists of class entities used to collect, transform, and
5+
* process data in Codr.
6+
*
7+
* @example
8+
* ```ts
9+
* import { Organization } from "@codr/models";
10+
* import { ObjectId } from "bson";
11+
*
12+
* const org = new Organization ({
13+
* name: "Demo Organization",
14+
* domains: ["localhost:3000"],
15+
* flags: {
16+
* isActive: true,
17+
* isDeleted: false,
18+
* isDemo: true,
19+
* },
20+
* slug: "demo",
21+
* createdBy: new ObjectId(),
22+
* })
23+
* ```
24+
*/
225

326
// export * as Types from "./types/mod.ts";
427
export * from "./models/mod.ts";

src/models/Organization.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,45 @@
11
import type { AtLeast } from "../types/mod.ts";
22
import { Base, type IBase } from "./Base.ts";
33

4+
/**
5+
* Flags used in the {@link IOrganization} interface.
6+
*/
47
interface OrganizationFlags {
8+
/** Whether or not the organization is active */
59
isActive: boolean;
10+
/** Whether or not the organization is soft deleted */
611
isDeleted: boolean;
12+
/** Whether or not the organization is a demo organization */
713
isDemo: boolean;
814
}
915

16+
/**
17+
* Parameters for building an {@link Organization} entity.
18+
*/
1019
export interface IOrganization extends IBase<"Organization"> {
11-
domains: string[]; // to restrict signin to a specified domain
20+
/** A list of domains (and ports) linked to the Organziation */
21+
domains: string[];
22+
/** Flags options for the organization */
1223
flags: OrganizationFlags;
24+
/** Name of the organization */
1325
name: string;
26+
/** Slug for generating subdomains for the organization */
1427
slug: string;
1528
}
1629

30+
/**
31+
* A class the represents an organization.
32+
*/
1733
export class Organization extends Base<"Organization"> {
1834
readonly domains: string[];
1935
readonly flags: OrganizationFlags;
2036
readonly name: string;
2137
readonly slug: string;
2238

39+
/**
40+
* Create an Organization entity.
41+
* @param params An object of required and optional parameters referenced from the {@link IOrganization} interface.
42+
*/
2343
constructor({
2444
flags = {
2545
isActive: true,
@@ -50,6 +70,10 @@ export class Organization extends Base<"Organization"> {
5070
this.slug = slug;
5171
}
5272

73+
/**
74+
* Transforms the organization class object to a json object. Useful for saving the entity to the database.
75+
* @returns a json representation of the organization.
76+
*/
5377
toJSON(): Omit<IOrganization, "kind"> {
5478
const json = super.toJSON();
5579
return {

tests/organization.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Deno.test("Create organziation", function createOrganization() {
66
const createdBy: ObjectId = new ObjectId();
77
const org = new Organization({
88
domains: ["localhost:3000"],
9-
name: "Demo Account",
9+
name: "Demo Organization",
1010
flags: {
1111
isActive: true,
1212
isDeleted: false,
@@ -16,7 +16,7 @@ Deno.test("Create organziation", function createOrganization() {
1616
createdBy,
1717
});
1818

19-
assertEquals(org.toJSON().name, "Demo Account");
19+
assertEquals(org.toJSON().name, "Demo Organization");
2020
assertEquals(org.toJSON().slug, "demo");
2121
assertEquals(org.toJSON().createdBy.toString(), createdBy.toString());
2222
assertEquals(org.toJSON().flags.isActive, true);

0 commit comments

Comments
 (0)