This repository has been archived by the owner on Nov 27, 2022. It is now read-only.
forked from Urigo/WhatsApp-Clone-Server
-
Notifications
You must be signed in to change notification settings - Fork 3
/
db.ts
executable file
·301 lines (281 loc) · 8.21 KB
/
db.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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
// For TypeORM
import "reflect-metadata";
import { Chat } from "./entity/Chat";
import { Recipient } from "./entity/Recipient";
import moment from 'moment';
import { Message } from "./entity/Message";
import { User } from "./entity/User";
import { Connection } from "typeorm";
export enum MessageType {
PICTURE,
TEXT,
LOCATION,
}
export async function addSampleData(connection: Connection) {
const user1 = new User({
username: 'ethan',
password: '$2a$08$NO9tkFLCoSqX1c5wk3s7z.JfxaVMKA.m7zUDdDwEquo4rvzimQeJm', // 111
name: 'Ethan Gonzalez',
picture: 'https://randomuser.me/api/portraits/thumb/men/1.jpg',
phone: '+391234567890',
});
await connection.manager.save(user1);
const user2 = new User({
username: 'bryan',
password: '$2a$08$xE4FuCi/ifxjL2S8CzKAmuKLwv18ktksSN.F3XYEnpmcKtpbpeZgO', // 222
name: 'Bryan Wallace',
picture: 'https://randomuser.me/api/portraits/thumb/men/2.jpg',
phone: '+391234567891',
});
await connection.manager.save(user2);
const user3 = new User({
username: 'avery',
password: '$2a$08$UHgH7J8G6z1mGQn2qx2kdeWv0jvgHItyAsL9hpEUI3KJmhVW5Q1d.', // 333
name: 'Avery Stewart',
picture: 'https://randomuser.me/api/portraits/thumb/women/1.jpg',
phone: '+391234567892',
});
await connection.manager.save(user3);
const user4 = new User({
username: 'katie',
password: '$2a$08$wR1k5Q3T9FC7fUgB7Gdb9Os/GV7dGBBf4PLlWT7HERMFhmFDt47xi', // 444
name: 'Katie Peterson',
picture: 'https://randomuser.me/api/portraits/thumb/women/2.jpg',
phone: '+391234567893',
});
await connection.manager.save(user4);
const user5 = new User({
username: 'ray',
password: '$2a$08$6.mbXqsDX82ZZ7q5d8Osb..JrGSsNp4R3IKj7mxgF6YGT0OmMw242', // 555
name: 'Ray Edwards',
picture: 'https://randomuser.me/api/portraits/thumb/men/3.jpg',
phone: '+391234567894',
});
await connection.manager.save(user5);
const user6 = new User({
username: 'niko',
password: '$2a$08$fL5lZR.Rwf9FWWe8XwwlceiPBBim8n9aFtaem.INQhiKT4.Ux3Uq.', // 666
name: 'Niccolò Belli',
picture: 'https://randomuser.me/api/portraits/thumb/men/4.jpg',
phone: '+391234567895',
});
await connection.manager.save(user6);
const user7 = new User({
username: 'mario',
password: '$2a$08$nDHDmWcVxDnH5DDT3HMMC.psqcnu6wBiOgkmJUy9IH..qxa3R6YrO', // 777
name: 'Mario Rossi',
picture: 'https://randomuser.me/api/portraits/thumb/men/5.jpg',
phone: '+391234567896',
});
await connection.manager.save(user7);
await connection.manager.save(new Chat({
createdAt: moment().subtract(10, 'weeks').toDate(),
allTimeMembers: [user1, user3],
listingMembers: [user1, user3],
messages: [
new Message({
sender: user1,
content: 'You on your way?',
createdAt: moment().subtract(1, 'hours').toDate(),
type: MessageType.TEXT,
holders: [user1, user3],
recipients: [
new Recipient({
user: user3,
}),
],
}),
new Message({
sender: user3,
content: 'Yep!',
createdAt: moment().subtract(1, 'hours').add(5, 'minutes').toDate(),
type: MessageType.TEXT,
holders: [user1, user3],
recipients: [
new Recipient({
user: user1,
}),
],
}),
],
}));
await connection.manager.save(new Chat({
createdAt: moment().subtract(9, 'weeks').toDate(),
allTimeMembers: [user1, user4],
listingMembers: [user1, user4],
messages: [
new Message({
sender: user1,
content: 'Hey, it\'s me',
createdAt: moment().subtract(2, 'hours').toDate(),
type: MessageType.TEXT,
holders: [user1, user4],
recipients: [
new Recipient({
user: user4,
}),
],
}),
],
}));
await connection.manager.save(new Chat({
createdAt: moment().subtract(8, 'weeks').toDate(),
allTimeMembers: [user1, user5],
listingMembers: [user1, user5],
messages: [
new Message({
sender: user1,
content: 'I should buy a boat',
createdAt: moment().subtract(1, 'days').toDate(),
type: MessageType.TEXT,
holders: [user1, user5],
recipients: [
new Recipient({
user: user5,
}),
],
}),
new Message({
sender: user1,
content: 'You still there?',
createdAt: moment().subtract(1, 'days').add(16, 'hours').toDate(),
type: MessageType.TEXT,
holders: [user1, user5],
recipients: [
new Recipient({
user: user5,
}),
],
}),
],
}));
await connection.manager.save(new Chat({
createdAt: moment().subtract(7, 'weeks').toDate(),
allTimeMembers: [user3, user4],
listingMembers: [user3, user4],
messages: [
new Message({
sender: user3,
content: 'Look at my mukluks!',
createdAt: moment().subtract(4, 'days').toDate(),
type: MessageType.TEXT,
holders: [user3, user4],
recipients: [
new Recipient({
user: user4,
}),
],
}),
],
}));
await connection.manager.save(new Chat({
createdAt: moment().subtract(6, 'weeks').toDate(),
allTimeMembers: [user2, user5],
listingMembers: [user2, user5],
messages: [
new Message({
sender: user2,
content: 'This is wicked good ice cream.',
createdAt: moment().subtract(2, 'weeks').toDate(),
type: MessageType.TEXT,
holders: [user2, user5],
recipients: [
new Recipient({
user: user5,
}),
],
}),
new Message({
sender: user5,
content: 'Love it!',
createdAt: moment().subtract(2, 'weeks').add(10, 'minutes').toDate(),
type: MessageType.TEXT,
holders: [user2, user5],
recipients: [
new Recipient({
user: user2,
}),
],
}),
],
}));
await connection.manager.save(new Chat({
createdAt: moment().subtract(5, 'weeks').toDate(),
allTimeMembers: [user1, user6],
listingMembers: [user1],
}));
await connection.manager.save(new Chat({
createdAt: moment().subtract(4, 'weeks').toDate(),
allTimeMembers: [user2, user1],
listingMembers: [user2],
}));
await connection.manager.save(new Chat({
createdAt: moment().subtract(3, 'weeks').toDate(),
name: 'Ethan\'s group',
picture: 'https://randomuser.me/api/portraits/thumb/lego/1.jpg',
allTimeMembers: [user1, user3, user4, user6],
listingMembers: [user1, user3, user4, user6],
actualGroupMembers: [user1, user4, user6],
admins: [user1, user6],
owner: user1,
messages: [
new Message({
sender: user1,
content: 'I made a group',
createdAt: moment().subtract(2, 'weeks').toDate(),
type: MessageType.TEXT,
holders: [user1, user3, user4, user6],
recipients: [
new Recipient({
user: user3,
}),
new Recipient({
user: user4,
}),
new Recipient({
user: user6,
}),
],
}),
new Message({
sender: user1,
content: 'Ops, Avery was not supposed to be here',
createdAt: moment().subtract(2, 'weeks').add(2, 'minutes').toDate(),
type: MessageType.TEXT,
holders: [user1, user4, user6],
recipients: [
new Recipient({
user: user4,
}),
new Recipient({
user: user6,
}),
],
}),
new Message({
sender: user4,
content: 'Awesome!',
createdAt: moment().subtract(2, 'weeks').add(10, 'minutes').toDate(),
type: MessageType.TEXT,
holders: [user1, user4, user6],
recipients: [
new Recipient({
user: user1,
}),
new Recipient({
user: user6,
}),
],
}),
],
}));
await connection.manager.save(new Chat({
createdAt: moment().subtract(2, 'weeks').toDate(),
name: 'Ray\'s group',
allTimeMembers: [user3, user6],
listingMembers: [user3, user6],
actualGroupMembers: [user3, user6],
admins: [user6],
owner: user6,
}));
}