From 122b14d748b8663038f4ba3a3cfa7237140efd8c Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sun, 22 Jan 2023 01:02:50 +0100 Subject: [PATCH] Updated the Project.ts model --- src/models/Project.ts | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/models/Project.ts b/src/models/Project.ts index c995be6..ff84e95 100644 --- a/src/models/Project.ts +++ b/src/models/Project.ts @@ -1,15 +1,45 @@ -import {model, ObjectId, Schema} from "mongoose"; +import { model, ObjectId, Schema } from "mongoose"; +import crypto from "crypto"; +import { fieldEncryption } from "mongoose-field-encryption"; + +export interface IProjectDefaults { + licenseKey: string, + groups: string[], + permissions: string[], + expirationDate: Date +} export interface IProject { _id: ObjectId, - name: string + name: string, + creatorId: ObjectId, + validationKey: string, + defaults: IProjectDefaults } const ProjectSchema = new Schema({ name: { type: String, - required: true - } + 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: [] }, + }, +}); + +ProjectSchema.plugin(fieldEncryption, { + fields: ["name", "creatorId", "validationKey", "defaults"], + secret: process.env.ENC_KEY, + saltGenerator: () => process.env.SIG_KEY }); export const Project = model("projects", ProjectSchema); \ No newline at end of file