-
Notifications
You must be signed in to change notification settings - Fork 675
/
Copy pathApiKey.ts
executable file
·45 lines (41 loc) · 906 Bytes
/
ApiKey.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
40
41
42
43
44
45
import { Schema, model, Document } from 'mongoose';
export const DOCUMENT_NAME = 'ApiKey';
export const COLLECTION_NAME = 'api_keys';
export default interface ApiKey extends Document {
key: string;
version: number;
metadata: string;
status?: boolean;
createdAt?: Date;
updatedAt?: Date;
}
Schema.Types.String.set('trim', true);
const schema = new Schema(
{
key: {
type: Schema.Types.String,
required: true,
unique: true,
maxlength: 1024,
},
version: {
type: Schema.Types.Number,
required: true,
min: 1,
max: 100,
},
metadata: {
type: Schema.Types.String,
required: true,
},
status: {
type: Schema.Types.Boolean,
default: true,
},
},
{
versionKey: false,
},
);
schema.set('timestamps', true);
export const ApiKeyModel = model<ApiKey>(DOCUMENT_NAME, schema, COLLECTION_NAME);