diff --git a/src/models/Project.ts b/src/models/Project.ts new file mode 100644 index 0000000..efaa453 --- /dev/null +++ b/src/models/Project.ts @@ -0,0 +1,48 @@ +import { model, ObjectId, Schema } from "mongoose"; +import crypto from "crypto"; + +export enum IProjectPlan { + PERSONAL = "personal", PLUS = "plus", PRO = "pro" +} + +export interface IProjectDefaults { + licenseKey: string, + groups: string[], + permissions: string[], + expirationDate: Date, + maxUses: number +} + +export interface IProject { + _id: ObjectId, + name: string, + creatorId: ObjectId, + validationKey: string, + defaults: IProjectDefaults, + plan: IProjectPlan +} + +const ProjectSchema = new Schema({ + name: { + type: String, + required: true, + }, + creatorId: { + type: String, + required: true, + }, + validationKey: { + type: String, + default: () => crypto.randomBytes(24).toString("hex") + }, + defaults: { + type: Object, + default: { licenseKey: "NNUN-UUNN-UNAU-NAAN", groups: [], expirationDate: new Date(0), permissions: [], maxUses: -1 }, + }, + plan: { + type: String, + default: IProjectPlan.PERSONAL + } +}); + +export const Project = model("projects", ProjectSchema); \ No newline at end of file