From 7e745cff495d0fe5b8b178b9d57ba7b1f7fc9b0d Mon Sep 17 00:00:00 2001
From: DylanBulmer <dylan@bulmersolutions.com>
Date: Sat, 20 Jul 2024 13:36:03 -0400
Subject: [PATCH] start documenting the organization model

---
 deno.json                  |  4 ++--
 src/mod.ts                 | 25 ++++++++++++++++++++++++-
 src/models/Organization.ts | 26 +++++++++++++++++++++++++-
 tests/organization.test.ts |  4 ++--
 4 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/deno.json b/deno.json
index 0902deb..7ee580d 100644
--- a/deno.json
+++ b/deno.json
@@ -1,6 +1,6 @@
 {
   "name": "@codr/models",
-  "version": "0.1.3",
+  "version": "0.1.4",
   "exports": "./mod.ts",
   "fmt": {
     "lineWidth": 80,
@@ -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",
diff --git a/src/mod.ts b/src/mod.ts
index 1505932..38b9724 100644
--- a/src/mod.ts
+++ b/src/mod.ts
@@ -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";
diff --git a/src/models/Organization.ts b/src/models/Organization.ts
index 9bf0c6f..c24dc79 100644
--- a/src/models/Organization.ts
+++ b/src/models/Organization.ts
@@ -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,
@@ -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 {
diff --git a/tests/organization.test.ts b/tests/organization.test.ts
index b1fa690..7363877 100644
--- a/tests/organization.test.ts
+++ b/tests/organization.test.ts
@@ -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,
@@ -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);