@tiledesk/tiledesk-server 2.10.13 → 2.10.14

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
+ # 2.10.14
9
+ - Updated tybot-connector to 0.2.127
10
+ - Restored request.js file
11
+
8
12
  # 2.10.13
9
13
  - Updated tybot-connector to 0.2.127
10
14
  - Added event on request fully abandoned
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-server",
3
3
  "description": "The Tiledesk server module",
4
- "version": "2.10.13",
4
+ "version": "2.10.14",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
package/routes/request.js CHANGED
@@ -30,7 +30,6 @@ csv.separator = ';';
30
30
 
31
31
  const { check, validationResult } = require('express-validator');
32
32
  const RoleConstants = require('../models/roleConstants');
33
- const eventService = require('../pubmodules/events/eventService');
34
33
 
35
34
  // var messageService = require('../services/messageService');
36
35
 
@@ -183,7 +182,7 @@ router.post('/',
183
182
 
184
183
  winston.debug('res.json(savedRequest)');
185
184
  var endTimestamp = new Date();
186
- winston.verbose("(Request Route) request create end: " + (endTimestamp - startTimestamp));
185
+ winston.verbose("request create end: " + (endTimestamp - startTimestamp));
187
186
  return res.json(savedRequest);
188
187
  // });
189
188
  // });
@@ -274,7 +273,7 @@ router.patch('/:requestid', function (req, res) {
274
273
 
275
274
 
276
275
 
277
- winston.verbose("(Request Route) Request patch update", update);
276
+ winston.verbose("Request patch update", update);
278
277
 
279
278
  //cacheinvalidation
280
279
  return Request.findOneAndUpdate({ "request_id": req.params.requestid, "id_project": req.projectid }, { $set: update }, { new: true, upsert: false })
@@ -327,18 +326,18 @@ router.put('/:requestid/close', async function (req, res) {
327
326
  })
328
327
 
329
328
  if (!request) {
330
- winston.verbose("(Request Route) Request with request_id " + request_id)
329
+ winston.verbose("Request with request_id " + request_id)
331
330
  return res.status(404).send({ success: false, error: "Request not found"})
332
331
  }
333
332
 
334
333
  if (!request.participantsAgents.includes(req.user.id)) {
335
- winston.verbose("(Request Route) Request can't be closed by a non participant. Attempt made by " + req.user.id);
334
+ winston.verbose("Request can't be closed by a non participant. Attempt made by " + req.user.id);
336
335
  return res.status(403).send({ success: false, error: "You must be among the participants to close a conversation."})
337
336
  }
338
337
  }
339
338
 
340
339
  return requestService.closeRequestByRequestId(req.params.requestid, req.projectid, false, true, closed_by, req.body.force).then(function (closedRequest) {
341
- winston.verbose("(Request Route) request closed", closedRequest);
340
+ winston.verbose("request closed", closedRequest);
342
341
  return res.json(closedRequest);
343
342
  });
344
343
 
@@ -350,7 +349,7 @@ router.put('/:requestid/reopen', function (req, res) {
350
349
  // reopenRequestByRequestId(request_id, id_project) {
351
350
  return requestService.reopenRequestByRequestId(req.params.requestid, req.projectid).then(function (reopenRequest) {
352
351
 
353
- winston.verbose("(Request Route) request reopen", reopenRequest);
352
+ winston.verbose("request reopen", reopenRequest);
354
353
 
355
354
  return res.json(reopenRequest);
356
355
  });
@@ -381,7 +380,7 @@ router.post('/:requestid/participants',
381
380
  //addParticipantByRequestId(request_id, id_project, member)
382
381
  return requestService.addParticipantByRequestId(req.params.requestid, req.projectid, req.body.member).then(function (updatedRequest) {
383
382
 
384
- winston.verbose("(Request Route) participant added", updatedRequest);
383
+ winston.verbose("participant added", updatedRequest);
385
384
 
386
385
  return res.json(updatedRequest);
387
386
  });
@@ -421,7 +420,7 @@ router.delete('/:requestid/participants/:participantid', function (req, res) {
421
420
  //removeParticipantByRequestId(request_id, id_project, member)
422
421
  return requestService.removeParticipantByRequestId(req.params.requestid, req.projectid, req.params.participantid).then(function (updatedRequest) {
423
422
 
424
- winston.verbose("(Request Route) participant removed", updatedRequest);
423
+ winston.verbose("participant removed", updatedRequest);
425
424
 
426
425
  return res.json(updatedRequest);
427
426
  });
@@ -452,16 +451,10 @@ router.delete('/:requestid/participants/:participantid', function (req, res) {
452
451
  router.put('/:requestid/assign', function (req, res) {
453
452
  winston.debug(req.body);
454
453
 
455
- let id_project = req.projectid;
456
- let user = req.user;
457
- let pu;
458
- if (req.projectuser) {
459
- pu = req.projectuser.id;
460
- }
461
-
462
454
  // leggi la request se già assegnata o già chiusa (1000) esci
463
- // cacheinvalidation
464
- return Request.findOne({ "request_id": req.params.requestid, "id_project": id_project })
455
+
456
+ //cacheinvalidation
457
+ return Request.findOne({ "request_id": req.params.requestid, "id_project": req.projectid })
465
458
  .exec(function (err, request) {
466
459
 
467
460
  if (err) {
@@ -474,17 +467,13 @@ router.put('/:requestid/assign', function (req, res) {
474
467
  }
475
468
 
476
469
  if (request.status === RequestConstants.ASSIGNED || request.status === RequestConstants.SERVED || request.status === RequestConstants.CLOSED) {
477
- winston.verbose('(Request Route) Request already assigned');
470
+ winston.info('Request already assigned');
478
471
  return res.json(request);
479
472
  }
480
473
  //route(request_id, departmentid, id_project) {
481
- requestService.route(req.params.requestid, req.body.departmentid, id_project, req.body.nobot, req.body.no_populate).then(function (updatedRequest) {
474
+ requestService.route(req.params.requestid, req.body.departmentid, req.projectid, req.body.nobot, req.body.no_populate).then(function (updatedRequest) {
482
475
 
483
- winston.debug("request routed ", updatedRequest);
484
-
485
- if (updatedRequest.status === RequestConstants.ABANDONED) {
486
- eventService.emit('request.fully_abandoned', updatedRequest, id_project, pu, user._id, undefined, user);
487
- }
476
+ winston.debug("department changed", updatedRequest);
488
477
 
489
478
  return res.json(updatedRequest);
490
479
  }).catch(function (error) {
@@ -635,7 +624,7 @@ router.patch('/:requestid/attributes', function (req, res) {
635
624
  winston.error("error saving request attributes", err)
636
625
  return res.status(500).send({ success: false, msg: 'Error getting object.' });
637
626
  }
638
- winston.verbose("(Request Route) saved request attributes", savedRequest.toObject())
627
+ winston.verbose(" saved request attributes", savedRequest.toObject())
639
628
  requestEvent.emit("request.update", savedRequest);
640
629
  requestEvent.emit("request.update.comment", { comment: "ATTRIBUTES_PATCH", request: savedRequest });//Deprecated
641
630
  requestEvent.emit("request.updated", { comment: "ATTRIBUTES_PATCH", request: savedRequest, patch: { attributes: data } });
@@ -668,7 +657,7 @@ router.post('/:requestid/notes', async function (req, res) {
668
657
 
669
658
  // Check if the user is a participant
670
659
  if (!request.participantsAgents.includes(req.user.id)) {
671
- winston.verbose("(Request Route) Trying to add a note from a non participating agent");
660
+ winston.verbose("Trying to add a note from a non participating agent");
672
661
  return res.status(403).send({ success: false, error: "You are not participating in the conversation"})
673
662
  }
674
663
  }
@@ -714,7 +703,7 @@ router.delete('/:requestid/notes/:noteid', async function (req, res) {
714
703
 
715
704
  // Check if the user is a participant
716
705
  if (!request.participantsAgents.includes(req.user.id)) {
717
- winston.verbose("(Request Route) Trying to delete a note from a non participating agent");
706
+ winston.verbose("Trying to delete a note from a non participating agent");
718
707
  return res.status(403).send({ success: false, error: "You are not participating in the conversation"})
719
708
  }
720
709
  }
@@ -784,7 +773,7 @@ router.post('/:requestid/email/send',
784
773
  }
785
774
 
786
775
  let newto = request.lead.email
787
- winston.verbose("(Request Route) Sending an email newto " + newto);
776
+ winston.verbose("Sending an email newto " + newto);
788
777
 
789
778
  //sendEmailDirect(to, text, project, request_id, subject, tokenQueryString, sourcePage, payload)
790
779
  emailService.sendEmailDirect(newto, text, req.project, request_id, subject, undefined, undefined, undefined, replyto);
@@ -807,7 +796,7 @@ router.post('/:requestid/followers',
807
796
  check('member').notEmpty(),
808
797
  ],
809
798
  function (req, res) {
810
- winston.verbose("(Request Route) followers add", req.body);
799
+ winston.info("followers add", req.body);
811
800
 
812
801
  const errors = validationResult(req);
813
802
  if (!errors.isEmpty()) {
@@ -817,7 +806,7 @@ router.post('/:requestid/followers',
817
806
  //addParticipantByRequestId(request_id, id_project, member)
818
807
  return requestService.addFollowerByRequestId(req.params.requestid, req.projectid, req.body.member).then(function (updatedRequest) {
819
808
 
820
- winston.verbose("(Request Route) participant added", updatedRequest);
809
+ winston.verbose("participant added", updatedRequest);
821
810
 
822
811
  return res.json(updatedRequest);
823
812
  });
@@ -850,7 +839,7 @@ router.delete('/:requestid/followers/:followerid', function (req, res) {
850
839
  //removeFollowerByRequestId(request_id, id_project, member)
851
840
  return requestService.removeFollowerByRequestId(req.params.requestid, req.projectid, req.params.followerid).then(function (updatedRequest) {
852
841
 
853
- winston.verbose("(Request Route) follower removed", updatedRequest);
842
+ winston.verbose("follower removed", updatedRequest);
854
843
 
855
844
  return res.json(updatedRequest);
856
845
  });
@@ -877,7 +866,7 @@ router.delete('/:requestid', function (req, res) {
877
866
  if (err) {
878
867
  return res.status(500).send({ success: false, msg: 'Error deleting messages.' });
879
868
  }
880
- winston.verbose('(Request Route) Messages deleted for the recipient: ' + req.params.requestid);
869
+ winston.verbose('Messages deleted for the recipient: ' + req.params.requestid);
881
870
  });
882
871
 
883
872
 
@@ -891,7 +880,7 @@ router.delete('/:requestid', function (req, res) {
891
880
  return res.status(404).send({ success: false, msg: 'Object not found.' });
892
881
  }
893
882
 
894
- winston.verbose('(Request Route) Request deleted with request_id: ' + req.params.requestid);
883
+ winston.verbose('Request deleted with request_id: ' + req.params.requestid);
895
884
 
896
885
  requestEvent.emit('request.delete', request);
897
886
 
@@ -939,7 +928,7 @@ router.delete('/id/:id', function (req, res) {
939
928
  return res.status(404).send({ success: false, msg: 'Object not found.' });
940
929
  }
941
930
 
942
- winston.verbose('(Request Route) Request deleted with id: ' + req.params.id);
931
+ winston.verbose('Request deleted with id: ' + req.params.id);
943
932
 
944
933
  requestEvent.emit('request.delete', request);
945
934
 
@@ -1212,7 +1201,7 @@ router.get('/', function (req, res, next) {
1212
1201
  } else if (req.query.duration_op === 'lt') {
1213
1202
  query.duration = { $lte: duration }
1214
1203
  } else {
1215
- winston.verbose("(Request Route) Duration operator can be 'gt' or 'lt'. Skip duration_op " + req.query.duration_op)
1204
+ winston.verbose("Duration operator can be 'gt' or 'lt'. Skip duration_op " + req.query.duration_op)
1216
1205
  }
1217
1206
  }
1218
1207
 
@@ -1228,12 +1217,12 @@ router.get('/', function (req, res, next) {
1228
1217
 
1229
1218
  if (req.query.full_text) {
1230
1219
  if (req.query.no_textscore != "true" && req.query.no_textscore != true) {
1231
- winston.verbose('(Request Route) fulltext projection on');
1220
+ winston.verbose('fulltext projection on');
1232
1221
  projection = { score: { $meta: "textScore" } };
1233
1222
  }
1234
1223
  }
1235
1224
 
1236
- winston.verbose('(Request Route) Find request with query ', query);
1225
+ winston.verbose('REQUEST ROUTE - REQUEST FIND QUERY ', query);
1237
1226
 
1238
1227
  var q1 = Request.find(query, projection).
1239
1228
  skip(skip).limit(limit);
@@ -1262,7 +1251,7 @@ router.get('/', function (req, res, next) {
1262
1251
  var q2 = Request.countDocuments(query).exec();
1263
1252
 
1264
1253
  if (req.query.no_count && req.query.no_count == "true") {
1265
- winston.verbose('(Request Route) - no_count');
1254
+ winston.info('REQUEST ROUTE - no_count ');
1266
1255
  q2 = 0;
1267
1256
  }
1268
1257
 
@@ -1274,16 +1263,16 @@ router.get('/', function (req, res, next) {
1274
1263
  count: results[1],
1275
1264
  requests: results[0]
1276
1265
  };
1277
- winston.debug('(Request Route) - objectToReturn ');
1278
- winston.debug('(Request Route) - objectToReturn ', objectToReturn);
1266
+ winston.debug('REQUEST ROUTE - objectToReturn ');
1267
+ winston.debug('REQUEST ROUTE - objectToReturn ', objectToReturn);
1279
1268
 
1280
1269
  const endExecTime = new Date();
1281
- winston.verbose('(Request Route) - exec time: ' + (endExecTime - startExecTime));
1270
+ winston.verbose('REQUEST ROUTE - exec time: ' + (endExecTime - startExecTime));
1282
1271
 
1283
1272
  return res.json(objectToReturn);
1284
1273
 
1285
1274
  }).catch(function (err) {
1286
- winston.error('(Request Route) find request error ', err);
1275
+ winston.error('REQUEST ROUTE - REQUEST FIND ERR ', err);
1287
1276
  return res.status(500).send({ success: false, msg: 'Error getting requests.', err: err });
1288
1277
  });
1289
1278
 
@@ -1835,7 +1824,7 @@ router.get('/csv', function (req, res, next) {
1835
1824
  } else if (req.query.duration_op === 'lt') {
1836
1825
  query.duration = { $lte: duration }
1837
1826
  } else {
1838
- winston.verbose("(Request Route) Duration operator can be 'gt' or 'lt'. Skip duration_op " + req.query.duration_op)
1827
+ winston.verbose("Duration operator can be 'gt' or 'lt'. Skip duration_op " + req.query.duration_op)
1839
1828
  }
1840
1829
  }
1841
1830
 
@@ -2162,4 +2151,4 @@ router.get('/:requestid/chatbot/parameters', async (req, res) => {
2162
2151
 
2163
2152
  })
2164
2153
 
2165
- module.exports = router;
2154
+ module.exports = router;