@tiledesk/tiledesk-server 3.5.0 → 3.5.1
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/CHANGELOG.md +3 -0
- package/deploynew.sh +7 -1
- package/docs/numeric-input-validation.md +91 -0
- package/models/request.js +8 -0
- package/package.json +1 -1
- package/pubmodules/activities/routes/activity.js +9 -10
- package/pubmodules/canned/cannedResponseRoute.js +6 -9
- package/pubmodules/events/eventRoute.js +6 -9
- package/routes/answered.js +7 -3
- package/routes/campaigns.js +7 -3
- package/routes/department.js +14 -3
- package/routes/faq.js +6 -14
- package/routes/filesp.js +9 -4
- package/routes/kb.js +40 -15
- package/routes/lead.js +23 -28
- package/routes/logs.js +8 -1
- package/routes/message.js +3 -1
- package/routes/messagesRoot.js +5 -18
- package/routes/project.js +57 -12
- package/routes/project_user.js +21 -4
- package/routes/property.js +18 -20
- package/routes/request.js +31 -45
- package/routes/roles.js +8 -18
- package/routes/segment.js +8 -18
- package/routes/subscription.js +4 -5
- package/routes/tag.js +6 -9
- package/routes/unanswered.js +7 -3
- package/routes/user-request.js +29 -34
- package/test/kbRoute.js +4 -7
- package/test/numericInput.js +137 -0
- package/utils/numericInput.js +200 -0
package/routes/logs.js
CHANGED
|
@@ -8,6 +8,7 @@ const { v4: uuidv4 } = require('uuid');
|
|
|
8
8
|
const jwt = require("jsonwebtoken")
|
|
9
9
|
|
|
10
10
|
const jwtSecret = process.env.CHAT21_JWT_SECRET || "tokenKey";
|
|
11
|
+
var numericInput = require('../utils/numericInput');
|
|
11
12
|
|
|
12
13
|
router.get('/', function (req, res, next) {
|
|
13
14
|
winston.info("logs", req.body);
|
|
@@ -87,13 +88,19 @@ router.post('/whatsapp', async (req, res) => {
|
|
|
87
88
|
|
|
88
89
|
winston.info("save following log: ", req.body);
|
|
89
90
|
|
|
91
|
+
var statusCode = numericInput.takeOptionalBoundedInteger(res, req.body.status_code, 0, 999, 'status_code');
|
|
92
|
+
if (statusCode === null) return;
|
|
93
|
+
if (statusCode === undefined) {
|
|
94
|
+
return numericInput.sendInvalidNumber(res, 'status_code must be an integer between 0 and 999');
|
|
95
|
+
}
|
|
96
|
+
|
|
90
97
|
let log = new MessageLog({
|
|
91
98
|
id_project: req.body.id_project,
|
|
92
99
|
json_message: req.body.json_message,
|
|
93
100
|
transaction_id: req.body.transaction_id,
|
|
94
101
|
message_id: req.body.message_id,
|
|
95
102
|
status: req.body.status,
|
|
96
|
-
status_code:
|
|
103
|
+
status_code: statusCode,
|
|
97
104
|
error: req.body.error
|
|
98
105
|
});
|
|
99
106
|
|
package/routes/message.js
CHANGED
|
@@ -16,6 +16,7 @@ var MessageConstants = require("../models/messageConstants");
|
|
|
16
16
|
|
|
17
17
|
var cacheUtil = require('../utils/cacheUtil');
|
|
18
18
|
var cacheEnabler = require("../services/cacheEnabler");
|
|
19
|
+
var numericInput = require('../utils/numericInput');
|
|
19
20
|
|
|
20
21
|
const { check, validationResult } = require('express-validator');
|
|
21
22
|
|
|
@@ -61,7 +62,8 @@ async (req, res) => {
|
|
|
61
62
|
var fullname = req.body.senderFullname || req.user.fullName;
|
|
62
63
|
var email = req.body.email || req.user.email;
|
|
63
64
|
|
|
64
|
-
let messageStatus = req.body.status
|
|
65
|
+
let messageStatus = numericInput.takeMessageStatus(res, req.body.status);
|
|
66
|
+
if (messageStatus === null) return;
|
|
65
67
|
winston.debug('messageStatus: ' + messageStatus);
|
|
66
68
|
|
|
67
69
|
let q = Request.findOne({request_id: req.params.request_id, id_project: req.projectid});
|
package/routes/messagesRoot.js
CHANGED
|
@@ -11,6 +11,7 @@ var winston = require('../config/winston');
|
|
|
11
11
|
var fastCsv = require("fast-csv");
|
|
12
12
|
var roleChecker = require('../middleware/has-role');
|
|
13
13
|
const { check, validationResult } = require('express-validator');
|
|
14
|
+
var numericInput = require('../utils/numericInput');
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
router.post('/',
|
|
@@ -68,24 +69,10 @@ router.post('/',
|
|
|
68
69
|
|
|
69
70
|
router.get('/',roleChecker.hasRoleOrTypes('owner'), function(req, res) {
|
|
70
71
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
var limit =
|
|
74
|
-
|
|
75
|
-
// console.log("req.query.populate_request",req.query.populate_request);
|
|
76
|
-
if (req.query.limit) {
|
|
77
|
-
limit = parseInt(req.query.limit);
|
|
78
|
-
}
|
|
79
|
-
if (limit > 50) {
|
|
80
|
-
limit = DEFAULT_LIMIT;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
var page = 0;
|
|
85
|
-
|
|
86
|
-
if (req.query.page) {
|
|
87
|
-
page = req.query.page;
|
|
88
|
-
}
|
|
72
|
+
const paging = numericInput.takePagination(res, req.query, { defaultLimit: 10, maxLimit: 50, overMax: 'default' });
|
|
73
|
+
if (!paging) return;
|
|
74
|
+
var limit = paging.limit;
|
|
75
|
+
var page = paging.page;
|
|
89
76
|
|
|
90
77
|
var skip = page * limit;
|
|
91
78
|
|
package/routes/project.js
CHANGED
|
@@ -12,6 +12,47 @@ var Department = require('../models/department');
|
|
|
12
12
|
var Group = require('../models/group');
|
|
13
13
|
|
|
14
14
|
var winston = require('../config/winston');
|
|
15
|
+
var numericInput = require('../utils/numericInput');
|
|
16
|
+
|
|
17
|
+
function validateProjectNumbers(res, body) {
|
|
18
|
+
var parsed = {};
|
|
19
|
+
var checks = [
|
|
20
|
+
['versions', body.versions, 0, 99999999, 'versions must be an integer between 0 and 99999999'],
|
|
21
|
+
['settings.max_agent_assigned_chat', body['settings.max_agent_assigned_chat'], -1, 100000, 'settings.max_agent_assigned_chat must be -1 (unlimited) or an integer between 0 and 100000'],
|
|
22
|
+
['settings.reassignment_delay', body['settings.reassignment_delay'], 0, 315360000, 'settings.reassignment_delay must be an integer between 0 and 315360000'],
|
|
23
|
+
['settings.email.config.port', body['settings.email.config.port'], 1, 65535, 'settings.email.config.port must be an integer between 1 and 65535']
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
for (var i = 0; i < checks.length; i++) {
|
|
27
|
+
var key = checks[i][0];
|
|
28
|
+
var value = checks[i][1];
|
|
29
|
+
if (value === undefined) continue;
|
|
30
|
+
var n = numericInput.parseBoundedInteger(value, checks[i][2], checks[i][3]);
|
|
31
|
+
if (n === null) {
|
|
32
|
+
return numericInput.sendInvalidNumber(res, checks[i][4]);
|
|
33
|
+
}
|
|
34
|
+
parsed[key] = n;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (body.settings && typeof body.settings === 'object' && !Array.isArray(body.settings)) {
|
|
38
|
+
if (body.settings.max_agent_assigned_chat !== undefined) {
|
|
39
|
+
var maxAgentAssignedChat = numericInput.parseBoundedInteger(body.settings.max_agent_assigned_chat, -1, 100000);
|
|
40
|
+
if (maxAgentAssignedChat === null) {
|
|
41
|
+
return numericInput.sendInvalidNumber(res, 'settings.max_agent_assigned_chat must be -1 (unlimited) or an integer between 0 and 100000');
|
|
42
|
+
}
|
|
43
|
+
body.settings.max_agent_assigned_chat = maxAgentAssignedChat;
|
|
44
|
+
}
|
|
45
|
+
if (body.settings.reassignment_delay !== undefined) {
|
|
46
|
+
var reassignmentDelay = numericInput.parseBoundedInteger(body.settings.reassignment_delay, 0, 315360000);
|
|
47
|
+
if (reassignmentDelay === null) {
|
|
48
|
+
return numericInput.sendInvalidNumber(res, 'settings.reassignment_delay must be an integer between 0 and 315360000');
|
|
49
|
+
}
|
|
50
|
+
body.settings.reassignment_delay = reassignmentDelay;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return parsed;
|
|
55
|
+
}
|
|
15
56
|
var roleChecker = require('../middleware/has-role');
|
|
16
57
|
var config = require('../config/database');
|
|
17
58
|
|
|
@@ -260,6 +301,8 @@ router.put('/:projectid', [passport.authenticate(['basic', 'jwt'], { session: fa
|
|
|
260
301
|
winston.debug('UPDATE PROJECT REQ BODY ', req.body);
|
|
261
302
|
|
|
262
303
|
var update = {};
|
|
304
|
+
var projectNumbers = validateProjectNumbers(res, req.body);
|
|
305
|
+
if (projectNumbers === null) return;
|
|
263
306
|
let updating_quotes = false;
|
|
264
307
|
|
|
265
308
|
if (req.body.profile) {
|
|
@@ -418,8 +461,8 @@ router.put('/:projectid', [passport.authenticate(['basic', 'jwt'], { session: fa
|
|
|
418
461
|
update["settings.chat_limit_on"] = req.body["settings.chat_limit_on"];
|
|
419
462
|
}
|
|
420
463
|
|
|
421
|
-
if (
|
|
422
|
-
update["settings.max_agent_assigned_chat"] =
|
|
464
|
+
if (projectNumbers["settings.max_agent_assigned_chat"] !== undefined) {
|
|
465
|
+
update["settings.max_agent_assigned_chat"] = projectNumbers["settings.max_agent_assigned_chat"];
|
|
423
466
|
}
|
|
424
467
|
|
|
425
468
|
|
|
@@ -428,8 +471,8 @@ router.put('/:projectid', [passport.authenticate(['basic', 'jwt'], { session: fa
|
|
|
428
471
|
update["settings.reassignment_on"] = req.body["settings.reassignment_on"];
|
|
429
472
|
}
|
|
430
473
|
|
|
431
|
-
if (
|
|
432
|
-
update["settings.reassignment_delay"] =
|
|
474
|
+
if (projectNumbers["settings.reassignment_delay"] !== undefined) {
|
|
475
|
+
update["settings.reassignment_delay"] = projectNumbers["settings.reassignment_delay"];
|
|
433
476
|
}
|
|
434
477
|
|
|
435
478
|
|
|
@@ -469,8 +512,8 @@ router.put('/:projectid', [passport.authenticate(['basic', 'jwt'], { session: fa
|
|
|
469
512
|
update.widget = req.body.widget;
|
|
470
513
|
}
|
|
471
514
|
|
|
472
|
-
if (
|
|
473
|
-
update.versions =
|
|
515
|
+
if (projectNumbers.versions !== undefined) {
|
|
516
|
+
update.versions = projectNumbers.versions;
|
|
474
517
|
}
|
|
475
518
|
|
|
476
519
|
if (req.body.channels!=undefined) {
|
|
@@ -525,6 +568,8 @@ router.patch('/:projectid', [passport.authenticate(['basic', 'jwt'], { session:
|
|
|
525
568
|
winston.debug('PATCH PROJECT REQ BODY ', req.body);
|
|
526
569
|
|
|
527
570
|
var update = {};
|
|
571
|
+
var projectNumbers = validateProjectNumbers(res, req.body);
|
|
572
|
+
if (projectNumbers === null) return;
|
|
528
573
|
|
|
529
574
|
if (req.body.name!=undefined) {
|
|
530
575
|
update.name = req.body.name;
|
|
@@ -604,8 +649,8 @@ router.patch('/:projectid', [passport.authenticate(['basic', 'jwt'], { session:
|
|
|
604
649
|
update["settings.chat_limit_on"] = req.body["settings.chat_limit_on"];
|
|
605
650
|
}
|
|
606
651
|
|
|
607
|
-
if (
|
|
608
|
-
update["settings.max_agent_assigned_chat"] =
|
|
652
|
+
if (projectNumbers["settings.max_agent_assigned_chat"] !== undefined) {
|
|
653
|
+
update["settings.max_agent_assigned_chat"] = projectNumbers["settings.max_agent_assigned_chat"];
|
|
609
654
|
}
|
|
610
655
|
|
|
611
656
|
|
|
@@ -614,8 +659,8 @@ router.patch('/:projectid', [passport.authenticate(['basic', 'jwt'], { session:
|
|
|
614
659
|
update["settings.reassignment_on"] = req.body["settings.reassignment_on"];
|
|
615
660
|
}
|
|
616
661
|
|
|
617
|
-
if (
|
|
618
|
-
update["settings.reassignment_delay"] =
|
|
662
|
+
if (projectNumbers["settings.reassignment_delay"] !== undefined) {
|
|
663
|
+
update["settings.reassignment_delay"] = projectNumbers["settings.reassignment_delay"];
|
|
619
664
|
}
|
|
620
665
|
|
|
621
666
|
|
|
@@ -633,8 +678,8 @@ router.patch('/:projectid', [passport.authenticate(['basic', 'jwt'], { session:
|
|
|
633
678
|
update.widget = req.body.widget;
|
|
634
679
|
}
|
|
635
680
|
|
|
636
|
-
if (
|
|
637
|
-
update.versions =
|
|
681
|
+
if (projectNumbers.versions !== undefined) {
|
|
682
|
+
update.versions = projectNumbers.versions;
|
|
638
683
|
}
|
|
639
684
|
|
|
640
685
|
if (req.body.channels!=undefined) {
|
package/routes/project_user.js
CHANGED
|
@@ -18,6 +18,7 @@ var validtoken = require('../middleware/valid-token')
|
|
|
18
18
|
var roleChecker = require('../middleware/has-role');
|
|
19
19
|
const puEvent = require('../event/projectUserEvent');
|
|
20
20
|
const { track } = require('../lib/analyticsClient');
|
|
21
|
+
var numericInput = require('../utils/numericInput');
|
|
21
22
|
const projectUserUpdateContextUtil = require('../utils/projectUserUpdateContextUtil');
|
|
22
23
|
|
|
23
24
|
function emitProjectUserDeleteActivity(req, project_user, deleteType) {
|
|
@@ -220,11 +221,19 @@ router.put('/', [passport.authenticate(['basic', 'jwt'], { session: false }), va
|
|
|
220
221
|
}
|
|
221
222
|
|
|
222
223
|
if (req.body.max_assigned_chat!=undefined) {
|
|
223
|
-
|
|
224
|
+
var maxAssignedChat = numericInput.parseBoundedInteger(req.body.max_assigned_chat, -1, 100000);
|
|
225
|
+
if (maxAssignedChat === null) {
|
|
226
|
+
return numericInput.sendInvalidNumber(res, 'max_assigned_chat must be -1 (unlimited) or an integer between 0 and 100000');
|
|
227
|
+
}
|
|
228
|
+
update.max_assigned_chat = maxAssignedChat;
|
|
224
229
|
}
|
|
225
230
|
|
|
226
231
|
if (req.body.number_assigned_requests!=undefined) {
|
|
227
|
-
|
|
232
|
+
var numberAssignedRequests = numericInput.parseBoundedInteger(req.body.number_assigned_requests, 0, 1000000);
|
|
233
|
+
if (numberAssignedRequests === null) {
|
|
234
|
+
return numericInput.sendInvalidNumber(res, 'number_assigned_requests must be an integer between 0 and 1000000');
|
|
235
|
+
}
|
|
236
|
+
update.number_assigned_requests = numberAssignedRequests;
|
|
228
237
|
}
|
|
229
238
|
|
|
230
239
|
if (req.body.attributes!=undefined) {
|
|
@@ -292,11 +301,19 @@ router.put('/:project_userid', [passport.authenticate(['basic', 'jwt'], { sessio
|
|
|
292
301
|
}
|
|
293
302
|
|
|
294
303
|
if (req.body.max_assigned_chat!=undefined) {
|
|
295
|
-
|
|
304
|
+
var maxAssignedChat = numericInput.parseBoundedInteger(req.body.max_assigned_chat, -1, 100000);
|
|
305
|
+
if (maxAssignedChat === null) {
|
|
306
|
+
return numericInput.sendInvalidNumber(res, 'max_assigned_chat must be -1 (unlimited) or an integer between 0 and 100000');
|
|
307
|
+
}
|
|
308
|
+
update.max_assigned_chat = maxAssignedChat;
|
|
296
309
|
}
|
|
297
310
|
|
|
298
311
|
if (req.body.number_assigned_requests!=undefined) {
|
|
299
|
-
|
|
312
|
+
var numberAssignedRequests = numericInput.parseBoundedInteger(req.body.number_assigned_requests, 0, 1000000);
|
|
313
|
+
if (numberAssignedRequests === null) {
|
|
314
|
+
return numericInput.sendInvalidNumber(res, 'number_assigned_requests must be an integer between 0 and 1000000');
|
|
315
|
+
}
|
|
316
|
+
update.number_assigned_requests = numberAssignedRequests;
|
|
300
317
|
}
|
|
301
318
|
|
|
302
319
|
if (req.body.attributes!=undefined) {
|
package/routes/property.js
CHANGED
|
@@ -2,6 +2,7 @@ var express = require('express');
|
|
|
2
2
|
var router = express.Router();
|
|
3
3
|
var Property = require("../models/property");
|
|
4
4
|
var winston = require('../config/winston');
|
|
5
|
+
var numericInput = require('../utils/numericInput');
|
|
5
6
|
|
|
6
7
|
router.post('/', function (req, res) {
|
|
7
8
|
|
|
@@ -43,7 +44,11 @@ router.put('/:propertyid', function (req, res) {
|
|
|
43
44
|
update.type = req.body.type;
|
|
44
45
|
}
|
|
45
46
|
if (req.body.status!=undefined) {
|
|
46
|
-
|
|
47
|
+
var propertyStatus = numericInput.takeOptionalAllowedInteger(res, req.body.status, numericInput.PROPERTY_STATUSES, 'status');
|
|
48
|
+
if (propertyStatus === null) return;
|
|
49
|
+
if (propertyStatus !== undefined) {
|
|
50
|
+
update.status = propertyStatus;
|
|
51
|
+
}
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
|
|
@@ -113,20 +118,11 @@ router.get('/:propertyid', function (req, res) {
|
|
|
113
118
|
|
|
114
119
|
router.get('/', function (req, res) {
|
|
115
120
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
var page = 0;
|
|
124
|
-
|
|
125
|
-
if (req.query.page) {
|
|
126
|
-
page = req.query.page;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
var skip = page * limit;
|
|
121
|
+
const paging = numericInput.takePagination(res, req.query, { defaultLimit: 40, maxLimit: 1000, overMax: 'reject' });
|
|
122
|
+
if (!paging) return;
|
|
123
|
+
var limit = paging.limit;
|
|
124
|
+
var skip = paging.skip;
|
|
125
|
+
winston.debug('property ROUTE - limit: '+limit);
|
|
130
126
|
winston.debug('property ROUTE - SKIP PAGE ', skip);
|
|
131
127
|
|
|
132
128
|
|
|
@@ -138,13 +134,15 @@ router.get('/', function (req, res) {
|
|
|
138
134
|
}
|
|
139
135
|
|
|
140
136
|
if (req.query.status) {
|
|
141
|
-
|
|
137
|
+
var propertyStatus = numericInput.takeOptionalAllowedInteger(res, req.query.status, numericInput.PROPERTY_STATUSES, 'status');
|
|
138
|
+
if (propertyStatus === null) return;
|
|
139
|
+
if (propertyStatus !== undefined) {
|
|
140
|
+
query.status = propertyStatus;
|
|
141
|
+
}
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
var direction =
|
|
145
|
-
if (
|
|
146
|
-
direction = req.query.direction;
|
|
147
|
-
}
|
|
144
|
+
var direction = numericInput.takeSortDirection(res, req.query.direction);
|
|
145
|
+
if (direction === null) return;
|
|
148
146
|
|
|
149
147
|
var sortField = "createdAt";
|
|
150
148
|
if (req.query.sort) {
|
package/routes/request.js
CHANGED
|
@@ -37,6 +37,7 @@ const { Scheduler } = require('../services/Scheduler');
|
|
|
37
37
|
const faq_kb = require('../models/faq_kb');
|
|
38
38
|
const participantInviteService = require('../services/participantInviteService');
|
|
39
39
|
const participantRemoveService = require('../services/participantRemoveService');
|
|
40
|
+
const numericInput = require('../utils/numericInput');
|
|
40
41
|
|
|
41
42
|
const datesUtil = require('../utils/datesUtil');
|
|
42
43
|
//const JobManager = require('../utils/jobs-worker-queue-manager-v2/JobManagerV2');
|
|
@@ -111,7 +112,8 @@ router.post('/',
|
|
|
111
112
|
var fullname = req.body.senderFullname || req.user.fullName;
|
|
112
113
|
var email = req.body.email || req.user.email;
|
|
113
114
|
|
|
114
|
-
let messageStatus = req.body.status
|
|
115
|
+
let messageStatus = numericInput.takeMessageStatus(res, req.body.status);
|
|
116
|
+
if (messageStatus === null) return;
|
|
115
117
|
winston.debug('messageStatus: ' + messageStatus);
|
|
116
118
|
|
|
117
119
|
var request_id = req.body.request_id || 'support-group-' + req.projectid + "-" + UIDGenerator.generate();
|
|
@@ -233,8 +235,10 @@ router.patch('/:requestid', function (req, res) {
|
|
|
233
235
|
}
|
|
234
236
|
|
|
235
237
|
// TODO test it. does it work?
|
|
236
|
-
if (req.body.status) {
|
|
237
|
-
|
|
238
|
+
if (req.body.status !== undefined && req.body.status !== null && req.body.status !== '') {
|
|
239
|
+
var status = numericInput.takeOptionalAllowedInteger(res, req.body.status, numericInput.REQUEST_STATUSES, 'status');
|
|
240
|
+
if (status === null) return;
|
|
241
|
+
update.status = status;
|
|
238
242
|
}
|
|
239
243
|
|
|
240
244
|
if (req.body.tags) {
|
|
@@ -245,8 +249,12 @@ router.patch('/:requestid', function (req, res) {
|
|
|
245
249
|
// update.notes = req.body.notes;
|
|
246
250
|
// }
|
|
247
251
|
|
|
248
|
-
if (req.body.rating) {
|
|
249
|
-
|
|
252
|
+
if (req.body.rating !== undefined && req.body.rating !== null && req.body.rating !== '') {
|
|
253
|
+
var rating = numericInput.parseBoundedInteger(req.body.rating, 1, 5);
|
|
254
|
+
if (rating === null) {
|
|
255
|
+
return numericInput.sendInvalidNumber(res, 'rating must be an integer between 1 and 5');
|
|
256
|
+
}
|
|
257
|
+
update.rating = rating;
|
|
250
258
|
}
|
|
251
259
|
|
|
252
260
|
if (req.body.rating_message) {
|
|
@@ -294,7 +302,7 @@ router.patch('/:requestid', function (req, res) {
|
|
|
294
302
|
winston.verbose("Request patch update", update);
|
|
295
303
|
|
|
296
304
|
//cacheinvalidation
|
|
297
|
-
return Request.findOneAndUpdate({ "request_id": req.params.requestid, "id_project": req.projectid }, { $set: update }, { new: true, upsert: false })
|
|
305
|
+
return Request.findOneAndUpdate({ "request_id": req.params.requestid, "id_project": req.projectid }, { $set: update }, { new: true, upsert: false, runValidators: true })
|
|
298
306
|
.populate('lead')
|
|
299
307
|
.populate('department')
|
|
300
308
|
.populate('participatingBots')
|
|
@@ -1274,29 +1282,15 @@ router.get('/', function (req, res, next) {
|
|
|
1274
1282
|
winston.debug("req.query.sort", req.query.sort);
|
|
1275
1283
|
winston.debug('REQUEST ROUTE - QUERY ', req.query)
|
|
1276
1284
|
|
|
1277
|
-
const
|
|
1278
|
-
|
|
1279
|
-
var
|
|
1280
|
-
var
|
|
1281
|
-
var
|
|
1282
|
-
var skip = 0;
|
|
1285
|
+
const paging = numericInput.takePagination(res, req.query, { defaultLimit: 40, maxLimit: 100, overMax: 'default' });
|
|
1286
|
+
if (!paging) return;
|
|
1287
|
+
var limit = paging.limit;
|
|
1288
|
+
var page = paging.page;
|
|
1289
|
+
var skip = paging.skip;
|
|
1283
1290
|
let statusArray = [];
|
|
1284
1291
|
var projectuser = req.projectuser;
|
|
1285
1292
|
let filterRangeField = req.query.filterRangeField || 'createdAt';
|
|
1286
1293
|
|
|
1287
|
-
if (req.query.limit) {
|
|
1288
|
-
limit = parseInt(req.query.limit);
|
|
1289
|
-
}
|
|
1290
|
-
if (limit > 100) {
|
|
1291
|
-
limit = DEFAULT_LIMIT;
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
if (req.query.page) {
|
|
1295
|
-
page = req.query.page;
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
skip = page * limit;
|
|
1299
|
-
|
|
1300
1294
|
// Default query
|
|
1301
1295
|
var query = { "id_project": req.projectid, "status": { $lt: 1000, $nin: [50, 150] }, preflight: false };
|
|
1302
1296
|
|
|
@@ -1347,8 +1341,8 @@ router.get('/', function (req, res, next) {
|
|
|
1347
1341
|
if (req.query.status === 'all') {
|
|
1348
1342
|
delete query.status;
|
|
1349
1343
|
} else {
|
|
1350
|
-
|
|
1351
|
-
|
|
1344
|
+
statusArray = numericInput.takeStatusList(res, req.query.status, numericInput.REQUEST_STATUSES);
|
|
1345
|
+
if (!statusArray) return;
|
|
1352
1346
|
if (statusArray.length > 0) {
|
|
1353
1347
|
query.status = {
|
|
1354
1348
|
$in: statusArray
|
|
@@ -1492,10 +1486,8 @@ router.get('/', function (req, res, next) {
|
|
|
1492
1486
|
}
|
|
1493
1487
|
|
|
1494
1488
|
|
|
1495
|
-
var direction =
|
|
1496
|
-
if (
|
|
1497
|
-
direction = req.query.direction;
|
|
1498
|
-
}
|
|
1489
|
+
var direction = numericInput.takeSortDirection(res, req.query.direction);
|
|
1490
|
+
if (direction === null) return;
|
|
1499
1491
|
|
|
1500
1492
|
var sortField = "createdAt";
|
|
1501
1493
|
if (req.query.sort) {
|
|
@@ -2003,17 +1995,13 @@ router.get('/csv', function (req, res, next) {
|
|
|
2003
1995
|
winston.debug('REQUEST ROUTE - QUERY ', req.query)
|
|
2004
1996
|
|
|
2005
1997
|
var limit = 100000; // Number of request per page
|
|
2006
|
-
var page = 0;
|
|
2007
|
-
|
|
1998
|
+
var page = numericInput.takeOptionalBoundedInteger(res, req.query.page, 0, 1000000, 'page');
|
|
1999
|
+
if (page === null) return;
|
|
2000
|
+
if (page === undefined) page = 0;
|
|
2001
|
+
var skip = page * limit;
|
|
2008
2002
|
let statusArray = [];
|
|
2009
2003
|
var projectuser = req.projectuser;
|
|
2010
2004
|
let filterRangeField = req.query.filterRangeField || 'createdAt';
|
|
2011
|
-
|
|
2012
|
-
if (req.query.page) {
|
|
2013
|
-
page = req.query.page;
|
|
2014
|
-
}
|
|
2015
|
-
|
|
2016
|
-
skip = page * limit;
|
|
2017
2005
|
winston.debug('REQUEST ROUTE - SKIP PAGE ', skip);
|
|
2018
2006
|
|
|
2019
2007
|
// Default query (same as GET /)
|
|
@@ -2057,8 +2045,8 @@ router.get('/csv', function (req, res, next) {
|
|
|
2057
2045
|
if (req.query.status === 'all') {
|
|
2058
2046
|
delete query.status;
|
|
2059
2047
|
} else {
|
|
2060
|
-
statusArray = req.query.status
|
|
2061
|
-
|
|
2048
|
+
statusArray = numericInput.takeStatusList(res, req.query.status, numericInput.REQUEST_STATUSES);
|
|
2049
|
+
if (!statusArray) return;
|
|
2062
2050
|
if (statusArray.length > 0) {
|
|
2063
2051
|
query.status = { $in: statusArray };
|
|
2064
2052
|
} else {
|
|
@@ -2173,10 +2161,8 @@ router.get('/csv', function (req, res, next) {
|
|
|
2173
2161
|
query.priority = req.query.priority;
|
|
2174
2162
|
}
|
|
2175
2163
|
|
|
2176
|
-
var direction =
|
|
2177
|
-
if (
|
|
2178
|
-
direction = req.query.direction;
|
|
2179
|
-
}
|
|
2164
|
+
var direction = numericInput.takeSortDirection(res, req.query.direction);
|
|
2165
|
+
if (direction === null) return;
|
|
2180
2166
|
winston.debug("direction", direction);
|
|
2181
2167
|
|
|
2182
2168
|
var sortField = "createdAt";
|
package/routes/roles.js
CHANGED
|
@@ -2,6 +2,7 @@ var express = require('express');
|
|
|
2
2
|
var router = express.Router();
|
|
3
3
|
var Role = require("../models/role");
|
|
4
4
|
var winston = require('../config/winston');
|
|
5
|
+
var numericInput = require('../utils/numericInput');
|
|
5
6
|
const roleEvent = require('../event/roleEvent');
|
|
6
7
|
|
|
7
8
|
router.post('/', function (req, res) {
|
|
@@ -92,20 +93,11 @@ router.get('/:roleid', function (req, res) {
|
|
|
92
93
|
|
|
93
94
|
router.get('/', async(req, res) => {
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
var page = 0;
|
|
103
|
-
|
|
104
|
-
if (req.query.page) {
|
|
105
|
-
page = req.query.page;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
var skip = page * limit;
|
|
96
|
+
const paging = numericInput.takePagination(res, req.query, { defaultLimit: 40, maxLimit: 1000, overMax: 'reject' });
|
|
97
|
+
if (!paging) return;
|
|
98
|
+
var limit = paging.limit;
|
|
99
|
+
var skip = paging.skip;
|
|
100
|
+
winston.debug('LEAD ROUTE - limit: '+limit);
|
|
109
101
|
winston.debug('ROLE ROUTE - SKIP PAGE ', skip);
|
|
110
102
|
|
|
111
103
|
|
|
@@ -113,10 +105,8 @@ router.get('/', async(req, res) => {
|
|
|
113
105
|
|
|
114
106
|
|
|
115
107
|
|
|
116
|
-
var direction =
|
|
117
|
-
if (
|
|
118
|
-
direction = req.query.direction;
|
|
119
|
-
}
|
|
108
|
+
var direction = numericInput.takeSortDirection(res, req.query.direction);
|
|
109
|
+
if (direction === null) return;
|
|
120
110
|
|
|
121
111
|
var sortField = "createdAt";
|
|
122
112
|
if (req.query.sort) {
|
package/routes/segment.js
CHANGED
|
@@ -2,6 +2,7 @@ var express = require('express');
|
|
|
2
2
|
var router = express.Router();
|
|
3
3
|
var winston = require('../config/winston');
|
|
4
4
|
var Segment = require("../models/segment");
|
|
5
|
+
var numericInput = require('../utils/numericInput');
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
router.post('/', function (req, res) {
|
|
@@ -91,29 +92,18 @@ router.get('/:segmentid', function (req, res) {
|
|
|
91
92
|
|
|
92
93
|
router.get('/', function (req, res) {
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
var page = 0;
|
|
102
|
-
|
|
103
|
-
if (req.query.page) {
|
|
104
|
-
page = req.query.page;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
var skip = page * limit;
|
|
95
|
+
const paging = numericInput.takePagination(res, req.query, { defaultLimit: 40, maxLimit: 1000, overMax: 'reject' });
|
|
96
|
+
if (!paging) return;
|
|
97
|
+
var limit = paging.limit;
|
|
98
|
+
var skip = paging.skip;
|
|
99
|
+
winston.debug('LEAD ROUTE - limit: '+limit);
|
|
108
100
|
winston.debug('LEAD ROUTE - SKIP PAGE ', skip);
|
|
109
101
|
|
|
110
102
|
|
|
111
103
|
var query = { "id_project": req.projectid, "status": 100};
|
|
112
104
|
|
|
113
|
-
var direction =
|
|
114
|
-
if (
|
|
115
|
-
direction = req.query.direction;
|
|
116
|
-
}
|
|
105
|
+
var direction = numericInput.takeSortDirection(res, req.query.direction);
|
|
106
|
+
if (direction === null) return;
|
|
117
107
|
|
|
118
108
|
var sortField = "createdAt";
|
|
119
109
|
if (req.query.sort) {
|
package/routes/subscription.js
CHANGED
|
@@ -4,6 +4,7 @@ var Subscription = require("../models/subscription");
|
|
|
4
4
|
var SubscriptionLog = require("../models/subscriptionLog");
|
|
5
5
|
var subscriptionEvent = require("../event/subscriptionEvent");
|
|
6
6
|
var winston = require('../config/winston');
|
|
7
|
+
var numericInput = require('../utils/numericInput');
|
|
7
8
|
|
|
8
9
|
//space
|
|
9
10
|
|
|
@@ -96,11 +97,9 @@ router.get('/', function (req, res) {
|
|
|
96
97
|
router.get('/history', function (req, res) {
|
|
97
98
|
|
|
98
99
|
var limit = 40; // Number of leads per page
|
|
99
|
-
var page = 0;
|
|
100
|
-
|
|
101
|
-
if (
|
|
102
|
-
page = req.query.page;
|
|
103
|
-
}
|
|
100
|
+
var page = numericInput.takeOptionalBoundedInteger(res, req.query.page, 0, 1000000, 'page');
|
|
101
|
+
if (page === null) return;
|
|
102
|
+
if (page === undefined) page = 0;
|
|
104
103
|
|
|
105
104
|
var skip = page * limit;
|
|
106
105
|
winston.debug('Subscription ROUTE - SKIP PAGE ', skip);
|
package/routes/tag.js
CHANGED
|
@@ -2,6 +2,7 @@ var express = require('express');
|
|
|
2
2
|
var router = express.Router();
|
|
3
3
|
var TagLibrary = require("../models/tagLibrary");
|
|
4
4
|
var winston = require('../config/winston');
|
|
5
|
+
var numericInput = require('../utils/numericInput');
|
|
5
6
|
|
|
6
7
|
router.post('/', function (req, res) {
|
|
7
8
|
|
|
@@ -86,11 +87,9 @@ router.get('/:tagid', function (req, res) {
|
|
|
86
87
|
|
|
87
88
|
router.get('/', function (req, res) {
|
|
88
89
|
var limit = 40; // Number of Tags per page
|
|
89
|
-
var page = 0;
|
|
90
|
-
|
|
91
|
-
if (
|
|
92
|
-
page = req.query.page;
|
|
93
|
-
}
|
|
90
|
+
var page = numericInput.takeOptionalBoundedInteger(res, req.query.page, 0, 1000000, 'page');
|
|
91
|
+
if (page === null) return;
|
|
92
|
+
if (page === undefined) page = 0;
|
|
94
93
|
|
|
95
94
|
var skip = page * limit;
|
|
96
95
|
winston.debug('Tag ROUTE - SKIP PAGE ', skip);
|
|
@@ -104,10 +103,8 @@ router.get('/', function (req, res) {
|
|
|
104
103
|
// }
|
|
105
104
|
|
|
106
105
|
|
|
107
|
-
var direction =
|
|
108
|
-
if (
|
|
109
|
-
direction = req.query.direction;
|
|
110
|
-
}
|
|
106
|
+
var direction = numericInput.takeSortDirection(res, req.query.direction);
|
|
107
|
+
if (direction === null) return;
|
|
111
108
|
|
|
112
109
|
var sortField = "createdAt";
|
|
113
110
|
if (req.query.sort) {
|
package/routes/unanswered.js
CHANGED
|
@@ -4,6 +4,7 @@ const { Namespace, UnansweredQuestion } = require('../models/kb_setting');
|
|
|
4
4
|
var winston = require('../config/winston');
|
|
5
5
|
var fastCsv = require('fast-csv');
|
|
6
6
|
const kbQuestionService = require('../services/kbQuestionService');
|
|
7
|
+
const numericInput = require('../utils/numericInput');
|
|
7
8
|
|
|
8
9
|
// Add a new unanswered question
|
|
9
10
|
router.post('/', async (req, res) => {
|
|
@@ -49,10 +50,13 @@ router.get('/:namespace', async (req, res) => {
|
|
|
49
50
|
});
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
const
|
|
53
|
-
|
|
53
|
+
const paging = numericInput.takePagination(res, req.query, { defaultLimit: 20, maxLimit: 100, overMax: 'reject' });
|
|
54
|
+
if (!paging) return;
|
|
55
|
+
const page = paging.page;
|
|
56
|
+
const limit = paging.limit;
|
|
54
57
|
const sortField = req.query.sortField || 'createdAt';
|
|
55
|
-
const direction =
|
|
58
|
+
const direction = numericInput.takeSortDirection(res, req.query.direction);
|
|
59
|
+
if (direction === null) return;
|
|
56
60
|
|
|
57
61
|
const filter = { id_project, namespace };
|
|
58
62
|
|