1 | import { Document, Schema, Model, model } from 'mongoose';
|
2 | import { IUsers } from '../../Interfaces/Database/IUsers';
|
3 |
|
4 | const { Types } = Schema;
|
5 |
|
6 | export interface IUsersModel extends IUsers, Document {}
|
7 |
|
8 | const UsersSchema: Schema = new Schema({
|
9 | CreatedAt: Types.Date,
|
10 | Name: Types.String,
|
11 | Roles: [ Types.String ]
|
12 | });
|
13 |
|
14 | UsersSchema.pre('save', function(next) {
|
15 | const now = new Date();
|
16 |
|
17 |
|
18 | if (!this.CreatedAt) {
|
19 |
|
20 |
|
21 | this.CreatedAt = now;
|
22 | }
|
23 |
|
24 | next();
|
25 | });
|
26 |
|
27 | export const Users: Model<IUsersModel> = model<IUsersModel>('Users', UsersSchema);
|