-
Notifications
You must be signed in to change notification settings - Fork 675
/
Copy pathRole.ts
executable file
·39 lines (34 loc) · 828 Bytes
/
Role.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Schema, model, Document } from 'mongoose';
export const DOCUMENT_NAME = 'Role';
export const COLLECTION_NAME = 'roles';
export const enum RoleCode {
LEARNER = 'LEARNER',
WRITER = 'WRITER',
EDITOR = 'EDITOR',
ADMIN = 'ADMIN',
}
export default interface Role extends Document {
code: string;
status?: boolean;
createdAt?: Date;
updatedAt?: Date;
}
Schema.Types.String.set('trim', true);
const schema = new Schema(
{
code: {
type: Schema.Types.String,
required: true,
enum: [RoleCode.LEARNER, RoleCode.WRITER, RoleCode.EDITOR, RoleCode.ADMIN],
},
status: {
type: Schema.Types.Boolean,
default: true,
},
},
{
versionKey: false,
},
);
schema.set('timestamps', true);
export const RoleModel = model<Role>(DOCUMENT_NAME, schema, COLLECTION_NAME);