@tiledesk/tiledesk-server 2.9.30 → 2.9.32
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +9 -0
- package/models/requestConstants.js +1 -0
- package/package.json +2 -2
- package/pubmodules/routing-queue/listener.js +5 -1
- package/pubmodules/routing-queue/listenerQueued.js +1 -1
- package/routes/project.js +108 -1
- package/routes/request.js +93 -107
- package/services/requestService.js +14 -0
- package/test/projectRoute.js +41 -0
- package/websocket/webSocketServer.js +1 -1
package/CHANGELOG.md
CHANGED
@@ -5,6 +5,15 @@
|
|
5
5
|
🚀 IN PRODUCTION 🚀
|
6
6
|
(https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
|
7
7
|
|
8
|
+
# 2.9.32
|
9
|
+
- Added voice filters in get requests
|
10
|
+
- Added endpoint to get all projects
|
11
|
+
- Updated vxml-connector to 0.1.49
|
12
|
+
|
13
|
+
# 2.9.31
|
14
|
+
- Improved conversations queues management
|
15
|
+
- Added conversation status 150 (ABANDONED)
|
16
|
+
|
8
17
|
# 2.9.30
|
9
18
|
- Restore Voice and SMS modules
|
10
19
|
|
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.9.
|
4
|
+
"version": "2.9.32",
|
5
5
|
"scripts": {
|
6
6
|
"start": "node ./bin/www",
|
7
7
|
"pretest": "mongodb-runner start",
|
@@ -52,7 +52,7 @@
|
|
52
52
|
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.73",
|
53
53
|
"@tiledesk/tiledesk-whatsapp-jobworker": "^0.0.8",
|
54
54
|
"@tiledesk/tiledesk-sms-connector": "^0.1.10",
|
55
|
-
"@tiledesk/tiledesk-vxml-connector": "^0.1.
|
55
|
+
"@tiledesk/tiledesk-vxml-connector": "^0.1.49",
|
56
56
|
"amqplib": "^0.5.5",
|
57
57
|
"app-root-path": "^3.0.0",
|
58
58
|
"bcrypt-nodejs": "0.0.3",
|
@@ -177,7 +177,11 @@ class Listener {
|
|
177
177
|
winston.debug("abandoned_by_project_usersAsArray", abandoned_by_project_usersAsArray);
|
178
178
|
|
179
179
|
var available_agents_not_busy = available_agents_not_busy.filter(projectUser=> !abandoned_by_project_usersAsArray.includes(projectUser._id.toString()))
|
180
|
-
|
180
|
+
|
181
|
+
if (available_agents_not_busy.length == 0) {
|
182
|
+
res.context.request.attributes.fully_abandoned = true;
|
183
|
+
}
|
184
|
+
|
181
185
|
winston.debug("available_agents_not_busy after: ", available_agents_not_busy );
|
182
186
|
}
|
183
187
|
}
|
@@ -50,7 +50,7 @@ class Listener {
|
|
50
50
|
return winston.warn("Chatbot is not a project_user. Skip update.")
|
51
51
|
}
|
52
52
|
|
53
|
-
return Request.countDocuments({ id_project: id_project, participantsAgents: id_user, status: { $lt: 1000 } }, (err, requestsCount) => {
|
53
|
+
return Request.countDocuments({ id_project: id_project, participantsAgents: id_user, status: { $lt: 1000 }, draft: { $in: [null, false] } }, (err, requestsCount) => {
|
54
54
|
winston.verbose("requestsCount for id_user: ", id_user, "and project: ", id_project, "-->", requestsCount);
|
55
55
|
if (err) {
|
56
56
|
return winston.error(err);
|
package/routes/project.js
CHANGED
@@ -13,7 +13,7 @@ var Group = require('../models/group');
|
|
13
13
|
|
14
14
|
var winston = require('../config/winston');
|
15
15
|
var roleChecker = require('../middleware/has-role');
|
16
|
-
|
16
|
+
var config = require('../config/database');
|
17
17
|
|
18
18
|
// THE THREE FOLLOWS IMPORTS ARE USED FOR AUTHENTICATION IN THE ROUTE
|
19
19
|
var passport = require('passport');
|
@@ -25,6 +25,24 @@ var orgUtil = require("../utils/orgUtil");
|
|
25
25
|
var cacheEnabler = require("../services/cacheEnabler");
|
26
26
|
var mongoose = require('mongoose');
|
27
27
|
|
28
|
+
var jwt = require('jsonwebtoken');
|
29
|
+
// CHECK IT ASAP!!!!
|
30
|
+
let configSecret = process.env.GLOBAL_SECRET || config.secret;
|
31
|
+
var pKey = process.env.GLOBAL_SECRET_OR_PRIVATE_KEY;
|
32
|
+
// console.log("pKey",pKey);
|
33
|
+
|
34
|
+
if (pKey) {
|
35
|
+
configSecret = pKey.replace(/\\n/g, '\n');
|
36
|
+
}
|
37
|
+
|
38
|
+
let pubConfigSecret = process.env.GLOBAL_SECRET || config.secret;
|
39
|
+
var pubKey = process.env.GLOBAL_SECRET_OR_PUB_KEY;
|
40
|
+
if (pubKey) {
|
41
|
+
pubConfigSecret = pubKey.replace(/\\n/g, '\n');
|
42
|
+
}
|
43
|
+
// CHECK IT ASAP!!!!
|
44
|
+
|
45
|
+
|
28
46
|
router.post('/', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], async (req, res) => {
|
29
47
|
|
30
48
|
// create(name, createdBy, settings)
|
@@ -735,6 +753,95 @@ Project.findByIdAndUpdate(req.params.projectid, { $pull: { bannedUsers: { "_id":
|
|
735
753
|
|
736
754
|
});
|
737
755
|
|
756
|
+
router.get('/all', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], function (req, res) {
|
757
|
+
|
758
|
+
if (req.headers.authorization) {
|
759
|
+
|
760
|
+
let token = req.headers.authorization.split(" ")[1];
|
761
|
+
let decode = jwt.verify(token, pubConfigSecret)
|
762
|
+
if (decode && (decode.email === process.env.ADMIN_EMAIL)) {
|
763
|
+
|
764
|
+
Project.aggregate([
|
765
|
+
// {
|
766
|
+
// $match: {
|
767
|
+
// status: 100,
|
768
|
+
// //createdAt: { $gte: startDate}
|
769
|
+
// },
|
770
|
+
// },
|
771
|
+
{
|
772
|
+
$sort: {
|
773
|
+
createdAt: -1
|
774
|
+
},
|
775
|
+
},
|
776
|
+
{
|
777
|
+
$lookup: {
|
778
|
+
from: 'project_users',
|
779
|
+
localField: '_id',
|
780
|
+
foreignField: 'id_project',
|
781
|
+
as: 'project_user',
|
782
|
+
pipeline: [
|
783
|
+
{ $match: { role: 'owner' } }
|
784
|
+
]
|
785
|
+
}
|
786
|
+
},
|
787
|
+
{
|
788
|
+
$addFields: {
|
789
|
+
project_user: { $arrayElemAt: ['$project_user', 0] }
|
790
|
+
}
|
791
|
+
},
|
792
|
+
{
|
793
|
+
$lookup: {
|
794
|
+
from: 'users',
|
795
|
+
localField: 'project_user.id_user',
|
796
|
+
foreignField: '_id',
|
797
|
+
as: 'user'
|
798
|
+
},
|
799
|
+
},
|
800
|
+
{
|
801
|
+
$addFields: {
|
802
|
+
user: { $arrayElemAt: ['$user', 0] }
|
803
|
+
}
|
804
|
+
}
|
805
|
+
])
|
806
|
+
.then((projects) => {
|
807
|
+
winston.verbose("Projects found " + projects.length)
|
808
|
+
// const fieldsToKeep = ['_id', 'name', 'createdBy', 'createdAt', 'user.email' ];
|
809
|
+
|
810
|
+
const filteredProjects = projects.map(project => {
|
811
|
+
const filteredProject = {};
|
812
|
+
filteredProject._id = project._id;
|
813
|
+
filteredProject.name = project.name;
|
814
|
+
filteredProject.owner = project.user?.email;
|
815
|
+
filteredProject.createdAt = project.createdAt;
|
816
|
+
filteredProject.profile_name = project.profile?.name;
|
817
|
+
// ... add other fields here
|
818
|
+
|
819
|
+
// fieldsToKeep.forEach(field => {
|
820
|
+
// if (project[field] !== undefined) {
|
821
|
+
// filteredProject[field] = project[field];
|
822
|
+
// }
|
823
|
+
// });
|
824
|
+
return filteredProject;
|
825
|
+
});
|
826
|
+
|
827
|
+
return res.status(200).send(filteredProjects);
|
828
|
+
})
|
829
|
+
.catch((err) => {
|
830
|
+
console.error(err);
|
831
|
+
return res.status(500).send({ success: false, error: err});
|
832
|
+
});
|
833
|
+
|
834
|
+
// let updatedUser = await User.findByIdAndUpdate(savedUser._id, { emailverified: true }, { new: true }).exec();
|
835
|
+
// winston.debug("updatedUser: ", updatedUser);
|
836
|
+
// skipVerificationEmail = true;
|
837
|
+
// winston.verbose("skip sending verification email")
|
838
|
+
} else {
|
839
|
+
return res.status(403).send({ success: false, error: "You don't have the permission required to perform the operation"});
|
840
|
+
}
|
841
|
+
|
842
|
+
}
|
843
|
+
|
844
|
+
});
|
738
845
|
|
739
846
|
|
740
847
|
//roleChecker.hasRole('agent') works because req.params.projectid is valid using :projectid of this method
|
package/routes/request.js
CHANGED
@@ -881,8 +881,13 @@ router.get('/', function (req, res, next) {
|
|
881
881
|
winston.debug('REQUEST ROUTE - QUERY ', req.query)
|
882
882
|
|
883
883
|
const DEFAULT_LIMIT = 40;
|
884
|
-
|
884
|
+
|
885
|
+
var page = 0;
|
885
886
|
var limit = DEFAULT_LIMIT; // Number of request per page
|
887
|
+
var page = 0;
|
888
|
+
var skip = 0;
|
889
|
+
let statusArray = [];
|
890
|
+
var projectuser = req.projectuser;
|
886
891
|
|
887
892
|
if (req.query.limit) {
|
888
893
|
limit = parseInt(req.query.limit);
|
@@ -891,29 +896,20 @@ router.get('/', function (req, res, next) {
|
|
891
896
|
limit = DEFAULT_LIMIT;
|
892
897
|
}
|
893
898
|
|
894
|
-
|
895
|
-
var page = 0;
|
896
|
-
|
897
899
|
if (req.query.page) {
|
898
900
|
page = req.query.page;
|
899
901
|
}
|
900
902
|
|
901
|
-
|
902
|
-
winston.debug('REQUEST ROUTE - SKIP PAGE ', skip);
|
903
|
-
|
904
|
-
let statusArray = [];
|
905
|
-
|
906
|
-
var query = { "id_project": req.projectid, "status": { $lt: 1000 }, preflight: false };
|
907
|
-
|
908
|
-
|
909
|
-
var projectuser = req.projectuser;
|
903
|
+
skip = page * limit;
|
910
904
|
|
905
|
+
// Default query
|
906
|
+
var query = { "id_project": req.projectid, "status": { $lt: 1000, $ne: 150 }, preflight: false };
|
911
907
|
|
912
908
|
if (req.user instanceof Subscription) {
|
913
|
-
//
|
909
|
+
// All request
|
914
910
|
} else if (projectuser && (projectuser.role == "owner" || projectuser.role == "admin")) {
|
915
|
-
//
|
916
|
-
//
|
911
|
+
// All request
|
912
|
+
// Per uni mostrare solo quelle proprie quindi solo participants
|
917
913
|
if (req.query.mine) {
|
918
914
|
query["$or"] = [{ "snapshot.agents.id_user": req.user.id }, { "participants": req.user.id }];
|
919
915
|
}
|
@@ -921,10 +917,8 @@ router.get('/', function (req, res, next) {
|
|
921
917
|
query["$or"] = [{ "snapshot.agents.id_user": req.user.id }, { "participants": req.user.id }];
|
922
918
|
}
|
923
919
|
|
924
|
-
|
925
920
|
if (req.query.dept_id) {
|
926
921
|
query.department = req.query.dept_id;
|
927
|
-
winston.debug('REQUEST ROUTE - QUERY DEPT ID', query.department);
|
928
922
|
}
|
929
923
|
|
930
924
|
if (req.query.requester_email) {
|
@@ -932,27 +926,13 @@ router.get('/', function (req, res, next) {
|
|
932
926
|
}
|
933
927
|
|
934
928
|
if (req.query.full_text) {
|
935
|
-
winston.debug('req.query.fulltext', req.query.full_text);
|
936
929
|
query.$text = { "$search": req.query.full_text };
|
937
930
|
}
|
938
931
|
|
939
|
-
var history_search = false;
|
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
|
-
// }
|
932
|
+
var history_search = false;
|
953
933
|
|
934
|
+
// Multiple status management
|
954
935
|
if (req.query.status) {
|
955
|
-
|
956
936
|
if (req.query.status === 'all') {
|
957
937
|
delete query.status;
|
958
938
|
} else {
|
@@ -966,40 +946,27 @@ router.get('/', function (req, res, next) {
|
|
966
946
|
delete query.status;
|
967
947
|
}
|
968
948
|
}
|
969
|
-
|
970
949
|
if (statusArray.length > 0) {
|
971
950
|
query.status = {
|
972
951
|
$in: statusArray
|
973
952
|
}
|
974
953
|
}
|
975
|
-
|
976
954
|
}
|
977
955
|
|
978
956
|
if (req.query.lead) {
|
979
|
-
winston.debug('req.query.lead', req.query.lead);
|
980
957
|
query.lead = req.query.lead;
|
981
958
|
}
|
982
959
|
|
983
960
|
// USERS & BOTS
|
984
961
|
if (req.query.participant) {
|
985
|
-
winston.debug('req.query.participant', req.query.participant);
|
986
962
|
query.participants = req.query.participant;
|
987
963
|
}
|
988
964
|
|
989
|
-
winston.debug('req.query.hasbot', req.query.hasbot);
|
990
965
|
if (req.query.hasbot != undefined) {
|
991
|
-
winston.debug('req.query.hasbot', req.query.hasbot);
|
992
966
|
query.hasBot = req.query.hasbot;
|
993
967
|
}
|
994
968
|
|
995
|
-
// if (req.query.waiting_time_exists) { //non basta aggiungi anche che nn è null
|
996
|
-
// query.waiting_time = {"$exists": req.query.waiting_time_exists} //{$ne:null}
|
997
|
-
// winston.debug('REQUEST ROUTE - QUERY waiting_time_exists', query.waiting_time_exists);
|
998
|
-
// }
|
999
|
-
|
1000
|
-
|
1001
969
|
if (req.query.tags) {
|
1002
|
-
winston.debug('req.query.tags', req.query.tags);
|
1003
970
|
query["tags.tag"] = req.query.tags;
|
1004
971
|
}
|
1005
972
|
|
@@ -1031,9 +998,7 @@ router.get('/', function (req, res, next) {
|
|
1031
998
|
//fixato. secondo me qui manca un parentesi tonda per gli or
|
1032
999
|
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))) {
|
1033
1000
|
|
1034
|
-
|
1035
1001
|
var startdate = moment().subtract(14, "days").format("YYYY-MM-DD");
|
1036
|
-
|
1037
1002
|
var enddate = moment().format("YYYY-MM-DD");
|
1038
1003
|
|
1039
1004
|
winston.debug('»»» REQUEST ROUTE - startdate ', startdate);
|
@@ -1042,11 +1007,8 @@ router.get('/', function (req, res, next) {
|
|
1042
1007
|
var enddatePlusOneDay = moment(new Date()).add(1, 'days').toDate()
|
1043
1008
|
winston.debug('»»» REQUEST ROUTE - enddate + 1 days: ', enddatePlusOneDay);
|
1044
1009
|
|
1045
|
-
// var enddatePlusOneDay = "2019-09-17T00:00:00.000Z"
|
1046
|
-
|
1047
1010
|
query.createdAt = { $gte: new Date(Date.parse(startdate)).toISOString(), $lte: new Date(enddatePlusOneDay).toISOString() }
|
1048
1011
|
winston.debug('REQUEST ROUTE - QUERY CREATED AT ', query.createdAt);
|
1049
|
-
|
1050
1012
|
}
|
1051
1013
|
|
1052
1014
|
/**
|
@@ -1077,9 +1039,6 @@ router.get('/', function (req, res, next) {
|
|
1077
1039
|
var newdate = new Date(date);
|
1078
1040
|
var endDate_plusOneDay = newdate.setDate(newdate.getDate() + 1);
|
1079
1041
|
winston.debug('REQUEST ROUTE - REQ QUERY FORMATTED END DATE + 1 DAY ', endDate_plusOneDay);
|
1080
|
-
// var endDate_plusOneDay = moment('2018-09-03').add(1, 'd')
|
1081
|
-
// var endDate_plusOneDay = endDate.add(1).day();
|
1082
|
-
// var toDate = new Date(Date.parse(endDate_plusOneDay)).toISOString()
|
1083
1042
|
|
1084
1043
|
query.createdAt = { $gte: new Date(Date.parse(startDate)).toISOString(), $lte: new Date(endDate_plusOneDay).toISOString() }
|
1085
1044
|
winston.debug('REQUEST ROUTE - QUERY CREATED AT ', query.createdAt);
|
@@ -1097,44 +1056,34 @@ router.get('/', function (req, res, next) {
|
|
1097
1056
|
|
1098
1057
|
winston.debug('REQUEST ROUTE - QUERY CREATED AT (only for start date)', query.createdAt);
|
1099
1058
|
}
|
1100
|
-
// }
|
1101
|
-
|
1102
|
-
|
1103
1059
|
|
1104
1060
|
if (req.query.snap_department_routing) {
|
1105
1061
|
query["snapshot.department.routing"] = req.query.snap_department_routing;
|
1106
|
-
winston.debug('REQUEST ROUTE - QUERY snap_department_routing', query.snap_department_routing);
|
1107
1062
|
}
|
1108
1063
|
|
1109
1064
|
if (req.query.snap_department_default) {
|
1110
1065
|
query["snapshot.department.default"] = req.query.snap_department_default;
|
1111
|
-
winston.debug('REQUEST ROUTE - QUERY snap_department_default', query.snap_department_default);
|
1112
1066
|
}
|
1113
1067
|
|
1114
1068
|
|
1115
1069
|
if (req.query.snap_department_id_bot) {
|
1116
1070
|
query["snapshot.department.id_bot"] = req.query.snap_department_id_bot;
|
1117
|
-
winston.debug('REQUEST ROUTE - QUERY snap_department_id_bot', query.snap_department_id_bot);
|
1118
1071
|
}
|
1119
1072
|
|
1120
1073
|
if (req.query.snap_department_id_bot_exists) {
|
1121
1074
|
query["snapshot.department.id_bot"] = { "$exists": req.query.snap_department_id_bot_exists }
|
1122
|
-
winston.debug('REQUEST ROUTE - QUERY snap_department_id_bot_exists', query.snap_department_id_bot_exists);
|
1123
1075
|
}
|
1124
1076
|
|
1125
1077
|
if (req.query.snap_lead_lead_id) {
|
1126
1078
|
query["snapshot.lead.lead_id"] = req.query.snap_lead_lead_id;
|
1127
|
-
winston.debug('REQUEST ROUTE - QUERY snap_lead_lead_id', query.snap_lead_lead_id);
|
1128
1079
|
}
|
1129
1080
|
|
1130
1081
|
if (req.query.snap_lead_email) {
|
1131
1082
|
query["snapshot.lead.email"] = req.query.snap_lead_email;
|
1132
|
-
winston.debug('REQUEST ROUTE - QUERY snap_lead_email', query.snap_lead_email);
|
1133
1083
|
}
|
1134
1084
|
|
1135
1085
|
if (req.query.smartAssignment) {
|
1136
1086
|
query.smartAssignment = req.query.smartAssignment;
|
1137
|
-
winston.debug('REQUEST ROUTE - QUERY smartAssignment', query.smartAssignment);
|
1138
1087
|
}
|
1139
1088
|
|
1140
1089
|
if (req.query.channel) {
|
@@ -1145,8 +1094,6 @@ router.get('/', function (req, res, next) {
|
|
1145
1094
|
} else {
|
1146
1095
|
query["channel.name"] = req.query.channel
|
1147
1096
|
}
|
1148
|
-
|
1149
|
-
winston.debug('REQUEST ROUTE - QUERY channel', query.channel);
|
1150
1097
|
}
|
1151
1098
|
|
1152
1099
|
if (req.query.priority) {
|
@@ -1158,46 +1105,61 @@ router.get('/', function (req, res, next) {
|
|
1158
1105
|
if (req.query.direction) {
|
1159
1106
|
direction = req.query.direction;
|
1160
1107
|
}
|
1161
|
-
winston.debug("direction", direction);
|
1162
1108
|
|
1163
1109
|
var sortField = "createdAt";
|
1164
1110
|
if (req.query.sort) {
|
1165
1111
|
sortField = req.query.sort;
|
1166
1112
|
}
|
1167
|
-
winston.debug("sortField", sortField);
|
1168
1113
|
|
1169
1114
|
var sortQuery = {};
|
1170
1115
|
sortQuery[sortField] = direction;
|
1171
|
-
|
1116
|
+
|
1117
|
+
// VOICE FILTERS - Start
|
1118
|
+
if (req.query.caller) {
|
1119
|
+
query["attributes.caller_phone"] = req.query.caller;
|
1120
|
+
}
|
1121
|
+
if (req.query.called) {
|
1122
|
+
query["attributes.called_phone"] = req.query.called;
|
1123
|
+
}
|
1124
|
+
if (req.query.call_id) {
|
1125
|
+
query["attributes.call_id"] = req.query.call_id;
|
1126
|
+
}
|
1127
|
+
// VOICE FILTERS - End
|
1128
|
+
|
1129
|
+
if (req.query.duration && req.query.duration_op) {
|
1130
|
+
let duration = Number(req.query.duration) * 60 * 1000;
|
1131
|
+
if (req.query.duration_op === 'gt') {
|
1132
|
+
query.duration = { $gte: duration }
|
1133
|
+
} else if (req.query.duration_op === 'lt') {
|
1134
|
+
query.duration = { $lte: duration }
|
1135
|
+
} else {
|
1136
|
+
winston.verbose("Duration operator can be 'gt' or 'lt'. Skip duration_op " + req.query.duration_op)
|
1137
|
+
}
|
1138
|
+
}
|
1139
|
+
|
1140
|
+
if (req.query.abandonded && (req.query.abandoned === true || req.query.abandoned === 'true')) {
|
1141
|
+
query["attributes.fully_abandoned"] = true
|
1142
|
+
}
|
1172
1143
|
|
1173
1144
|
if (req.query.draft && (req.query.draft === 'false' || req.query.draft === false)) {
|
1174
1145
|
query.draft = { $in: [false, null] }
|
1175
1146
|
}
|
1176
1147
|
|
1177
|
-
winston.debug('REQUEST ROUTE - REQUEST FIND ', query);
|
1178
|
-
|
1179
1148
|
var projection = undefined;
|
1180
1149
|
|
1181
1150
|
if (req.query.full_text) {
|
1182
|
-
|
1183
1151
|
if (req.query.no_textscore != "true" && req.query.no_textscore != true) {
|
1184
|
-
winston.
|
1152
|
+
winston.verbose('fulltext projection on');
|
1185
1153
|
projection = { score: { $meta: "textScore" } };
|
1186
1154
|
}
|
1187
|
-
|
1188
1155
|
}
|
1189
|
-
|
1156
|
+
|
1157
|
+
winston.verbose('REQUEST ROUTE - REQUEST FIND QUERY ', query);
|
1158
|
+
|
1190
1159
|
var q1 = Request.find(query, projection).
|
1191
1160
|
skip(skip).limit(limit);
|
1192
1161
|
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
winston.debug('REQUEST ROUTE no_populate:' + req.query.no_populate);
|
1198
|
-
|
1199
1162
|
if (req.query.no_populate != "true" && req.query.no_populate != true) {
|
1200
|
-
winston.verbose('REQUEST ROUTE - no_polutate false ', req.headers);
|
1201
1163
|
q1.populate('department').
|
1202
1164
|
populate('participatingBots'). //nico già nn gli usa
|
1203
1165
|
populate('participatingAgents'). //nico già nn gli usa
|
@@ -1205,17 +1167,7 @@ router.get('/', function (req, res, next) {
|
|
1205
1167
|
populate({ path: 'requester', populate: { path: 'id_user' } }); //toglilo perche nico lo prende già da snapshot
|
1206
1168
|
}
|
1207
1169
|
|
1208
|
-
// cache(cacheUtil.defaultTTL, "requests-"+projectId).
|
1209
|
-
|
1210
|
-
|
1211
|
-
// if (req.query.select_snapshot) {
|
1212
|
-
// winston.info('select_snapshot');
|
1213
|
-
// q1.select("+snapshot");
|
1214
|
-
// // q1.select({ "snapshot": 1});
|
1215
|
-
// }
|
1216
|
-
|
1217
1170
|
if (req.query.full_text) {
|
1218
|
-
winston.debug('fulltext sort');
|
1219
1171
|
if (req.query.no_textscore != "true" && req.query.no_textscore != true) {
|
1220
1172
|
q1.sort({ score: { $meta: "textScore" } }) //https://docs.mongodb.com/manual/reference/operator/query/text/#sort-by-text-search-score
|
1221
1173
|
}
|
@@ -1223,10 +1175,6 @@ router.get('/', function (req, res, next) {
|
|
1223
1175
|
q1.sort(sortQuery);
|
1224
1176
|
}
|
1225
1177
|
|
1226
|
-
|
1227
|
-
// winston.info('q1',q1);
|
1228
|
-
|
1229
|
-
|
1230
1178
|
q1.exec();
|
1231
1179
|
|
1232
1180
|
// TODO if ?onlycount=true do not perform find query but only
|
@@ -1239,10 +1187,7 @@ router.get('/', function (req, res, next) {
|
|
1239
1187
|
q2 = 0;
|
1240
1188
|
}
|
1241
1189
|
|
1242
|
-
var promises = [
|
1243
|
-
q1,
|
1244
|
-
q2
|
1245
|
-
];
|
1190
|
+
var promises = [ q1, q2 ];
|
1246
1191
|
|
1247
1192
|
Promise.all(promises).then(function (results) {
|
1248
1193
|
var objectToReturn = {
|
@@ -1669,11 +1614,6 @@ router.get('/csv', function (req, res, next) {
|
|
1669
1614
|
query.$text = { "$search": req.query.full_text };
|
1670
1615
|
}
|
1671
1616
|
|
1672
|
-
// if (req.query.status) {
|
1673
|
-
// winston.debug('req.query.status', req.query.status);
|
1674
|
-
// query.status = req.query.status;
|
1675
|
-
// }
|
1676
|
-
|
1677
1617
|
if (req.query.status) {
|
1678
1618
|
|
1679
1619
|
if (req.query.status === 'all') {
|
@@ -1781,6 +1721,27 @@ router.get('/csv', function (req, res, next) {
|
|
1781
1721
|
|
1782
1722
|
winston.debug("sort query", sortQuery);
|
1783
1723
|
|
1724
|
+
if (req.query.channel) {
|
1725
|
+
if (req.query.channel === "offline") {
|
1726
|
+
query["channel.name"] = { "$in": ["email", "form"] }
|
1727
|
+
} else if (req.query.channel === "online") {
|
1728
|
+
query["channel.name"] = { "$nin": ["email", "form"] }
|
1729
|
+
} else {
|
1730
|
+
query["channel.name"] = req.query.channel
|
1731
|
+
}
|
1732
|
+
}
|
1733
|
+
|
1734
|
+
// VOICE FILTERS - Start
|
1735
|
+
if (req.query.caller) {
|
1736
|
+
query["attributes.caller_phone"] = req.query.caller;
|
1737
|
+
}
|
1738
|
+
if (req.query.called) {
|
1739
|
+
query["attributes.called_phone"] = req.query.called;
|
1740
|
+
}
|
1741
|
+
if (req.query.call_id) {
|
1742
|
+
query["attributes.call_id"] = req.query.call_id;
|
1743
|
+
}
|
1744
|
+
// VOICE FILTERS - End
|
1784
1745
|
|
1785
1746
|
// TODO ORDER BY SCORE
|
1786
1747
|
// return Faq.find(query, {score: { $meta: "textScore" } })
|
@@ -1788,6 +1749,21 @@ router.get('/csv', function (req, res, next) {
|
|
1788
1749
|
|
1789
1750
|
// aggiungi filtro per data marco
|
1790
1751
|
|
1752
|
+
if (req.query.duration && req.query.duration_op) {
|
1753
|
+
let duration = Number(req.query.duration) * 60 * 1000;
|
1754
|
+
if (req.query.duration_op === 'gt') {
|
1755
|
+
query.duration = { $gte: duration }
|
1756
|
+
} else if (req.query.duration_op === 'lt') {
|
1757
|
+
query.duration = { $lte: duration }
|
1758
|
+
} else {
|
1759
|
+
winston.verbose("Duration operator can be 'gt' or 'lt'. Skip duration_op " + req.query.duration_op)
|
1760
|
+
}
|
1761
|
+
}
|
1762
|
+
|
1763
|
+
if (req.query.draft && (req.query.draft === 'false' || req.query.draft === false)) {
|
1764
|
+
query.draft = { $in: [false, null] }
|
1765
|
+
}
|
1766
|
+
|
1791
1767
|
winston.debug('REQUEST ROUTE - REQUEST FIND ', query)
|
1792
1768
|
return Request.find(query, '-transcript -status -__v').
|
1793
1769
|
skip(skip).limit(limit).
|
@@ -1865,7 +1841,17 @@ router.get('/csv', function (req, res, next) {
|
|
1865
1841
|
// // da terminare e testare. potrebbe essere troppo lenta la query per tanti record
|
1866
1842
|
// element.participatingAgents = participatingAgents;
|
1867
1843
|
|
1868
|
-
|
1844
|
+
if (element.attributes) {
|
1845
|
+
if (element.attributes.caller_phone) {
|
1846
|
+
element.caller_phone = element.attributes.caller_phone;
|
1847
|
+
}
|
1848
|
+
if (element.attributes.called_phone) {
|
1849
|
+
element.called_phone = element.attributes.called_phone;
|
1850
|
+
}
|
1851
|
+
if (element.attributes.caller_phone) {
|
1852
|
+
element.call_id = element.attributes.call_id;
|
1853
|
+
}
|
1854
|
+
}
|
1869
1855
|
|
1870
1856
|
delete element.lead;
|
1871
1857
|
|
@@ -310,6 +310,20 @@ class RequestService {
|
|
310
310
|
|
311
311
|
winston.verbose("Request " + request.request_id + " contains already the same participants at the same request status. Routed to the same participants");
|
312
312
|
|
313
|
+
if (routedRequest.attributes.fully_abandoned && routedRequest.attributes.fully_abandoned === true) {
|
314
|
+
request.status = RequestConstants.ABANDONED;
|
315
|
+
request.attributes.fully_abandoned = true;
|
316
|
+
request.markModified('status');
|
317
|
+
request.markModified('attributes');
|
318
|
+
request.save((err, savedRequest) => {
|
319
|
+
if (err) {
|
320
|
+
winston.error("Error updating request with status ABANDONED ", err);
|
321
|
+
} else {
|
322
|
+
winston.verbose("Status modified in ABANDONED for request: " + savedRequest._id);
|
323
|
+
}
|
324
|
+
})
|
325
|
+
}
|
326
|
+
|
313
327
|
if (no_populate === "true" || no_populate === true) {
|
314
328
|
winston.debug("no_populate is true");
|
315
329
|
return resolve(request);
|
package/test/projectRoute.js
CHANGED
@@ -50,6 +50,47 @@ describe('ProjectRoute', () => {
|
|
50
50
|
|
51
51
|
describe('/create', () => {
|
52
52
|
|
53
|
+
it('getAllProjectsWithSuperAdminCredential', (done) => {
|
54
|
+
|
55
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
56
|
+
var pwd = "pwd";
|
57
|
+
|
58
|
+
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
|
59
|
+
projectService.create("test-project-create-1", savedUser._id).then(() => {
|
60
|
+
projectService.create("test-project-create-2", savedUser._id).then((savedProject2) => {
|
61
|
+
|
62
|
+
chai.request(server)
|
63
|
+
.post('/auth/signin')
|
64
|
+
.send({ email: "admin@tiledesk.com", password: "adminadmin" })
|
65
|
+
// .send({ email: email, password: pwd }) // con queste credenziali non si può fare la richiesta /projects/all
|
66
|
+
.end((err, res) => {
|
67
|
+
|
68
|
+
if (log) { console.log("login with superadmin res.body: ", res.body) };
|
69
|
+
res.should.have.status(200);
|
70
|
+
res.body.should.be.a('object');
|
71
|
+
expect(res.body.success).to.equal(true);
|
72
|
+
expect(res.body.token).not.equal(null);
|
73
|
+
|
74
|
+
let superadmin_token = res.body.token;
|
75
|
+
|
76
|
+
chai.request(server)
|
77
|
+
.get('/projects/all')
|
78
|
+
.set('Authorization', superadmin_token)
|
79
|
+
.end((err, res) => {
|
80
|
+
|
81
|
+
console.log("res.body: ", res.body.length);
|
82
|
+
console.log("example: ", res.body[0]);
|
83
|
+
res.should.have.status(200);
|
84
|
+
res.body.should.be.a('array');
|
85
|
+
|
86
|
+
done()
|
87
|
+
})
|
88
|
+
})
|
89
|
+
})
|
90
|
+
})
|
91
|
+
})
|
92
|
+
}).timeout(10000)
|
93
|
+
|
53
94
|
it('updateProjectProfileWithSuperAdminCredential', (done) => {
|
54
95
|
|
55
96
|
var email = "test-signup-" + Date.now() + "@email.com";
|
@@ -310,7 +310,7 @@ class WebSocketServer {
|
|
310
310
|
|
311
311
|
// db.getCollection('requests').find({"id_project":"5e15bef09877c800176d217f","status":{"$lt":1000},"$or":[{"agents":{"id_user":"5ddd30bff0195f0017f72c6d"}},{"participants":"5ddd30bff0195f0017f72c6d"}]})
|
312
312
|
// pubblica dopo toni
|
313
|
-
var query = { "id_project": projectId, "status": { $lt: 1000, $gt: 50 }, preflight: false, "draft": { $in: [false, null] } };
|
313
|
+
var query = { "id_project": projectId, "status": { $lt: 1000, $gt: 50, $ne: 150 }, preflight: false, "draft": { $in: [false, null] } };
|
314
314
|
// add hasBot:false
|
315
315
|
|
316
316
|
// var query = {"id_project":projectId, "status": { $lt: 1000, $gt: 50 }, $or:[ {preflight:false}, { preflight : { $exists: false } } ] };
|