1 | import { Document, Schema, Model, model } from 'mongoose';
|
2 | import { ICommands as IDBCommands } from '../../Interfaces/Database/ICommands';
|
3 |
|
4 | const { Types } = Schema;
|
5 |
|
6 | export interface ICommandsModel extends IDBCommands, Document {}
|
7 |
|
8 | export 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 |
|
18 | CommandsSchema.pre('save', function(next) {
|
19 | const now = new Date();
|
20 |
|
21 |
|
22 | if (!this.CreatedAt) {
|
23 |
|
24 |
|
25 | this.CreatedAt = now;
|
26 | }
|
27 |
|
28 | next();
|
29 | });
|
30 |
|
31 | export const Commands: Model<ICommandsModel> = model<ICommandsModel>('Commands', CommandsSchema);
|