-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdb.ts
More file actions
163 lines (152 loc) · 2.63 KB
/
Copy pathdb.ts
File metadata and controls
163 lines (152 loc) · 2.63 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import os from "os";
import path from "path";
import { INTEGER, NUMBER, Sequelize, STRING, ENUM, JSON, BOOLEAN } from "sequelize";
import { User, Time, Appointment, Organization, Connection } from "./models";
const sequelize = new Sequelize("kleo", "", undefined, {
dialect: "sqlite",
storage: path.join("db/temp.sqlite"),
logging: true
});
export enum Status {
available = "available",
pending="pending",
confirmed="confirmed",
unavailable="unavailable",
}
// Initialize all models.
User.init(
{
nonce: {
allowNull: false,
type: INTEGER.UNSIGNED, // SQLITE will use INTEGER
defaultValue: (): number => Math.floor(Math.random() * 10000) // Initialize with a random nonce
},
publicAddress: {
// polygon public address of the user
allowNull: false,
type: STRING,
unique: true,
validate: { isLowercase: true }
},
username: {
type: STRING, // user defined username
unique: true
}
},
{
modelName: "user",
sequelize, // This bit is important
timestamps: true
}
);
Time.init(
{
user: {
allowNull: true,
type: INTEGER.UNSIGNED // SQLITE will use INTEGER
},
status: {
allowNull: false,
type: STRING,
defaultValue: "unavailable" // Initialize with a unavailable status
},
timeStart: {
type: NUMBER // start time the user is available in epoch
},
timeEnd: {
type: NUMBER // end time the user is available in epoch
},
secret: {
type: STRING
}
},
{
modelName: "time",
sequelize, // This bit is important
timestamps: true
}
);
Appointment.init(
{
fromUser: {
allowNull: true,
type: NUMBER // SQLITE will use INTEGER
},
toUser: {
allowNull: true,
type: NUMBER
},
secret: {
type: STRING
},
status: {
type: ENUM,
values: [Status.available, Status.unavailable, Status.pending, Status.confirmed]
},
slot: {
type: STRING,
allowNull: true,
}
},
{
modelName: "appointment",
sequelize,
timestamps: true
}
);
Organization.init(
{
domainUrl: {
type: STRING,
allowNull: false,
unique: true,
},
inviteCode: {
type: STRING,
allowNull: false,
},
authorized: {
type: BOOLEAN,
},
intent: {
type: STRING,
},
intentGeneric: {
type: STRING,
},
formData: {
type: JSON
}
},
{
modelName: "organization",
sequelize,
timestamps: true
}
);
Connection.init(
{
userAddress: {
type: NUMBER
},
organizationId: {
type: NUMBER,
},
domainUrl: {
type: STRING,
unique: true,
allowNull: false,
},
connectData: {
type: JSON,
allowNull: true
}
},
{
modelName: "connection",
sequelize,
timestamps: true
}
);
sequelize.sync();
export { sequelize };