UNPKG

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