@itleanchatbot/shared-models-js-postgres 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,428 @@
1
+ const { v4: uuidv4 } = require('uuid')
2
+
3
+ ;('use strict')
4
+
5
+ module.exports = {
6
+ up: async (queryInterface, Sequelize) => {
7
+ const { ENTERPRISE_CNPJ } = process.env
8
+
9
+ const EnterpriseId = await queryInterface.rawSelect(
10
+ 'Enterprises',
11
+ { where: { cnpj: ENTERPRISE_CNPJ } },
12
+ ['id']
13
+ )
14
+
15
+ const [systemUser] = await queryInterface.bulkInsert(
16
+ 'SystemUsers',
17
+ [
18
+ {
19
+ name: 'tranship.test.0001',
20
+ email: 'tranship.test@email.com',
21
+ password: '',
22
+ EnterpriseId,
23
+ maxSimultaneousAttendances: 10,
24
+ createdAt: new Date(),
25
+ updatedAt: new Date(),
26
+ },
27
+ ],
28
+ { returning: true }
29
+ )
30
+
31
+ await queryInterface.bulkInsert('SocketClients', [
32
+ {
33
+ SystemUserId: systemUser.id,
34
+ socketId: 'tranship.test.0001',
35
+ serverId: uuidv4(),
36
+ chatSession: 'tranship.test.0001',
37
+ protocol: 'tranship',
38
+ createdAt: new Date(),
39
+ updatedAt: new Date(),
40
+ },
41
+ ])
42
+
43
+ const ProfileId = await queryInterface.rawSelect(
44
+ 'Profiles',
45
+ { where: { name: 'Operador Desk' } },
46
+ ['id']
47
+ )
48
+
49
+ await queryInterface.bulkInsert(
50
+ 'SystemUsers_Profiles',
51
+ [
52
+ {
53
+ SystemUserId: systemUser.id,
54
+ ProfileId,
55
+ createdAt: new Date(),
56
+ updatedAt: new Date(),
57
+ },
58
+ ],
59
+ { returning: true }
60
+ )
61
+
62
+ const [branch] = await queryInterface.bulkInsert(
63
+ 'Branches',
64
+ [
65
+ {
66
+ EnterpriseId,
67
+ internalId: '20210607FIL',
68
+ name: 'Teste',
69
+ createdAt: new Date(),
70
+ updatedAt: new Date(),
71
+ },
72
+ ],
73
+ { returning: true }
74
+ )
75
+
76
+ const [department] = await queryInterface.bulkInsert(
77
+ 'Departments',
78
+ [
79
+ {
80
+ EnterpriseId,
81
+ internalId: '20210607DEP',
82
+ name: 'Teste',
83
+ createdAt: new Date(),
84
+ updatedAt: new Date(),
85
+ },
86
+ ],
87
+ { returning: true }
88
+ )
89
+
90
+ const [subDepartment_01, subDepartment_02] =
91
+ await queryInterface.bulkInsert(
92
+ 'SubDepartments',
93
+ [
94
+ {
95
+ EnterpriseId,
96
+ internalId: '20210607SUB',
97
+ name: 'Teste',
98
+ createdAt: new Date(),
99
+ updatedAt: new Date(),
100
+ },
101
+ {
102
+ EnterpriseId,
103
+ internalId: '20210608SUB',
104
+ name: 'Teste',
105
+ createdAt: new Date(),
106
+ updatedAt: new Date(),
107
+ },
108
+ ],
109
+ { returning: true }
110
+ )
111
+
112
+ const [line_01, line_02] = await queryInterface.bulkInsert(
113
+ 'Lines',
114
+ [
115
+ {
116
+ BranchId: branch.id,
117
+ DepartmentId: department.id,
118
+ SubDepartmentId: subDepartment_01.id,
119
+ createdAt: new Date(),
120
+ updatedAt: new Date(),
121
+ },
122
+ {
123
+ BranchId: branch.id,
124
+ DepartmentId: department.id,
125
+ SubDepartmentId: subDepartment_02.id,
126
+ createdAt: new Date(),
127
+ updatedAt: new Date(),
128
+ },
129
+ ],
130
+ { returning: true }
131
+ )
132
+
133
+ await queryInterface.bulkInsert('SystemUsers_Lines', [
134
+ {
135
+ LineId: line_02.id,
136
+ SystemUserId: systemUser.id,
137
+ createdAt: new Date(),
138
+ updatedAt: new Date(),
139
+ },
140
+ ])
141
+
142
+ await queryInterface.bulkInsert('LineConfigurations', [
143
+ {
144
+ LineId: line_01.id,
145
+ transfer: true,
146
+ autoDistribution: false,
147
+ sendEmoji: false,
148
+ sendAttachment: false,
149
+ activateSystemUserMaxResponseTime: false,
150
+ systemUserMaxResponseTimeInMinutes: 0,
151
+ activateUserMaxResponseTime: false,
152
+ userMaxResponseTimeInMinutes: 0,
153
+ createdAt: new Date(),
154
+ updatedAt: new Date(),
155
+ },
156
+ {
157
+ LineId: line_02.id,
158
+ transfer: true,
159
+ autoDistribution: true,
160
+ sendEmoji: false,
161
+ sendAttachment: false,
162
+ activateSystemUserMaxResponseTime: false,
163
+ systemUserMaxResponseTimeInMinutes: 0,
164
+ activateUserMaxResponseTime: false,
165
+ userMaxResponseTimeInMinutes: 0,
166
+ createdAt: new Date(),
167
+ updatedAt: new Date(),
168
+ },
169
+ ])
170
+
171
+ const ItleanProviderId = await queryInterface.rawSelect(
172
+ 'ItleanProviders',
173
+ { where: { EnterpriseId } },
174
+ ['id']
175
+ )
176
+
177
+ const IntelligenceId = await queryInterface.rawSelect(
178
+ 'Intelligences',
179
+ { where: { providerType: 'itlean' } },
180
+ ['id']
181
+ )
182
+
183
+ const [skill] = await queryInterface.bulkInsert(
184
+ 'Skills',
185
+ [
186
+ {
187
+ name: `tranship.test.0001`,
188
+ lang: 'pt-br',
189
+ description: `fake-description-test${Date.now()}`,
190
+ IntelligenceId,
191
+ ItleanProviderId,
192
+ createdAt: new Date(),
193
+ updatedAt: new Date(),
194
+ },
195
+ ],
196
+ { returning: true }
197
+ )
198
+
199
+ const ChannelTypeId = await queryInterface.rawSelect(
200
+ 'ChannelTypes',
201
+ { where: { channelName: 'webchat' } },
202
+ ['id']
203
+ )
204
+
205
+ const serverId = uuidv4()
206
+
207
+ const [channel] = await queryInterface.bulkInsert(
208
+ 'Channels',
209
+ [
210
+ {
211
+ SkillId: skill.id,
212
+ ChannelTypeId,
213
+ name: 'tranship.test.0001',
214
+ configurations: JSON.stringify({
215
+ domainName: 'tranship.test.0001',
216
+ displayName: 'Teste',
217
+ sendAttachments: false,
218
+ componentsColor: '#000000',
219
+ backgroundColor: '#000000',
220
+ fontColor: '#000000',
221
+ serverId,
222
+ }),
223
+ createdAt: new Date(),
224
+ updatedAt: new Date(),
225
+ },
226
+ ],
227
+ { returning: true }
228
+ )
229
+
230
+ const [dialogNode_01, dialogNode_02] = await queryInterface.bulkInsert(
231
+ 'DialogNodes',
232
+ [
233
+ {
234
+ name: 'tranship_test_0001',
235
+ condition: 'true',
236
+ step: 1,
237
+ replayWait: true,
238
+ JumpToDialogNodeId: null,
239
+ JumpToSkillId: null,
240
+ SkillId: skill.id,
241
+ DialogNodeFolderId: null,
242
+ type: 'tranship',
243
+ isMultipleResponse: false,
244
+ contexts: '[]',
245
+ hasMultipleResponse: false,
246
+ createdAt: new Date(),
247
+ updatedAt: new Date(),
248
+ },
249
+ {
250
+ name: 'tranship_test_0002',
251
+ condition: 'true',
252
+ step: 2,
253
+ replayWait: true,
254
+ JumpToDialogNodeId: null,
255
+ JumpToSkillId: null,
256
+ SkillId: skill.id,
257
+ DialogNodeFolderId: null,
258
+ type: 'tranship',
259
+ isMultipleResponse: false,
260
+ contexts: '[]',
261
+ hasMultipleResponse: false,
262
+ createdAt: new Date(),
263
+ updatedAt: new Date(),
264
+ },
265
+ ],
266
+ { returning: true }
267
+ )
268
+
269
+ await queryInterface.bulkInsert('TranshipTriggers', [
270
+ {
271
+ DialogNodeId: dialogNode_01.id,
272
+ branch: '$fil',
273
+ department: '$dep',
274
+ subDepartment: '$sub',
275
+ clientData: JSON.stringify([
276
+ {
277
+ label: 'Teste',
278
+ value: '$teste',
279
+ },
280
+ ]),
281
+ createdAt: new Date(),
282
+ updatedAt: new Date(),
283
+ },
284
+ {
285
+ DialogNodeId: dialogNode_02.id,
286
+ branch: '$fil',
287
+ department: '$dep',
288
+ subDepartment: '$sub',
289
+ clientData: JSON.stringify([
290
+ {
291
+ label: 'Teste',
292
+ value: '$teste',
293
+ },
294
+ ]),
295
+ createdAt: new Date(),
296
+ updatedAt: new Date(),
297
+ },
298
+ ])
299
+
300
+ const [client] = await queryInterface.bulkInsert(
301
+ 'Clients',
302
+ [
303
+ {
304
+ clientId: 'tranship.test.0001',
305
+ serverId,
306
+ createdAt: new Date(),
307
+ updatedAt: new Date(),
308
+ },
309
+ ],
310
+ { returning: true }
311
+ )
312
+
313
+ await queryInterface.bulkInsert('Sessions', [
314
+ {
315
+ ChannelId: channel.id,
316
+ ClientId: client.id,
317
+ tranship: false,
318
+ status: 'open',
319
+ endOfSession: new Date(),
320
+ createdAt: new Date(),
321
+ updatedAt: new Date(),
322
+ },
323
+ ])
324
+ },
325
+
326
+ down: async (queryInterface, Sequelize) => {
327
+ const ChannelId = await queryInterface.rawSelect(
328
+ 'Channels',
329
+ { where: { name: 'tranship.test.0001' } },
330
+ ['id']
331
+ )
332
+
333
+ const SkillId = await queryInterface.rawSelect(
334
+ 'Skills',
335
+ { where: { name: 'tranship.test.0001' } },
336
+ ['id']
337
+ )
338
+
339
+ const DialogNodeId_01 = await queryInterface.rawSelect(
340
+ 'DialogNodes',
341
+ { where: { SkillId, name: 'tranship_test_0001', step: 1 } },
342
+ ['id']
343
+ )
344
+
345
+ const DialogNodeId_02 = await queryInterface.rawSelect(
346
+ 'DialogNodes',
347
+ { where: { SkillId, name: 'tranship_test_0002', step: 2 } },
348
+ ['id']
349
+ )
350
+
351
+ const BranchId = await queryInterface.rawSelect(
352
+ 'Branches',
353
+ { where: { internalId: '20210607FIL' } },
354
+ ['id']
355
+ )
356
+
357
+ const DepartmentId = await queryInterface.rawSelect(
358
+ 'Departments',
359
+ { where: { internalId: '20210607DEP' } },
360
+ ['id']
361
+ )
362
+
363
+ const SubDepartmentId_01 = await queryInterface.rawSelect(
364
+ 'SubDepartments',
365
+ { where: { internalId: '20210607SUB' } },
366
+ ['id']
367
+ )
368
+
369
+ const SubDepartmentId_02 = await queryInterface.rawSelect(
370
+ 'SubDepartments',
371
+ { where: { internalId: '20210608SUB' } },
372
+ ['id']
373
+ )
374
+
375
+ const LineId_01 = await queryInterface.rawSelect(
376
+ 'Lines',
377
+ {
378
+ where: { BranchId, DepartmentId, SubDepartmentId: SubDepartmentId_01 },
379
+ },
380
+ ['id']
381
+ )
382
+
383
+ const LineId_02 = await queryInterface.rawSelect(
384
+ 'Lines',
385
+ {
386
+ where: { BranchId, DepartmentId, SubDepartmentId: SubDepartmentId_02 },
387
+ },
388
+ ['id']
389
+ )
390
+
391
+ const SystemUserId = await queryInterface.rawSelect(
392
+ 'SystemUsers',
393
+ { where: { name: 'tranship.test.0001' } },
394
+ ['id']
395
+ )
396
+
397
+ await queryInterface.bulkDelete('Sessions', { ChannelId })
398
+ await queryInterface.bulkDelete('Clients', {
399
+ clientId: 'tranship.test.0001',
400
+ })
401
+ await queryInterface.bulkDelete('TranshipTriggers', {
402
+ DialogNodeId: DialogNodeId_01,
403
+ })
404
+ await queryInterface.bulkDelete('TranshipTriggers', {
405
+ DialogNodeId: DialogNodeId_02,
406
+ })
407
+ await queryInterface.bulkDelete('DialogNodes', { id: DialogNodeId_01 })
408
+ await queryInterface.bulkDelete('DialogNodes', { id: DialogNodeId_02 })
409
+ await queryInterface.bulkDelete('Channels', { id: ChannelId })
410
+ await queryInterface.bulkDelete('Skills', { id: SkillId })
411
+ await queryInterface.bulkDelete('LineConfigurations', { LineId: LineId_01 })
412
+ await queryInterface.bulkDelete('LineConfigurations', { LineId: LineId_02 })
413
+ await queryInterface.bulkDelete('SystemUsers_Lines', { LineId: LineId_02 })
414
+ await queryInterface.bulkDelete('Lines', { id: LineId_01 })
415
+ await queryInterface.bulkDelete('Lines', { id: LineId_02 })
416
+ await queryInterface.bulkDelete('Branches', { id: BranchId })
417
+ await queryInterface.bulkDelete('Departments', { id: DepartmentId })
418
+ await queryInterface.bulkDelete('SubDepartments', {
419
+ id: SubDepartmentId_01,
420
+ })
421
+ await queryInterface.bulkDelete('SubDepartments', {
422
+ id: SubDepartmentId_02,
423
+ })
424
+ await queryInterface.bulkDelete('SystemUsers_Profiles', { SystemUserId })
425
+ await queryInterface.bulkDelete('SocketClients', { SystemUserId })
426
+ await queryInterface.bulkDelete('SystemUsers', { id: SystemUserId })
427
+ },
428
+ }