Added encryption to the Permission.ts model

This commit is contained in:
Mathias Wagner 2023-08-02 19:17:17 +02:00
parent 07723ec54f
commit 72014cadf6
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -1,4 +1,6 @@
import {model, ObjectId, Schema, Types} from "mongoose";
import {model, ObjectId, Schema} from "mongoose";
import { fieldEncryption } from "mongoose-field-encryption";
import process from "process";
export interface IPermission {
projectId: ObjectId,
@ -8,7 +10,7 @@ export interface IPermission {
const PermissionSchema = new Schema<IPermission>({
projectId: {
type: Types.ObjectId,
type: String,
required: true
},
permission: {
@ -21,4 +23,10 @@ const PermissionSchema = new Schema<IPermission>({
}
});
PermissionSchema.plugin(fieldEncryption, {
fields: ["projectId", "permission", "description"],
secret: process.env.ENC_KEY,
saltGenerator: () => process.env.SIG_KEY
});
export const Permission = model<IPermission>("permissions", PermissionSchema);