This repository has been archived by the owner on Nov 16, 2021. It is now read-only.
generated from imhele/egg-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchat.ts
98 lines (95 loc) · 2.11 KB
/
chat.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { extendsModel } from '@/utils';
import { DefineModel } from '@/utils/types';
import { Application } from 'egg';
import { CHAR, INTEGER, Instance } from 'sequelize';
import yamlJoi from 'yaml-joi';
export interface Chat {
accountId: string;
chatId: string;
maxMsgId: number;
readMsgId: number;
/**
* account type
*/
type: number | null;
}
export const DefineChat: DefineModel<Chat> = {
Attr: {
accountId: {
type: CHAR(18),
allowNull: false,
},
chatId: {
type: CHAR(22),
allowNull: false,
},
maxMsgId: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
},
readMsgId: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
},
type: {
type: INTEGER,
defaultValue: null,
},
},
Sample: {
accountId: 'abcdefghijklmnopqr',
chatId: 'abcdefghijklmnopqrstuv',
maxMsgId: 0,
readMsgId: 0,
type: null,
},
Validator: yamlJoi(`
type: object
isSchema: true
limitation:
- keys:
accountId:
type: string
isSchema: true
limitation:
- length: 18
- token: []
chatId:
type: string
isSchema: true
limitation:
- length: 22
- token: []
maxMsgId:
type: number
isSchema: true
limitation:
- integer: []
- min: 0
readMsgId:
type: number
isSchema: true
limitation:
- integer: []
- min: 0
type:
type: number
isSchema: true
allowEmpty: "null"
limitation:
- integer: []
- min: 0
`),
};
export default (app: Application) => {
const ChatModel = app.model.define<Instance<Chat>, Chat>('Chat', DefineChat.Attr, {
indexes: [
{ name: 'accountIdIndex', fields: ['accountId'] },
{ name: 'chatIdIndex', fields: ['chatId'] },
],
});
ChatModel.removeAttribute('id');
return extendsModel(ChatModel);
};