@tiledesk/tiledesk-server 2.9.26 → 2.9.28

Sign up to get free protection for your applications and to get access to all the features.
package/routes/request.js CHANGED
@@ -901,17 +901,19 @@ router.get('/', function (req, res, next) {
901
901
  var skip = page * limit;
902
902
  winston.debug('REQUEST ROUTE - SKIP PAGE ', skip);
903
903
 
904
+ let statusArray = [];
904
905
 
905
906
  var query = { "id_project": req.projectid, "status": { $lt: 1000 }, preflight: false };
906
907
 
908
+
907
909
  var projectuser = req.projectuser;
908
910
 
909
911
 
910
912
  if (req.user instanceof Subscription) {
911
913
  //all request
912
914
  } else if (projectuser && (projectuser.role == "owner" || projectuser.role == "admin")) {
913
- //all request
914
- // per uni mostrare solo quelle priprio quindi solo participants
915
+ // all request
916
+ // per uni mostrare solo quelle proprie quindi solo participants
915
917
  if (req.query.mine) {
916
918
  query["$or"] = [{ "snapshot.agents.id_user": req.user.id }, { "participants": req.user.id }];
917
919
  }
@@ -919,9 +921,6 @@ router.get('/', function (req, res, next) {
919
921
  query["$or"] = [{ "snapshot.agents.id_user": req.user.id }, { "participants": req.user.id }];
920
922
  }
921
923
 
922
- // console.log('REQUEST ROUTE - req ', req);
923
- // console.log('REQUEST ROUTE - req.project ', req.project);
924
-
925
924
 
926
925
  if (req.query.dept_id) {
927
926
  query.department = req.query.dept_id;
@@ -937,19 +936,43 @@ router.get('/', function (req, res, next) {
937
936
  query.$text = { "$search": req.query.full_text };
938
937
  }
939
938
 
940
- var history_search = false;
939
+ var history_search = false; // ? serve ancora?
940
+
941
+ // if (req.query.status) {
942
+ // winston.debug('req.query.status', req.query.status);
943
+ // query.status = req.query.status;
944
+
945
+ // if (req.query.status == 1000 || req.query.status == "1000") {
946
+ // history_search = true;
947
+ // }
948
+ // if (req.query.status === "all") {
949
+ // history_search = true;
950
+ // delete query.status;
951
+ // }
952
+ // }
941
953
 
942
954
  if (req.query.status) {
943
- winston.debug('req.query.status', req.query.status);
944
- query.status = req.query.status;
945
955
 
946
- if (req.query.status == 1000 || req.query.status == "1000") {
947
- history_search = true;
948
- }
949
- if (req.query.status === "all") {
950
- history_search = true;
956
+ if (req.query.status === 'all') {
951
957
  delete query.status;
958
+ } else {
959
+ let statusArray = req.query.status.split(',').map(Number);
960
+ statusArray = statusArray.map(status => { return isNaN(status) ? null : status }).filter(status => status !== null)
961
+ if (statusArray.length > 0) {
962
+ query.status = {
963
+ $in: statusArray
964
+ }
965
+ } else {
966
+ delete query.status;
967
+ }
952
968
  }
969
+
970
+ if (statusArray.length > 0) {
971
+ query.status = {
972
+ $in: statusArray
973
+ }
974
+ }
975
+
953
976
  }
954
977
 
955
978
  if (req.query.lead) {
@@ -988,6 +1011,11 @@ router.get('/', function (req, res, next) {
988
1011
  query.ticket_id = req.query.ticket_id;
989
1012
  }
990
1013
 
1014
+ if (req.query.preflight && (req.query.preflight === 'true' || req.query.preflight === true)) {
1015
+ //query.preflight = req.query.preflight;
1016
+ delete query.preflight;
1017
+ }
1018
+
991
1019
  // if (req.query.request_id) {
992
1020
  // console.log('req.query.request_id', req.query.request_id);
993
1021
  // query.request_id = req.query.request_id;
@@ -1238,6 +1266,376 @@ router.get('/', function (req, res, next) {
1238
1266
 
1239
1267
  });
1240
1268
 
1269
+ // router.get('/', function (req, res, next) {
1270
+
1271
+ // const startExecTime = new Date();
1272
+
1273
+ // winston.debug("req projectid", req.projectid);
1274
+ // winston.debug("req.query.sort", req.query.sort);
1275
+ // winston.debug('REQUEST ROUTE - QUERY ', req.query)
1276
+
1277
+ // const DEFAULT_LIMIT = 40;
1278
+
1279
+ // var limit = DEFAULT_LIMIT; // Number of request per page
1280
+
1281
+ // if (req.query.limit) {
1282
+ // limit = parseInt(req.query.limit);
1283
+ // }
1284
+ // if (limit > 100) {
1285
+ // limit = DEFAULT_LIMIT;
1286
+ // }
1287
+
1288
+
1289
+ // var page = 0;
1290
+
1291
+ // if (req.query.page) {
1292
+ // page = req.query.page;
1293
+ // }
1294
+
1295
+ // var skip = page * limit;
1296
+ // winston.debug('REQUEST ROUTE - SKIP PAGE ', skip);
1297
+
1298
+
1299
+ // var query = { "id_project": req.projectid, "status": { $lt: 1000 }, preflight: false };
1300
+
1301
+ // var projectuser = req.projectuser;
1302
+
1303
+
1304
+ // if (req.user instanceof Subscription) {
1305
+ // //all request
1306
+ // } else if (projectuser && (projectuser.role == "owner" || projectuser.role == "admin")) {
1307
+ // //all request
1308
+ // // per uni mostrare solo quelle priprio quindi solo participants
1309
+ // if (req.query.mine) {
1310
+ // query["$or"] = [{ "snapshot.agents.id_user": req.user.id }, { "participants": req.user.id }];
1311
+ // }
1312
+ // } else {
1313
+ // query["$or"] = [{ "snapshot.agents.id_user": req.user.id }, { "participants": req.user.id }];
1314
+ // }
1315
+
1316
+ // // console.log('REQUEST ROUTE - req ', req);
1317
+ // // console.log('REQUEST ROUTE - req.project ', req.project);
1318
+
1319
+
1320
+ // if (req.query.dept_id) {
1321
+ // query.department = req.query.dept_id;
1322
+ // winston.debug('REQUEST ROUTE - QUERY DEPT ID', query.department);
1323
+ // }
1324
+
1325
+ // if (req.query.requester_email) {
1326
+ // query["snapshot.lead.email"] = req.query.requester_email;
1327
+ // }
1328
+
1329
+ // if (req.query.full_text) {
1330
+ // winston.debug('req.query.fulltext', req.query.full_text);
1331
+ // query.$text = { "$search": req.query.full_text };
1332
+ // }
1333
+
1334
+ // var history_search = false;
1335
+
1336
+ // if (req.query.status) {
1337
+ // winston.debug('req.query.status', req.query.status);
1338
+ // query.status = req.query.status;
1339
+
1340
+ // if (req.query.status == 1000 || req.query.status == "1000") {
1341
+ // history_search = true;
1342
+ // }
1343
+ // if (req.query.status === "all") {
1344
+ // history_search = true;
1345
+ // delete query.status;
1346
+ // }
1347
+ // }
1348
+
1349
+ // if (req.query.lead) {
1350
+ // winston.debug('req.query.lead', req.query.lead);
1351
+ // query.lead = req.query.lead;
1352
+ // }
1353
+
1354
+ // // USERS & BOTS
1355
+ // if (req.query.participant) {
1356
+ // winston.debug('req.query.participant', req.query.participant);
1357
+ // query.participants = req.query.participant;
1358
+ // }
1359
+
1360
+ // winston.debug('req.query.hasbot', req.query.hasbot);
1361
+ // if (req.query.hasbot != undefined) {
1362
+ // winston.debug('req.query.hasbot', req.query.hasbot);
1363
+ // query.hasBot = req.query.hasbot;
1364
+ // }
1365
+
1366
+ // // if (req.query.waiting_time_exists) { //non basta aggiungi anche che nn è null
1367
+ // // query.waiting_time = {"$exists": req.query.waiting_time_exists} //{$ne:null}
1368
+ // // winston.debug('REQUEST ROUTE - QUERY waiting_time_exists', query.waiting_time_exists);
1369
+ // // }
1370
+
1371
+
1372
+ // if (req.query.tags) {
1373
+ // winston.debug('req.query.tags', req.query.tags);
1374
+ // query["tags.tag"] = req.query.tags;
1375
+ // }
1376
+
1377
+ // if (req.query.location) {
1378
+ // query.location = req.query.location;
1379
+ // }
1380
+
1381
+ // if (req.query.ticket_id) {
1382
+ // query.ticket_id = req.query.ticket_id;
1383
+ // }
1384
+
1385
+ // if (req.query.preflight) {
1386
+ // query.preflight = req.query.preflight;
1387
+ // }
1388
+
1389
+ // // if (req.query.request_id) {
1390
+ // // console.log('req.query.request_id', req.query.request_id);
1391
+ // // query.request_id = req.query.request_id;
1392
+ // // }
1393
+
1394
+ // /**
1395
+ // **! *** DATE RANGE USECASE 1 ***
1396
+ // * in the tiledesk dashboard's HISTORY PAGE
1397
+ // * WHEN THE TRIAL IS EXIPIRED OR THE SUBSCIPTION IS NOT ACTIVE
1398
+ // * THE SEARCH FOR DATE INTERVAL OF THE HISTORY OF REQUESTS ARE DISABLED AND
1399
+ // * ARE DISPLAYED ONLY THE REQUESTS OF THE LAST 14 DAYS
1400
+ // */
1401
+ // //fixato. secondo me qui manca un parentesi tonda per gli or
1402
+ // if (history_search === true && req.project && req.project.profile && ((req.project.profile.type === 'free' && req.project.trialExpired === true) || (req.project.profile.type === 'payment' && req.project.isActiveSubscription === false))) {
1403
+
1404
+
1405
+ // var startdate = moment().subtract(14, "days").format("YYYY-MM-DD");
1406
+
1407
+ // var enddate = moment().format("YYYY-MM-DD");
1408
+
1409
+ // winston.debug('»»» REQUEST ROUTE - startdate ', startdate);
1410
+ // winston.debug('»»» REQUEST ROUTE - enddate ', enddate);
1411
+
1412
+ // var enddatePlusOneDay = moment(new Date()).add(1, 'days').toDate()
1413
+ // winston.debug('»»» REQUEST ROUTE - enddate + 1 days: ', enddatePlusOneDay);
1414
+
1415
+ // // var enddatePlusOneDay = "2019-09-17T00:00:00.000Z"
1416
+
1417
+ // query.createdAt = { $gte: new Date(Date.parse(startdate)).toISOString(), $lte: new Date(enddatePlusOneDay).toISOString() }
1418
+ // winston.debug('REQUEST ROUTE - QUERY CREATED AT ', query.createdAt);
1419
+
1420
+ // }
1421
+
1422
+ // /**
1423
+ // **! *** DATE RANGE USECASE 2 ***
1424
+ // * in the tiledesk dashboard's HISTORY PAGE
1425
+ // * WHEN THE USER SEARCH FOR DATE INTERVAL OF THE HISTORY OF REQUESTS
1426
+ // */
1427
+ // if (req.query.start_date && req.query.end_date) {
1428
+ // winston.debug('REQUEST ROUTE - REQ QUERY start_date ', req.query.start_date);
1429
+ // winston.debug('REQUEST ROUTE - REQ QUERY end_date ', req.query.end_date);
1430
+
1431
+ // /**
1432
+ // * USING TIMESTAMP in MS */
1433
+ // // var formattedStartDate = new Date(+req.query.start_date);
1434
+ // // var formattedEndDate = new Date(+req.query.end_date);
1435
+ // // query.createdAt = { $gte: formattedStartDate, $lte: formattedEndDate }
1436
+
1437
+ // /**
1438
+ // * USING MOMENT */
1439
+ // var startDate = moment(req.query.start_date, 'DD/MM/YYYY').format('YYYY-MM-DD');
1440
+ // var endDate = moment(req.query.end_date, 'DD/MM/YYYY').format('YYYY-MM-DD');
1441
+
1442
+ // winston.debug('REQUEST ROUTE - REQ QUERY FORMATTED START DATE ', startDate);
1443
+ // winston.debug('REQUEST ROUTE - REQ QUERY FORMATTED END DATE ', endDate);
1444
+
1445
+ // // ADD ONE DAY TO THE END DAY
1446
+ // var date = new Date(endDate);
1447
+ // var newdate = new Date(date);
1448
+ // var endDate_plusOneDay = newdate.setDate(newdate.getDate() + 1);
1449
+ // winston.debug('REQUEST ROUTE - REQ QUERY FORMATTED END DATE + 1 DAY ', endDate_plusOneDay);
1450
+ // // var endDate_plusOneDay = moment('2018-09-03').add(1, 'd')
1451
+ // // var endDate_plusOneDay = endDate.add(1).day();
1452
+ // // var toDate = new Date(Date.parse(endDate_plusOneDay)).toISOString()
1453
+
1454
+ // query.createdAt = { $gte: new Date(Date.parse(startDate)).toISOString(), $lte: new Date(endDate_plusOneDay).toISOString() }
1455
+ // winston.debug('REQUEST ROUTE - QUERY CREATED AT ', query.createdAt);
1456
+
1457
+ // } else if (req.query.start_date && !req.query.end_date) {
1458
+ // winston.debug('REQUEST ROUTE - REQ QUERY END DATE IS EMPTY (so search only for start date)');
1459
+ // var startDate = moment(req.query.start_date, 'DD/MM/YYYY').format('YYYY-MM-DD');
1460
+
1461
+ // var range = { $gte: new Date(Date.parse(startDate)).toISOString() };
1462
+ // if (req.query.filterRangeField) {
1463
+ // query[req.query.filterRangeField] = range;
1464
+ // } else {
1465
+ // query.createdAt = range;
1466
+ // }
1467
+
1468
+ // winston.debug('REQUEST ROUTE - QUERY CREATED AT (only for start date)', query.createdAt);
1469
+ // }
1470
+ // // }
1471
+
1472
+
1473
+
1474
+ // if (req.query.snap_department_routing) {
1475
+ // query["snapshot.department.routing"] = req.query.snap_department_routing;
1476
+ // winston.debug('REQUEST ROUTE - QUERY snap_department_routing', query.snap_department_routing);
1477
+ // }
1478
+
1479
+ // if (req.query.snap_department_default) {
1480
+ // query["snapshot.department.default"] = req.query.snap_department_default;
1481
+ // winston.debug('REQUEST ROUTE - QUERY snap_department_default', query.snap_department_default);
1482
+ // }
1483
+
1484
+
1485
+ // if (req.query.snap_department_id_bot) {
1486
+ // query["snapshot.department.id_bot"] = req.query.snap_department_id_bot;
1487
+ // winston.debug('REQUEST ROUTE - QUERY snap_department_id_bot', query.snap_department_id_bot);
1488
+ // }
1489
+
1490
+ // if (req.query.snap_department_id_bot_exists) {
1491
+ // query["snapshot.department.id_bot"] = { "$exists": req.query.snap_department_id_bot_exists }
1492
+ // winston.debug('REQUEST ROUTE - QUERY snap_department_id_bot_exists', query.snap_department_id_bot_exists);
1493
+ // }
1494
+
1495
+ // if (req.query.snap_lead_lead_id) {
1496
+ // query["snapshot.lead.lead_id"] = req.query.snap_lead_lead_id;
1497
+ // winston.debug('REQUEST ROUTE - QUERY snap_lead_lead_id', query.snap_lead_lead_id);
1498
+ // }
1499
+
1500
+ // if (req.query.snap_lead_email) {
1501
+ // query["snapshot.lead.email"] = req.query.snap_lead_email;
1502
+ // winston.debug('REQUEST ROUTE - QUERY snap_lead_email', query.snap_lead_email);
1503
+ // }
1504
+
1505
+ // if (req.query.smartAssignment) {
1506
+ // query.smartAssignment = req.query.smartAssignment;
1507
+ // winston.debug('REQUEST ROUTE - QUERY smartAssignment', query.smartAssignment);
1508
+ // }
1509
+
1510
+ // if (req.query.channel) {
1511
+ // if (req.query.channel === "offline") {
1512
+ // query["channel.name"] = { "$in": ["email", "form"] }
1513
+ // } else if (req.query.channel === "online") {
1514
+ // query["channel.name"] = { "$nin": ["email", "form"] }
1515
+ // } else {
1516
+ // query["channel.name"] = req.query.channel
1517
+ // }
1518
+
1519
+ // winston.debug('REQUEST ROUTE - QUERY channel', query.channel);
1520
+ // }
1521
+
1522
+ // if (req.query.priority) {
1523
+ // query.priority = req.query.priority;
1524
+ // }
1525
+
1526
+
1527
+ // var direction = -1; //-1 descending , 1 ascending
1528
+ // if (req.query.direction) {
1529
+ // direction = req.query.direction;
1530
+ // }
1531
+ // winston.debug("direction", direction);
1532
+
1533
+ // var sortField = "createdAt";
1534
+ // if (req.query.sort) {
1535
+ // sortField = req.query.sort;
1536
+ // }
1537
+ // winston.debug("sortField", sortField);
1538
+
1539
+ // var sortQuery = {};
1540
+ // sortQuery[sortField] = direction;
1541
+ // winston.debug("sort query", sortQuery);
1542
+
1543
+ // if (req.query.draft && (req.query.draft === 'false' || req.query.draft === false)) {
1544
+ // query.draft = { $in: [false, null] }
1545
+ // }
1546
+
1547
+ // winston.debug('REQUEST ROUTE - REQUEST FIND ', query);
1548
+
1549
+ // var projection = undefined;
1550
+
1551
+ // if (req.query.full_text) {
1552
+
1553
+ // if (req.query.no_textscore != "true" && req.query.no_textscore != true) {
1554
+ // winston.info('fulltext projection on');
1555
+ // projection = { score: { $meta: "textScore" } };
1556
+ // }
1557
+
1558
+ // }
1559
+ // // requestcachefarequi populaterequired
1560
+ // var q1 = Request.find(query, projection).
1561
+ // skip(skip).limit(limit);
1562
+
1563
+
1564
+
1565
+
1566
+
1567
+ // winston.debug('REQUEST ROUTE no_populate:' + req.query.no_populate);
1568
+
1569
+ // if (req.query.no_populate != "true" && req.query.no_populate != true) {
1570
+ // winston.verbose('REQUEST ROUTE - no_polutate false ', req.headers);
1571
+ // q1.populate('department').
1572
+ // populate('participatingBots'). //nico già nn gli usa
1573
+ // populate('participatingAgents'). //nico già nn gli usa
1574
+ // populate('lead').
1575
+ // populate({ path: 'requester', populate: { path: 'id_user' } }); //toglilo perche nico lo prende già da snapshot
1576
+ // }
1577
+
1578
+ // // cache(cacheUtil.defaultTTL, "requests-"+projectId).
1579
+
1580
+
1581
+ // // if (req.query.select_snapshot) {
1582
+ // // winston.info('select_snapshot');
1583
+ // // q1.select("+snapshot");
1584
+ // // // q1.select({ "snapshot": 1});
1585
+ // // }
1586
+
1587
+ // if (req.query.full_text) {
1588
+ // winston.debug('fulltext sort');
1589
+ // if (req.query.no_textscore != "true" && req.query.no_textscore != true) {
1590
+ // q1.sort({ score: { $meta: "textScore" } }) //https://docs.mongodb.com/manual/reference/operator/query/text/#sort-by-text-search-score
1591
+ // }
1592
+ // } else {
1593
+ // q1.sort(sortQuery);
1594
+ // }
1595
+
1596
+
1597
+ // // winston.info('q1',q1);
1598
+
1599
+
1600
+ // q1.exec();
1601
+
1602
+ // // TODO if ?onlycount=true do not perform find query but only
1603
+ // // set q1 to undefined; to skip query
1604
+
1605
+ // var q2 = Request.countDocuments(query).exec();
1606
+
1607
+ // if (req.query.no_count && req.query.no_count == "true") {
1608
+ // winston.info('REQUEST ROUTE - no_count ');
1609
+ // q2 = 0;
1610
+ // }
1611
+
1612
+ // var promises = [
1613
+ // q1,
1614
+ // q2
1615
+ // ];
1616
+
1617
+ // Promise.all(promises).then(function (results) {
1618
+ // var objectToReturn = {
1619
+ // perPage: limit,
1620
+ // count: results[1],
1621
+ // requests: results[0]
1622
+ // };
1623
+ // winston.debug('REQUEST ROUTE - objectToReturn ');
1624
+ // winston.debug('REQUEST ROUTE - objectToReturn ', objectToReturn);
1625
+
1626
+ // const endExecTime = new Date();
1627
+ // winston.verbose('REQUEST ROUTE - exec time: ' + (endExecTime - startExecTime));
1628
+
1629
+ // return res.json(objectToReturn);
1630
+
1631
+ // }).catch(function (err) {
1632
+ // winston.error('REQUEST ROUTE - REQUEST FIND ERR ', err);
1633
+ // return res.status(500).send({ success: false, msg: 'Error getting requests.', err: err });
1634
+ // });
1635
+
1636
+
1637
+ // });
1638
+
1241
1639
 
1242
1640
  // TODO converti con fast-csv e stream
1243
1641
  // DOWNLOAD HISTORY REQUESTS AS CSV
@@ -1257,6 +1655,8 @@ router.get('/csv', function (req, res, next) {
1257
1655
  var skip = page * limit;
1258
1656
  winston.debug('REQUEST ROUTE - SKIP PAGE ', skip);
1259
1657
 
1658
+ let statusArray = [];
1659
+
1260
1660
  var query = { "id_project": req.projectid };
1261
1661
 
1262
1662
  if (req.query.dept_id) {
@@ -1269,9 +1669,40 @@ router.get('/csv', function (req, res, next) {
1269
1669
  query.$text = { "$search": req.query.full_text };
1270
1670
  }
1271
1671
 
1672
+ // if (req.query.status) {
1673
+ // winston.debug('req.query.status', req.query.status);
1674
+ // query.status = req.query.status;
1675
+ // }
1676
+
1272
1677
  if (req.query.status) {
1273
- winston.debug('req.query.status', req.query.status);
1274
- query.status = req.query.status;
1678
+
1679
+ if (req.query.status === 'all') {
1680
+ delete query.status;
1681
+ } else {
1682
+ let statusArray = req.query.status.split(',').map(Number);
1683
+ statusArray = statusArray.map(status => { return isNaN(status) ? null : status }).filter(status => status !== null)
1684
+ if (statusArray.length > 0) {
1685
+ query.status = {
1686
+ $in: statusArray
1687
+ }
1688
+ } else {
1689
+ delete query.status;
1690
+ }
1691
+ }
1692
+
1693
+ if (statusArray.length > 0) {
1694
+ query.status = {
1695
+ $in: statusArray
1696
+ }
1697
+ }
1698
+
1699
+ }
1700
+
1701
+ if (req.query.preflight) {
1702
+ let preflight = (req.query.preflight === 'false');
1703
+ if (preflight) {
1704
+ query.preflight = false;
1705
+ }
1275
1706
  }
1276
1707
 
1277
1708
  if (req.query.lead) {
@@ -1464,50 +1895,153 @@ router.get('/csv', function (req, res, next) {
1464
1895
  });
1465
1896
 
1466
1897
  router.get('/count', async (req, res) => {
1467
-
1898
+
1468
1899
  let id_project = req.projectid;
1469
1900
  let merge_assigned = req.query.merge_assigned;
1901
+ let quota_count = false;
1902
+ if (req.query.conversation_quota === true || req.query.conversation_quota === 'true') {
1903
+ quota_count = true;
1904
+ }
1470
1905
 
1906
+ let open_count = 0;
1907
+ let closed_count = 0;
1471
1908
  let unassigned_count = 0;
1472
1909
  let human_assigned_count = 0;
1473
1910
  let bot_assigned_count = 0;
1474
1911
 
1475
- unassigned_count = await Request.countDocuments({ id_project: id_project, status: 100, preflight: false }).catch((err) => {
1476
- winston.error("Error getting unassigned requests count: ", err);
1477
- res.status(400).send({ success: false, error: err });
1478
- })
1479
- winston.debug("Unassigned count for project " + id_project + ": " + unassigned_count);
1480
-
1481
- human_assigned_count = await Request.countDocuments({ id_project: id_project, status: 200, preflight: false, hasBot: false }).catch((err) => {
1482
- winston.error("Error getting human unassigned requests count: ", err);
1483
- res.status(400).send({ success: false, error: err });
1484
- })
1485
- winston.debug("Human assigned count for project " + id_project + ": " + human_assigned_count);
1912
+ let currentSlot
1913
+ let promises = [];
1914
+
1915
+ if (quota_count) {
1916
+
1917
+ let quoteManager = req.app.get('quote_manager');
1918
+
1919
+ currentSlot = await quoteManager.getCurrentSlot(req.project);
1920
+ winston.debug("currentSlot: ", currentSlot)
1921
+ // Open count
1922
+ // Warning: 201 is a fake status -> Logical meaning: status < 1000;
1923
+ // (method) RequestService.getConversationsCount(id_project: any, status: any, preflight: any, hasBot: any): Promise<any>
1924
+ promises.push(requestService.getConversationsCount(id_project, 201, null, null, currentSlot.startDate, currentSlot.endDate).then((count) => {
1925
+ open_count = count;
1926
+ winston.debug("Unassigned count for project " + id_project + ": " + unassigned_count);
1927
+ }).catch((err) => {
1928
+ winston.error("Error getting unassigned conversation count");
1929
+ }))
1930
+
1931
+ // Closed count
1932
+ promises.push(requestService.getConversationsCount(id_project, RequestConstants.CLOSED, null, null, currentSlot.startDate, currentSlot.endDate).then((count) => {
1933
+ closed_count = count;
1934
+ winston.debug("Unassigned count for project " + id_project + ": " + unassigned_count);
1935
+ }).catch((err) => {
1936
+ winston.error("Error getting unassigned conversation count");
1937
+ }))
1938
+ } else {
1939
+ // Unassigned count
1940
+ promises.push(requestService.getConversationsCount(id_project, RequestConstants.UNASSIGNED, false, null, null, null).then((count) => {
1941
+ unassigned_count = count;
1942
+ winston.debug("Unassigned count for project " + id_project + ": " + unassigned_count);
1943
+ }).catch((err) => {
1944
+ winston.error("Error getting unassigned conversation count");
1945
+ }))
1946
+
1947
+ // Human assigned count
1948
+ promises.push(requestService.getConversationsCount(id_project, RequestConstants.ASSIGNED, false, false, null, null).then((count) => {
1949
+ human_assigned_count = count;
1950
+ winston.debug("Human assigned count for project " + id_project + ": " + human_assigned_count);
1951
+ }).catch((err) => {
1952
+ winston.error("Error getting human assigned conversation count");
1953
+ }))
1954
+
1955
+ // Bot assigned count
1956
+ promises.push(requestService.getConversationsCount(id_project, RequestConstants.ASSIGNED, false, true, null, null).then((count) => {
1957
+ bot_assigned_count = count;
1958
+ winston.debug("Bot assigned count for project " + id_project + ": " + bot_assigned_count);
1959
+ }).catch((err) => {
1960
+ winston.error("Error getting bot assigned conversation count");
1961
+ }))
1962
+ }
1963
+
1964
+ Promise.all(promises).then((response) => {
1965
+
1966
+ if (quota_count) {
1967
+ let data = {
1968
+ open: open_count,
1969
+ closed: closed_count,
1970
+ slot: {
1971
+ startDate: currentSlot.startDate.format('DD/MM/YYYY'),
1972
+ endDate: currentSlot.endDate.format('DD/MM/YYYY')
1973
+ }
1974
+ }
1975
+ return res.status(200).send(data);
1976
+ } else {
1977
+ if (merge_assigned) {
1978
+ let data = {
1979
+ unassigned: unassigned_count,
1980
+ assigned: human_assigned_count + bot_assigned_count
1981
+ }
1982
+ return res.status(200).send(data);
1983
+
1984
+ } else {
1985
+ let data = {
1986
+ unassigned: unassigned_count,
1987
+ assigned: human_assigned_count,
1988
+ bot_assigned: bot_assigned_count
1989
+ }
1990
+ return res.status(200).send(data);
1991
+ }
1992
+ }
1486
1993
 
1487
- bot_assigned_count = await Request.countDocuments({ id_project: id_project, status: 200, preflight: false, hasBot: true }).catch((err) => {
1488
- winston.error("Error getting bot assigned requests count: ", err);
1489
- res.status(400).send({ success: false, error: err });
1994
+ }).catch((err) => {
1995
+ console.error("err: ", err);
1996
+ return res.status(400).send({ success: false, error: err });
1490
1997
  })
1491
- winston.debug("Bot assigned count for project " + id_project + ": " + bot_assigned_count);
1492
-
1998
+ })
1493
1999
 
1494
- if (merge_assigned) {
1495
- let data = {
1496
- unassigned: unassigned_count,
1497
- assigned: human_assigned_count + bot_assigned_count
1498
- }
1499
- return res.status(200).send(data);
2000
+ // router.get('/count', async (req, res) => {
2001
+
2002
+ // let id_project = req.projectid;
2003
+ // let merge_assigned = req.query.merge_assigned;
2004
+
2005
+ // let unassigned_count = 0;
2006
+ // let human_assigned_count = 0;
2007
+ // let bot_assigned_count = 0;
2008
+
2009
+ // unassigned_count = await Request.countDocuments({ id_project: id_project, status: 100, preflight: false }).catch((err) => {
2010
+ // winston.error("Error getting unassigned requests count: ", err);
2011
+ // res.status(400).send({ success: false, error: err });
2012
+ // })
2013
+ // winston.debug("Unassigned count for project " + id_project + ": " + unassigned_count);
2014
+
2015
+ // human_assigned_count = await Request.countDocuments({ id_project: id_project, status: 200, preflight: false, hasBot: false }).catch((err) => {
2016
+ // winston.error("Error getting human unassigned requests count: ", err);
2017
+ // res.status(400).send({ success: false, error: err });
2018
+ // })
2019
+ // winston.debug("Human assigned count for project " + id_project + ": " + human_assigned_count);
2020
+
2021
+ // bot_assigned_count = await Request.countDocuments({ id_project: id_project, status: 200, preflight: false, hasBot: true }).catch((err) => {
2022
+ // winston.error("Error getting bot assigned requests count: ", err);
2023
+ // res.status(400).send({ success: false, error: err });
2024
+ // })
2025
+ // winston.debug("Bot assigned count for project " + id_project + ": " + bot_assigned_count);
2026
+
2027
+
2028
+ // if (merge_assigned) {
2029
+ // let data = {
2030
+ // unassigned: unassigned_count,
2031
+ // assigned: human_assigned_count + bot_assigned_count
2032
+ // }
2033
+ // return res.status(200).send(data);
1500
2034
 
1501
- } else {
1502
- let data = {
1503
- unassigned: unassigned_count,
1504
- assigned: human_assigned_count,
1505
- bot_assigned: bot_assigned_count
1506
- }
1507
- return res.status(200).send(data);
1508
- }
2035
+ // } else {
2036
+ // let data = {
2037
+ // unassigned: unassigned_count,
2038
+ // assigned: human_assigned_count,
2039
+ // bot_assigned: bot_assigned_count
2040
+ // }
2041
+ // return res.status(200).send(data);
2042
+ // }
1509
2043
 
1510
- })
2044
+ // })
1511
2045
 
1512
2046
  router.get('/:requestid', function (req, res) {
1513
2047