@itleanchatbot/shared-models-js-postgres 2.8.11 → 2.8.13
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.
- package/package.json +1 -1
- package/src/migrations/20211119123119-CreateApiPreRequest.js +66 -66
- package/src/migrations/20220118131507-alter-table-SystemUsers-isActive.js +20 -20
- package/src/migrations/20220121145703-alter-table-botiterable.js +28 -28
- package/src/migrations/20220126141248-alter-table-sessions-session-start.js +14 -14
- package/src/migrations/20220215123711-alter-table-conversation-sessions.js +15 -15
- package/src/migrations/20220301115430-create-sessionsPreReports.js +58 -0
- package/src/migrations/20220301115530-alter-sessions.js +14 -0
- package/src/migrations/20220303152530-create-dialogNodesPreReports.js +46 -0
- package/src/migrations/20220308145105-alter-table-transhipConversation-mimetype.js +16 -16
- package/src/migrations/20220309145730-create-function.js +116 -0
- package/src/models/dialogNodes.js +1 -0
- package/src/models/dialogNodesPreReports.js +35 -0
- package/src/models/faqQuestions.js +31 -31
- package/src/models/openFaqs.js +33 -33
- package/src/models/sessions.js +9 -0
- package/src/models/sessionsPreReports.js +43 -0
- package/src/seeders/20220221142239-add-permissions-to-adm.js +98 -98
- package/src/seeders/test/20210224165819-create-skill-framework.js +41 -41
- package/src/seeders/test/20210301174809-create-dialog-node-framework.js +43 -43
- package/src/seeders/test/20211122141406-api-pre-request.js +201 -201
package/package.json
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
up: async (queryInterface, Sequelize) => {
|
|
5
|
-
await queryInterface.createTable('ApiPreRequests', {
|
|
6
|
-
id: {
|
|
7
|
-
allowNull: false,
|
|
8
|
-
defaultValue: Sequelize.literal('uuid_generate_v4()'),
|
|
9
|
-
primaryKey: true,
|
|
10
|
-
type: Sequelize.UUID,
|
|
11
|
-
},
|
|
12
|
-
ApiId: {
|
|
13
|
-
allowNull: true,
|
|
14
|
-
defaultValue: null,
|
|
15
|
-
type: Sequelize.UUID,
|
|
16
|
-
references: {
|
|
17
|
-
model: 'Apis',
|
|
18
|
-
key: 'id',
|
|
19
|
-
},
|
|
20
|
-
onDelete: 'SET NULL',
|
|
21
|
-
onUpdate: 'CASCADE',
|
|
22
|
-
},
|
|
23
|
-
ApiResourceId: {
|
|
24
|
-
allowNull: true,
|
|
25
|
-
defaultValue: null,
|
|
26
|
-
type: Sequelize.UUID,
|
|
27
|
-
references: {
|
|
28
|
-
model: 'ApiResources',
|
|
29
|
-
key: 'id',
|
|
30
|
-
},
|
|
31
|
-
onDelete: 'SET NULL',
|
|
32
|
-
onUpdate: 'CASCADE',
|
|
33
|
-
},
|
|
34
|
-
PreApiResourceId: {
|
|
35
|
-
allowNull: false,
|
|
36
|
-
type: Sequelize.UUID,
|
|
37
|
-
references: {
|
|
38
|
-
model: 'ApiResources',
|
|
39
|
-
key: 'id',
|
|
40
|
-
},
|
|
41
|
-
onDelete: 'SET NULL',
|
|
42
|
-
onUpdate: 'CASCADE',
|
|
43
|
-
},
|
|
44
|
-
result: {
|
|
45
|
-
allowNull: false,
|
|
46
|
-
type: Sequelize.STRING,
|
|
47
|
-
},
|
|
48
|
-
delayForNewRequest: {
|
|
49
|
-
allowNull: false,
|
|
50
|
-
type: Sequelize.STRING,
|
|
51
|
-
},
|
|
52
|
-
createdAt: {
|
|
53
|
-
allowNull: false,
|
|
54
|
-
type: Sequelize.DATE,
|
|
55
|
-
},
|
|
56
|
-
updatedAt: {
|
|
57
|
-
allowNull: false,
|
|
58
|
-
type: Sequelize.DATE,
|
|
59
|
-
},
|
|
60
|
-
})
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
down: async (queryInterface) => {
|
|
64
|
-
await queryInterface.dropTable('ApiPreRequests')
|
|
65
|
-
}
|
|
66
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
up: async (queryInterface, Sequelize) => {
|
|
5
|
+
await queryInterface.createTable('ApiPreRequests', {
|
|
6
|
+
id: {
|
|
7
|
+
allowNull: false,
|
|
8
|
+
defaultValue: Sequelize.literal('uuid_generate_v4()'),
|
|
9
|
+
primaryKey: true,
|
|
10
|
+
type: Sequelize.UUID,
|
|
11
|
+
},
|
|
12
|
+
ApiId: {
|
|
13
|
+
allowNull: true,
|
|
14
|
+
defaultValue: null,
|
|
15
|
+
type: Sequelize.UUID,
|
|
16
|
+
references: {
|
|
17
|
+
model: 'Apis',
|
|
18
|
+
key: 'id',
|
|
19
|
+
},
|
|
20
|
+
onDelete: 'SET NULL',
|
|
21
|
+
onUpdate: 'CASCADE',
|
|
22
|
+
},
|
|
23
|
+
ApiResourceId: {
|
|
24
|
+
allowNull: true,
|
|
25
|
+
defaultValue: null,
|
|
26
|
+
type: Sequelize.UUID,
|
|
27
|
+
references: {
|
|
28
|
+
model: 'ApiResources',
|
|
29
|
+
key: 'id',
|
|
30
|
+
},
|
|
31
|
+
onDelete: 'SET NULL',
|
|
32
|
+
onUpdate: 'CASCADE',
|
|
33
|
+
},
|
|
34
|
+
PreApiResourceId: {
|
|
35
|
+
allowNull: false,
|
|
36
|
+
type: Sequelize.UUID,
|
|
37
|
+
references: {
|
|
38
|
+
model: 'ApiResources',
|
|
39
|
+
key: 'id',
|
|
40
|
+
},
|
|
41
|
+
onDelete: 'SET NULL',
|
|
42
|
+
onUpdate: 'CASCADE',
|
|
43
|
+
},
|
|
44
|
+
result: {
|
|
45
|
+
allowNull: false,
|
|
46
|
+
type: Sequelize.STRING,
|
|
47
|
+
},
|
|
48
|
+
delayForNewRequest: {
|
|
49
|
+
allowNull: false,
|
|
50
|
+
type: Sequelize.STRING,
|
|
51
|
+
},
|
|
52
|
+
createdAt: {
|
|
53
|
+
allowNull: false,
|
|
54
|
+
type: Sequelize.DATE,
|
|
55
|
+
},
|
|
56
|
+
updatedAt: {
|
|
57
|
+
allowNull: false,
|
|
58
|
+
type: Sequelize.DATE,
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
down: async (queryInterface) => {
|
|
64
|
+
await queryInterface.dropTable('ApiPreRequests')
|
|
65
|
+
}
|
|
66
|
+
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
up: async (queryInterface, Sequelize) => {
|
|
5
|
-
await queryInterface.addColumn('SystemUsers', 'isActive', {
|
|
6
|
-
type: Sequelize.BOOLEAN,
|
|
7
|
-
defaultValue: true,
|
|
8
|
-
allowNull: false
|
|
9
|
-
})
|
|
10
|
-
await queryInterface.addColumn('SystemUsers', 'disabledAt', {
|
|
11
|
-
type: Sequelize.DATE,
|
|
12
|
-
allowNull: true
|
|
13
|
-
})
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
down: async (queryInterface) => {
|
|
17
|
-
await queryInterface.removeColumn('SystemUsers', 'isActive')
|
|
18
|
-
await queryInterface.removeColumn('SystemUsers', 'disabledAt')
|
|
19
|
-
}
|
|
20
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
up: async (queryInterface, Sequelize) => {
|
|
5
|
+
await queryInterface.addColumn('SystemUsers', 'isActive', {
|
|
6
|
+
type: Sequelize.BOOLEAN,
|
|
7
|
+
defaultValue: true,
|
|
8
|
+
allowNull: false
|
|
9
|
+
})
|
|
10
|
+
await queryInterface.addColumn('SystemUsers', 'disabledAt', {
|
|
11
|
+
type: Sequelize.DATE,
|
|
12
|
+
allowNull: true
|
|
13
|
+
})
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
down: async (queryInterface) => {
|
|
17
|
+
await queryInterface.removeColumn('SystemUsers', 'isActive')
|
|
18
|
+
await queryInterface.removeColumn('SystemUsers', 'disabledAt')
|
|
19
|
+
}
|
|
20
|
+
};
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const datesColumns = [
|
|
4
|
-
'processedAt', 'enqueuedAt', 'failedAt', 'readAt', 'sentAt', 'deliveredAt'
|
|
5
|
-
]
|
|
6
|
-
module.exports = {
|
|
7
|
-
async up (queryInterface, Sequelize) {
|
|
8
|
-
|
|
9
|
-
await queryInterface.addColumn('BotIterables', 'brokerMessageStatus', {
|
|
10
|
-
type: Sequelize.STRING(100),
|
|
11
|
-
allowNull: true
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
for (const columnName of datesColumns) {
|
|
15
|
-
await queryInterface.addColumn('BotIterables', columnName, {
|
|
16
|
-
type: Sequelize.DATE,
|
|
17
|
-
allowNull: true
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
async down (queryInterface) {
|
|
23
|
-
await queryInterface.removeColumn('BotIterables', 'brokerStatus')
|
|
24
|
-
for(const columnName of datesColumns) {
|
|
25
|
-
await queryInterface.removeColumn('BotIterables', columnName)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const datesColumns = [
|
|
4
|
+
'processedAt', 'enqueuedAt', 'failedAt', 'readAt', 'sentAt', 'deliveredAt'
|
|
5
|
+
]
|
|
6
|
+
module.exports = {
|
|
7
|
+
async up (queryInterface, Sequelize) {
|
|
8
|
+
|
|
9
|
+
await queryInterface.addColumn('BotIterables', 'brokerMessageStatus', {
|
|
10
|
+
type: Sequelize.STRING(100),
|
|
11
|
+
allowNull: true
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
for (const columnName of datesColumns) {
|
|
15
|
+
await queryInterface.addColumn('BotIterables', columnName, {
|
|
16
|
+
type: Sequelize.DATE,
|
|
17
|
+
allowNull: true
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
async down (queryInterface) {
|
|
23
|
+
await queryInterface.removeColumn('BotIterables', 'brokerStatus')
|
|
24
|
+
for(const columnName of datesColumns) {
|
|
25
|
+
await queryInterface.removeColumn('BotIterables', columnName)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
async up (queryInterface, Sequelize) {
|
|
5
|
-
await queryInterface.addColumn('Sessions', 'startedSessionAt', {
|
|
6
|
-
type: Sequelize.DATE,
|
|
7
|
-
allowNull: true
|
|
8
|
-
})
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
async down (queryInterface) {
|
|
12
|
-
await queryInterface.removeColumn('Sessions', 'startedSessionAt')
|
|
13
|
-
}
|
|
14
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up (queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.addColumn('Sessions', 'startedSessionAt', {
|
|
6
|
+
type: Sequelize.DATE,
|
|
7
|
+
allowNull: true
|
|
8
|
+
})
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
async down (queryInterface) {
|
|
12
|
+
await queryInterface.removeColumn('Sessions', 'startedSessionAt')
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
up: async (queryInterface, Sequelize) => {
|
|
5
|
-
await queryInterface.addColumn('ConversationSessions', 'isHsm', {
|
|
6
|
-
allowNull: false,
|
|
7
|
-
defaultValue: false,
|
|
8
|
-
type: Sequelize.BOOLEAN,
|
|
9
|
-
})
|
|
10
|
-
},
|
|
11
|
-
|
|
12
|
-
down: async (queryInterface) => {
|
|
13
|
-
await queryInterface.removeColumn('ConversationSessions', 'isHsm')
|
|
14
|
-
}
|
|
15
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
up: async (queryInterface, Sequelize) => {
|
|
5
|
+
await queryInterface.addColumn('ConversationSessions', 'isHsm', {
|
|
6
|
+
allowNull: false,
|
|
7
|
+
defaultValue: false,
|
|
8
|
+
type: Sequelize.BOOLEAN,
|
|
9
|
+
})
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
down: async (queryInterface) => {
|
|
13
|
+
await queryInterface.removeColumn('ConversationSessions', 'isHsm')
|
|
14
|
+
}
|
|
15
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
up: async (queryInterface, Sequelize) => {
|
|
5
|
+
await queryInterface.createTable('SessionsPreReports', {
|
|
6
|
+
id: {
|
|
7
|
+
allowNull: false,
|
|
8
|
+
defaultValue: Sequelize.literal('uuid_generate_v4()'),
|
|
9
|
+
primaryKey: true,
|
|
10
|
+
type: Sequelize.UUID,
|
|
11
|
+
},
|
|
12
|
+
date: {
|
|
13
|
+
allowNull: false,
|
|
14
|
+
type: Sequelize.DATEONLY
|
|
15
|
+
},
|
|
16
|
+
ChannelId: {
|
|
17
|
+
allowNull: false,
|
|
18
|
+
type: Sequelize.UUID
|
|
19
|
+
},
|
|
20
|
+
SkillId: {
|
|
21
|
+
allowNull: false,
|
|
22
|
+
type: Sequelize.UUID
|
|
23
|
+
},
|
|
24
|
+
sessions: {
|
|
25
|
+
allowNull: false,
|
|
26
|
+
type: Sequelize.BIGINT
|
|
27
|
+
},
|
|
28
|
+
closedSessions: {
|
|
29
|
+
allowNull: false,
|
|
30
|
+
type: Sequelize.BIGINT
|
|
31
|
+
},
|
|
32
|
+
clientMessages: {
|
|
33
|
+
allowNull: false,
|
|
34
|
+
type: Sequelize.BIGINT
|
|
35
|
+
},
|
|
36
|
+
botMessages: {
|
|
37
|
+
allowNull: false,
|
|
38
|
+
type: Sequelize.BIGINT
|
|
39
|
+
},
|
|
40
|
+
totalSessionTime: {
|
|
41
|
+
allowNull: false,
|
|
42
|
+
type: Sequelize.BIGINT
|
|
43
|
+
},
|
|
44
|
+
createdAt: {
|
|
45
|
+
allowNull: false,
|
|
46
|
+
type: Sequelize.DATE,
|
|
47
|
+
},
|
|
48
|
+
updatedAt: {
|
|
49
|
+
allowNull: false,
|
|
50
|
+
type: Sequelize.DATE,
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
down: async (queryInterface, Sequelize) => {
|
|
56
|
+
await queryInterface.dropTable('SessionsPreReports')
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async up (queryInterface, Sequelize) {
|
|
5
|
+
await queryInterface.addColumn('Sessions', 'SessionsPreReportId', {
|
|
6
|
+
type: Sequelize.UUID,
|
|
7
|
+
allowNull: true
|
|
8
|
+
})
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
async down (queryInterface) {
|
|
12
|
+
await queryInterface.removeColumn('Sessions', 'SessionsPreReportId')
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
up: async (queryInterface, Sequelize) => {
|
|
5
|
+
await queryInterface.createTable('DialogNodesPreReports', {
|
|
6
|
+
id: {
|
|
7
|
+
allowNull: false,
|
|
8
|
+
defaultValue: Sequelize.literal('uuid_generate_v4()'),
|
|
9
|
+
primaryKey: true,
|
|
10
|
+
type: Sequelize.UUID,
|
|
11
|
+
},
|
|
12
|
+
date: {
|
|
13
|
+
allowNull: false,
|
|
14
|
+
type: Sequelize.DATEONLY
|
|
15
|
+
},
|
|
16
|
+
ChannelId: {
|
|
17
|
+
allowNull: false,
|
|
18
|
+
type: Sequelize.UUID
|
|
19
|
+
},
|
|
20
|
+
SkillId: {
|
|
21
|
+
allowNull: false,
|
|
22
|
+
type: Sequelize.UUID
|
|
23
|
+
},
|
|
24
|
+
DialogNodeId: {
|
|
25
|
+
allowNull: false,
|
|
26
|
+
type: Sequelize.UUID
|
|
27
|
+
},
|
|
28
|
+
quantity: {
|
|
29
|
+
allowNull: false,
|
|
30
|
+
type: Sequelize.INTEGER
|
|
31
|
+
},
|
|
32
|
+
createdAt: {
|
|
33
|
+
allowNull: false,
|
|
34
|
+
type: Sequelize.DATE,
|
|
35
|
+
},
|
|
36
|
+
updatedAt: {
|
|
37
|
+
allowNull: false,
|
|
38
|
+
type: Sequelize.DATE,
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
down: async (queryInterface, Sequelize) => {
|
|
44
|
+
await queryInterface.dropTable('DialogNodesPreReports')
|
|
45
|
+
}
|
|
46
|
+
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
module.exports = {
|
|
3
|
-
async up (queryInterface, Sequelize) {
|
|
4
|
-
await queryInterface.changeColumn('TranshipConversations', 'mimetype', {
|
|
5
|
-
type: Sequelize.STRING(255),
|
|
6
|
-
allowNull: true,
|
|
7
|
-
})
|
|
8
|
-
},
|
|
9
|
-
|
|
10
|
-
async down (queryInterface, Sequelize) {
|
|
11
|
-
await queryInterface.changeColumn('TranshipConversations', 'mimetype', {
|
|
12
|
-
type: Sequelize.STRING(50),
|
|
13
|
-
allowNull: true,
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
module.exports = {
|
|
3
|
+
async up (queryInterface, Sequelize) {
|
|
4
|
+
await queryInterface.changeColumn('TranshipConversations', 'mimetype', {
|
|
5
|
+
type: Sequelize.STRING(255),
|
|
6
|
+
allowNull: true,
|
|
7
|
+
})
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
async down (queryInterface, Sequelize) {
|
|
11
|
+
await queryInterface.changeColumn('TranshipConversations', 'mimetype', {
|
|
12
|
+
type: Sequelize.STRING(50),
|
|
13
|
+
allowNull: true,
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
up: async (queryInterface, Sequelize) => {
|
|
5
|
+
|
|
6
|
+
await queryInterface.sequelize.query(
|
|
7
|
+
`
|
|
8
|
+
create or replace function _build_sessions_pre_reports(minDate timestamp, maxDate timestamp)
|
|
9
|
+
returns INT AS $$
|
|
10
|
+
declare r RECORD;
|
|
11
|
+
declare "preReportId" UUID;
|
|
12
|
+
declare counter INT := 0;
|
|
13
|
+
declare "rSessions" INT;
|
|
14
|
+
declare "rClosedSessions" INT;
|
|
15
|
+
declare "rClientMessages" INT;
|
|
16
|
+
declare "rBotMessages" INT;
|
|
17
|
+
declare "rTotalSessionTime" BIGINT;
|
|
18
|
+
BEGIN
|
|
19
|
+
|
|
20
|
+
DELETE FROM "SessionsPreReports"
|
|
21
|
+
WHERE "date" BETWEEN cast(minDate as timestamp) AND cast(maxDate as timestamp);
|
|
22
|
+
|
|
23
|
+
FOR r IN (
|
|
24
|
+
select *
|
|
25
|
+
from "Sessions"
|
|
26
|
+
inner join "Channels"
|
|
27
|
+
on "Channels"."id" = "Sessions"."ChannelId"
|
|
28
|
+
inner join "Skills"
|
|
29
|
+
on "Skills"."id" = "Channels"."SkillId"
|
|
30
|
+
where "Sessions"."createdAt" between minDate and maxDate
|
|
31
|
+
) LOOP
|
|
32
|
+
|
|
33
|
+
"rClientMessages" := (
|
|
34
|
+
SELECT COUNT(*)
|
|
35
|
+
FROM "BotIterables"
|
|
36
|
+
WHERE "SessionId" = r."id"
|
|
37
|
+
AND "action" = 'client'
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
"rBotMessages" := (
|
|
41
|
+
SELECT COUNT(*)
|
|
42
|
+
FROM "BotIterables"
|
|
43
|
+
WHERE "SessionId" = r."id"
|
|
44
|
+
AND "action" = 'bot'
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
IF (r."status" = 'closed') THEN
|
|
48
|
+
"rClosedSessions" := 1;
|
|
49
|
+
"rTotalSessionTime" := (extract(epoch from age(r."endOfSession", r."createdAt"))) * 1000;
|
|
50
|
+
ELSE
|
|
51
|
+
"rClosedSessions" := 0;
|
|
52
|
+
"rTotalSessionTime" := 0;
|
|
53
|
+
END IF;
|
|
54
|
+
|
|
55
|
+
"preReportId" := (
|
|
56
|
+
SELECT "id"
|
|
57
|
+
FROM "SessionsPreReports"
|
|
58
|
+
WHERE "date" = cast(r."createdAt" as date)
|
|
59
|
+
AND "ChannelId" = r."ChannelId"
|
|
60
|
+
AND "SkillId" = r."SkillId"
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
IF ("preReportId" IS NULL) THEN
|
|
64
|
+
|
|
65
|
+
INSERT INTO "SessionsPreReports" (
|
|
66
|
+
"date",
|
|
67
|
+
"ChannelId",
|
|
68
|
+
"SkillId",
|
|
69
|
+
"sessions",
|
|
70
|
+
"closedSessions",
|
|
71
|
+
"clientMessages",
|
|
72
|
+
"botMessages",
|
|
73
|
+
"totalSessionTime",
|
|
74
|
+
"createdAt",
|
|
75
|
+
"updatedAt"
|
|
76
|
+
) VALUES (
|
|
77
|
+
cast(r."createdAt" as date),
|
|
78
|
+
r."ChannelId",
|
|
79
|
+
r."SkillId",
|
|
80
|
+
1,
|
|
81
|
+
"rClosedSessions",
|
|
82
|
+
"rClientMessages",
|
|
83
|
+
"rBotMessages",
|
|
84
|
+
"rTotalSessionTime",
|
|
85
|
+
current_timestamp,
|
|
86
|
+
current_timestamp
|
|
87
|
+
) RETURNING "id" INTO "preReportId";
|
|
88
|
+
|
|
89
|
+
ELSE
|
|
90
|
+
|
|
91
|
+
UPDATE "SessionsPreReports"
|
|
92
|
+
SET "sessions" = "sessions" + 1,
|
|
93
|
+
"closedSessions" = "closedSessions" + "rClosedSessions",
|
|
94
|
+
"clientMessages" = "clientMessages" + "rClientMessages",
|
|
95
|
+
"botMessages" = "botMessages" + "rBotMessages",
|
|
96
|
+
"totalSessionTime" = "totalSessionTime" + "rTotalSessionTime"
|
|
97
|
+
WHERE "id" = "preReportId";
|
|
98
|
+
|
|
99
|
+
END IF;
|
|
100
|
+
|
|
101
|
+
UPDATE "Sessions" SET "SessionsPreReportId" = "preReportId" WHERE "id" = r."id";
|
|
102
|
+
|
|
103
|
+
counter := counter + 1;
|
|
104
|
+
|
|
105
|
+
END LOOP;
|
|
106
|
+
RETURN counter;
|
|
107
|
+
END;
|
|
108
|
+
$$ LANGUAGE plpgsql;
|
|
109
|
+
`
|
|
110
|
+
)
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
down: async (queryInterface, Sequelize) => {
|
|
114
|
+
await queryInterface.sequelize.query('DROP FUNCTION _build_sessions_pre_reports(minDate timestamp, maxDate timestamp)')
|
|
115
|
+
},
|
|
116
|
+
}
|
|
@@ -145,6 +145,7 @@ const DialogNodesModel = (sequelize, Sequelize) => {
|
|
|
145
145
|
DialogNodes.hasOne(models.EndSessionTriggers)
|
|
146
146
|
DialogNodes.hasMany(models.EndSessionTriggers, { as: 'EndSessionJumpToDialogNode', foreignKey: 'JumpToDialogNodeId' })
|
|
147
147
|
DialogNodes.hasMany(models.InactivityTriggers)
|
|
148
|
+
DialogNodes.hasMany(models.DialogNodesPreReports)
|
|
148
149
|
}
|
|
149
150
|
return DialogNodes
|
|
150
151
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
exports.model = (sequelize, DataTypes) => {
|
|
2
|
+
const DialogNodesPreReports = sequelize.define('DialogNodesPreReports', {
|
|
3
|
+
date: {
|
|
4
|
+
allowNull: false,
|
|
5
|
+
type: DataTypes.DATEONLY
|
|
6
|
+
},
|
|
7
|
+
ChannelId: {
|
|
8
|
+
allowNull: false,
|
|
9
|
+
type: DataTypes.UUID
|
|
10
|
+
},
|
|
11
|
+
SkillId: {
|
|
12
|
+
allowNull: false,
|
|
13
|
+
type: DataTypes.UUID
|
|
14
|
+
},
|
|
15
|
+
DialogNodeId: {
|
|
16
|
+
allowNull: false,
|
|
17
|
+
type: DataTypes.UUID,
|
|
18
|
+
references: {
|
|
19
|
+
model: 'DialogNodes',
|
|
20
|
+
key: 'id',
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
quantity: {
|
|
24
|
+
allowNull: false,
|
|
25
|
+
type: DataTypes.INTEGER
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
DialogNodesPreReports.associate = models => {
|
|
30
|
+
DialogNodesPreReports.belongsTo(models.DialogNodes)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return DialogNodesPreReports
|
|
34
|
+
}
|
|
35
|
+
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
exports.model = (sequelize, Sequelize) => {
|
|
2
|
-
const OpenFAQs = sequelize.define('FaqQuestions', {
|
|
3
|
-
name: {
|
|
4
|
-
type: Sequelize.STRING(255),
|
|
5
|
-
allowNull: false,
|
|
6
|
-
validate: {
|
|
7
|
-
notEmpty: true,
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
OpenFAQId: {
|
|
11
|
-
type: Sequelize.UUID,
|
|
12
|
-
allowNull: false,
|
|
13
|
-
references: {
|
|
14
|
-
model: 'OpenFAQs',
|
|
15
|
-
key: 'id',
|
|
16
|
-
},
|
|
17
|
-
onDelete: 'CASCADE',
|
|
18
|
-
onUpdate: 'CASCADE',
|
|
19
|
-
foreignKeyConstraint: true,
|
|
20
|
-
validate: {
|
|
21
|
-
notEmpty: true,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
OpenFAQs.associate = (models) => {
|
|
27
|
-
OpenFAQs.belongsTo(models.OpenFAQs)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return OpenFAQs
|
|
31
|
-
}
|
|
1
|
+
exports.model = (sequelize, Sequelize) => {
|
|
2
|
+
const OpenFAQs = sequelize.define('FaqQuestions', {
|
|
3
|
+
name: {
|
|
4
|
+
type: Sequelize.STRING(255),
|
|
5
|
+
allowNull: false,
|
|
6
|
+
validate: {
|
|
7
|
+
notEmpty: true,
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
OpenFAQId: {
|
|
11
|
+
type: Sequelize.UUID,
|
|
12
|
+
allowNull: false,
|
|
13
|
+
references: {
|
|
14
|
+
model: 'OpenFAQs',
|
|
15
|
+
key: 'id',
|
|
16
|
+
},
|
|
17
|
+
onDelete: 'CASCADE',
|
|
18
|
+
onUpdate: 'CASCADE',
|
|
19
|
+
foreignKeyConstraint: true,
|
|
20
|
+
validate: {
|
|
21
|
+
notEmpty: true,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
OpenFAQs.associate = (models) => {
|
|
27
|
+
OpenFAQs.belongsTo(models.OpenFAQs)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return OpenFAQs
|
|
31
|
+
}
|