UNPKG

777 BPlain TextView Raw
1import { Document, Schema, Model, model } from 'mongoose';
2import { ICommands as IDBCommands } from '../../Interfaces/Database/ICommands';
3
4const { Types } = Schema;
5
6export interface ICommandsModel extends IDBCommands, Document {}
7
8export const CommandsSchema: Schema<IDBCommands> = new Schema({
9 AllowedRoles: [ Types.String ],
10 AllowedChannels: [ Types.String ],
11 AllowedUsers: [ Types.String ],
12 AllowedGuilds: [ Types.String ],
13 CreatedAt: [ Types.Date ],
14 Data: Types.Mixed,
15 Namespace: Types.String
16});
17
18CommandsSchema.pre('save', function(next) {
19 const now = new Date();
20
21 // @ts-ignore
22 if (!this.CreatedAt) {
23 // @ts-ignore
24
25 this.CreatedAt = now;
26 }
27
28 next();
29});
30
31export const Commands: Model<ICommandsModel> = model<ICommandsModel>('Commands', CommandsSchema);