Created the AccessKey.ts model
This commit is contained in:
parent
bd6e5f4fd6
commit
e8cf7f4be7
44
src/models/AccessKey.ts
Normal file
44
src/models/AccessKey.ts
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import { model, ObjectId, Schema } from "mongoose";
|
||||||
|
import { fieldEncryption } from "mongoose-field-encryption";
|
||||||
|
import crypto from "crypto";
|
||||||
|
|
||||||
|
export enum IKeyRole {
|
||||||
|
VIEW,
|
||||||
|
MANAGE,
|
||||||
|
ADMIN
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IAccessKey {
|
||||||
|
projectId: ObjectId,
|
||||||
|
name: string,
|
||||||
|
role: IKeyRole,
|
||||||
|
token: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const AccessKeySchema = new Schema<IAccessKey>({
|
||||||
|
projectId: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
default: "Standardschlüssel",
|
||||||
|
},
|
||||||
|
role: {
|
||||||
|
type: Number,
|
||||||
|
default: IKeyRole.VIEW,
|
||||||
|
enum: IKeyRole,
|
||||||
|
},
|
||||||
|
token: {
|
||||||
|
type: String,
|
||||||
|
default: crypto.randomBytes(64).toString("hex"),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
AccessKeySchema.plugin(fieldEncryption, {
|
||||||
|
fields: ["projectId", "name", "role", "token"],
|
||||||
|
secret: process.env.ENC_KEY,
|
||||||
|
saltGenerator: () => process.env.SIG_KEY,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const AccessKey = model<IAccessKey>("access_keys", AccessKeySchema);
|
Loading…
x
Reference in New Issue
Block a user