@itleanchatbot/shared-models-js-postgres 2.8.8 → 2.8.9

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itleanchatbot/shared-models-js-postgres",
3
- "version": "2.8.8",
3
+ "version": "2.8.9",
4
4
  "description": "Shared Models JS Postgres",
5
5
  "main": "index.js",
6
6
  "license": "ISC",
@@ -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,161 @@
1
+ 'use strict'
2
+
3
+ module.exports = {
4
+ up: async (queryInterface, Sequelize) => {
5
+
6
+ await queryInterface.sequelize.query(
7
+ `
8
+ CREATE OR REPLACE FUNCTION get_inactive_sessions(first_call boolean, records_per_page int, starter_page int, maximun int, current_page int DEFAULT 1)
9
+ RETURNS TABLE ("id" uuid) AS $$
10
+ declare r RECORD;
11
+ declare last_iterable "BotIterables"%ROWTYPE;
12
+ declare min_diff INT;
13
+ declare counter INT := 0;
14
+ BEGIN
15
+
16
+ IF ((records_per_page * current_page) > maximun) THEN
17
+ RETURN;
18
+ END IF;
19
+
20
+ IF (first_call) THEN
21
+ DROP TABLE IF EXISTS _tmp_get_inactive_sessions;
22
+ CREATE TEMPORARY TABLE _tmp_get_inactive_sessions (
23
+ "id" uuid
24
+ );
25
+ END IF;
26
+
27
+ FOR r IN (
28
+ select "Sessions"."id",
29
+ "InactivityTriggers"."min"
30
+ from "Sessions"
31
+ inner join "Clients"
32
+ on "Clients"."id" = "Sessions"."ClientId"
33
+ inner join "Channels"
34
+ on "Channels"."id" = "Sessions"."ChannelId"
35
+ inner join "ChannelTypes"
36
+ on "ChannelTypes"."id" = "Channels"."ChannelTypeId"
37
+ inner join "InactivityTriggers"
38
+ on "InactivityTriggers"."SkillId" = "Channels"."SkillId"
39
+ and "InactivityTriggers"."order" = "Sessions"."inactivityCounter"
40
+ where "Sessions"."status" = 'open'
41
+ and "Sessions"."tranship" = false
42
+ and "Channels"."deletedAt" is null
43
+ order by "Sessions"."createdAt"
44
+ limit records_per_page
45
+ offset ((starter_page - 1)*records_per_page)
46
+ ) LOOP
47
+
48
+ select * into last_iterable
49
+ from "BotIterables"
50
+ where "BotIterables"."SessionId" = r."id"
51
+ order by "BotIterables"."createdAt" DESC
52
+ limit 1;
53
+
54
+ min_diff := (
55
+ (SELECT DATE_PART('day', current_timestamp - last_iterable."createdAt") * 24 * 60) +
56
+ (SELECT DATE_PART('hour', current_timestamp - last_iterable."createdAt") * 60) +
57
+ (SELECT DATE_PART('minute', current_timestamp - last_iterable."createdAt"))
58
+ );
59
+
60
+ IF (last_iterable."action" = 'bot' and min_diff >= r."min") THEN
61
+
62
+ INSERT INTO _tmp_get_inactive_sessions ("id")
63
+ VALUES (r."id");
64
+
65
+ END IF;
66
+
67
+ counter := counter + 1;
68
+
69
+ END LOOP;
70
+
71
+ IF (counter = records_per_page) THEN
72
+ PERFORM get_inactive_sessions(false, records_per_page, starter_page + 1, maximun, current_page + 1);
73
+ END IF;
74
+
75
+ RETURN QUERY
76
+ SELECT * FROM _tmp_get_inactive_sessions;
77
+
78
+ END;
79
+ $$ LANGUAGE plpgsql;
80
+ `
81
+ )
82
+ },
83
+
84
+ down: async (queryInterface, Sequelize) => {
85
+ await queryInterface.sequelize.query(
86
+ `
87
+ CREATE OR REPLACE FUNCTION get_inactive_sessions(first_call boolean, records_per_page int, starter_page int, maximun int, current_page int DEFAULT 1)
88
+ RETURNS TABLE ("id" uuid) AS $$
89
+ declare r RECORD;
90
+ declare last_iterable "BotIterables"%ROWTYPE;
91
+ declare min_diff INT;
92
+ declare counter INT := 0;
93
+ BEGIN
94
+
95
+ IF ((records_per_page * current_page) > maximun) THEN
96
+ RETURN;
97
+ END IF;
98
+
99
+ IF (first_call) THEN
100
+ DROP TABLE IF EXISTS _tmp_get_inactive_sessions;
101
+ CREATE TEMPORARY TABLE _tmp_get_inactive_sessions (
102
+ "id" uuid
103
+ );
104
+ END IF;
105
+
106
+ FOR r IN (
107
+ select "Sessions"."id",
108
+ "InactivityTriggers"."min"
109
+ from "Sessions"
110
+ inner join "Clients"
111
+ on "Clients"."id" = "Sessions"."ClientId"
112
+ inner join "Channels"
113
+ on "Channels"."id" = "Sessions"."ChannelId"
114
+ inner join "ChannelTypes"
115
+ on "ChannelTypes"."id" = "Channels"."ChannelTypeId"
116
+ inner join "InactivityTriggers"
117
+ on "InactivityTriggers"."SkillId" = "Channels"."SkillId"
118
+ and "InactivityTriggers"."order" = "Sessions"."inactivityCounter"
119
+ where "Sessions"."status" = 'open'
120
+ and "Sessions"."tranship" = false
121
+ order by "Sessions"."createdAt"
122
+ limit records_per_page
123
+ offset ((starter_page - 1)*records_per_page)
124
+ ) LOOP
125
+
126
+ select * into last_iterable
127
+ from "BotIterables"
128
+ where "BotIterables"."SessionId" = r."id"
129
+ order by "BotIterables"."createdAt" DESC
130
+ limit 1;
131
+
132
+ min_diff := (
133
+ (SELECT DATE_PART('day', current_timestamp - last_iterable."createdAt") * 24 * 60) +
134
+ (SELECT DATE_PART('hour', current_timestamp - last_iterable."createdAt") * 60) +
135
+ (SELECT DATE_PART('minute', current_timestamp - last_iterable."createdAt"))
136
+ );
137
+
138
+ IF (last_iterable."action" = 'bot' and min_diff >= r."min") THEN
139
+
140
+ INSERT INTO _tmp_get_inactive_sessions ("id")
141
+ VALUES (r."id");
142
+
143
+ END IF;
144
+
145
+ counter := counter + 1;
146
+
147
+ END LOOP;
148
+
149
+ IF (counter = records_per_page) THEN
150
+ PERFORM get_inactive_sessions(false, records_per_page, starter_page + 1, maximun, current_page + 1);
151
+ END IF;
152
+
153
+ RETURN QUERY
154
+ SELECT * FROM _tmp_get_inactive_sessions;
155
+
156
+ END;
157
+ $$ LANGUAGE plpgsql;
158
+ `
159
+ )
160
+ },
161
+ }
@@ -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
+ }
@@ -1,33 +1,33 @@
1
- exports.model = (sequelize, Sequelize) => {
2
- const OpenFAQs = sequelize.define('OpenFAQs', {
3
- name: {
4
- allowNull: false,
5
- type: Sequelize.TEXT,
6
- unique: false,
7
- },
8
- SkillId: {
9
- allowNull: false,
10
- type: Sequelize.UUID,
11
- references: {
12
- model: 'Skill',
13
- key: 'id',
14
- },
15
- onDelete: 'RESTRICT',
16
- onUpdate: 'CASCADE',
17
- },
18
- answers: {
19
- allowNull: false,
20
- type: Sequelize.JSON,
21
- validate: {
22
- notEmpty: true,
23
- },
24
- },
25
- })
26
-
27
- OpenFAQs.associate = (models) => {
28
- OpenFAQs.belongsTo(models.Skill)
29
- OpenFAQs.hasMany(models.FaqQuestions)
30
- }
31
-
32
- return OpenFAQs
33
- }
1
+ exports.model = (sequelize, Sequelize) => {
2
+ const OpenFAQs = sequelize.define('OpenFAQs', {
3
+ name: {
4
+ allowNull: false,
5
+ type: Sequelize.TEXT,
6
+ unique: false,
7
+ },
8
+ SkillId: {
9
+ allowNull: false,
10
+ type: Sequelize.UUID,
11
+ references: {
12
+ model: 'Skill',
13
+ key: 'id',
14
+ },
15
+ onDelete: 'RESTRICT',
16
+ onUpdate: 'CASCADE',
17
+ },
18
+ answers: {
19
+ allowNull: false,
20
+ type: Sequelize.JSON,
21
+ validate: {
22
+ notEmpty: true,
23
+ },
24
+ },
25
+ })
26
+
27
+ OpenFAQs.associate = (models) => {
28
+ OpenFAQs.belongsTo(models.Skill)
29
+ OpenFAQs.hasMany(models.FaqQuestions)
30
+ }
31
+
32
+ return OpenFAQs
33
+ }