Updated the Project.ts model
This commit is contained in:
parent
30e02b9dd6
commit
122b14d748
@ -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 {
|
export interface IProject {
|
||||||
_id: ObjectId,
|
_id: ObjectId,
|
||||||
name: string
|
name: string,
|
||||||
|
creatorId: ObjectId,
|
||||||
|
validationKey: string,
|
||||||
|
defaults: IProjectDefaults
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProjectSchema = new Schema<IProject>({
|
const ProjectSchema = new Schema<IProject>({
|
||||||
name: {
|
name: {
|
||||||
type: String,
|
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<IProject>("projects", ProjectSchema);
|
export const Project = model<IProject>("projects", ProjectSchema);
|
Loading…
x
Reference in New Issue
Block a user