@tiledesk/tiledesk-server 2.2.28 → 2.2.29

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 CHANGED
@@ -1,5 +1,10 @@
1
- # untagged
2
- - Operator.select returns context object that contains the temp request..TEST IT
1
+
2
+ # 2.2.29
3
+ - Added endpoint to find requests created by users and guests
4
+ - Log fix
5
+
6
+ # 2.2.28 (compatible with dasboard ver. 2.2.36)
7
+ - Operator.select returns context object that contains the temp request
3
8
  - Added Serbian language to the widget
4
9
  - Added tag field to the project_user
5
10
  - Removed default BCC from email
@@ -7,15 +12,22 @@
7
12
  - Faq template now support blank and example
8
13
  - Organizzation support added
9
14
  - ipFilter related to the project is now supported
15
+ - Added filter channel name for the request
16
+ - Added edit card for payment
17
+ - Fix concierge concierge bot for department selection
18
+ - Added filter to find a request by ticket_id
19
+ - Added filter to snap_lead_lead_id for request
20
+ - Added endpoint to close a request by guest
21
+
10
22
 
11
- # 2.2.26
23
+ # 2.2.26 -> PROD (compatible with dasboard ver. 2.2.35)
12
24
  - Tag fix for 2.2.25
13
25
 
14
26
  # 2.2.25
15
27
  - New label prechat form
16
28
  - Updated mongodb-runner from 4.8.1 to 4.8.3 to fix ssh key error
17
29
 
18
- # 2.2.24 -> PROD
30
+ # 2.2.24
19
31
  - webhook subscription can fetch temmates endpoint
20
32
  - Added hasBot and createdAt index to the request model
21
33
 
package/app.js CHANGED
@@ -352,10 +352,10 @@ var projectIpFilter = function (req, res, next) {
352
352
  }
353
353
 
354
354
  var projectIpFilterEnabled = req.project.ipFilterEnabled;
355
- winston.info("project projectIpFilterEnabled: " +projectIpFilterEnabled)
355
+ winston.debug("project projectIpFilterEnabled: " +projectIpFilterEnabled)
356
356
 
357
357
  var projectIpFilter = req.project.ipFilter
358
- winston.info("project ipFilter: " + projectIpFilter)
358
+ winston.debug("project ipFilter: " + projectIpFilter)
359
359
 
360
360
  if (projectIpFilterEnabled === true && projectIpFilter && projectIpFilter.length > 0) {
361
361
  var ip = ipfilter(projectIpFilter, { detectIp: customDetection, mode: 'allow' })
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.2.28",
4
+ "version": "2.2.29",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -5,6 +5,7 @@ var winston = require('../config/winston');
5
5
  const requestEvent = require('../event/requestEvent');
6
6
  const { check, validationResult } = require('express-validator');
7
7
  var requestService = require('../services/requestService');
8
+ var mongoose = require('mongoose');
8
9
 
9
10
 
10
11
  router.patch('/:requestid/rating', function (req, res) {
@@ -70,4 +71,314 @@ router.put('/:requestid/closeg', function (req, res) {
70
71
 
71
72
  });
72
73
 
74
+
75
+
76
+
77
+ router.get('/me', function (req, res, next) {
78
+
79
+ winston.debug("req projectid", req.projectid);
80
+ winston.debug("req.query.sort", req.query.sort);
81
+ winston.debug('REQUEST ROUTE - QUERY ', req.query)
82
+
83
+ const DEFAULT_LIMIT = 40;
84
+
85
+ var limit = DEFAULT_LIMIT; // Number of request per page
86
+
87
+ if (req.query.limit) {
88
+ limit = parseInt(req.query.limit);
89
+ }
90
+ if (limit > 100) {
91
+ limit = DEFAULT_LIMIT;
92
+ }
93
+
94
+
95
+ var page = 0;
96
+
97
+ if (req.query.page) {
98
+ page = req.query.page;
99
+ }
100
+
101
+ var skip = page * limit;
102
+ winston.debug('REQUEST ROUTE - SKIP PAGE ', skip);
103
+
104
+
105
+ var user_id = req.user._id;
106
+ winston.debug('REQUEST ROUTE - user_id: '+user_id);
107
+
108
+ var isObjectId = mongoose.Types.ObjectId.isValid(user_id);
109
+ winston.debug("isObjectId:"+ isObjectId);
110
+
111
+
112
+ var query = { "id_project": req.projectid, "status": {$lt:1000}, preflight:false};
113
+
114
+
115
+ if (isObjectId) {
116
+ query["snapshot.requester.id_user"] = user_id;
117
+ // query.id_user = mongoose.Types.ObjectId(contact_id);
118
+ } else {
119
+ query["snapshot.requester.uuid_user"] = user_id;
120
+ }
121
+
122
+
123
+ // $or:[{"snapshot.requester.id_user": user_id}, {"snapshot.requester.uuid_user": user_id}]};
124
+
125
+ winston.debug('REQUEST ROUTE - query ', query);
126
+
127
+
128
+ if (req.query.dept_id) {
129
+ query.department = req.query.dept_id;
130
+ winston.debug('REQUEST ROUTE - QUERY DEPT ID', query.department);
131
+ }
132
+
133
+ if (req.query.full_text) {
134
+ winston.debug('req.query.fulltext', req.query.full_text);
135
+ query.$text = { "$search": req.query.full_text };
136
+ }
137
+
138
+ var history_search = false;
139
+
140
+ if (req.query.status) {
141
+ winston.debug('req.query.status', req.query.status);
142
+ query.status = req.query.status;
143
+
144
+ if (req.query.status == 1000 || req.query.status == "1000") {
145
+ history_search = true;
146
+ }
147
+ if (req.query.status==="all") {
148
+ history_search = true;
149
+ delete query.status;
150
+ }
151
+ }
152
+
153
+ // if (req.query.lead) {
154
+ // winston.debug('req.query.lead', req.query.lead);
155
+ // query.lead = req.query.lead;
156
+ // }
157
+
158
+ // USERS & BOTS
159
+ if (req.query.participant) {
160
+ winston.debug('req.query.participant', req.query.participant);
161
+ query.participants = req.query.participant;
162
+ }
163
+
164
+ winston.debug('req.query.hasbot', req.query.hasbot);
165
+ if (req.query.hasbot!=undefined) {
166
+ winston.debug('req.query.hasbot', req.query.hasbot);
167
+ query.hasBot = req.query.hasbot;
168
+ }
169
+
170
+ // if (req.query.waiting_time_exists) { //non basta aggiungi anche che nn è null
171
+ // query.waiting_time = {"$exists": req.query.waiting_time_exists} //{$ne:null}
172
+ // winston.debug('REQUEST ROUTE - QUERY waiting_time_exists', query.waiting_time_exists);
173
+ // }
174
+
175
+
176
+ if (req.query.tags) {
177
+ winston.debug('req.query.tags', req.query.tags);
178
+ query["tags.tag"] = req.query.tags;
179
+ }
180
+
181
+ if (req.query.location) {
182
+ query.location = req.query.location;
183
+ }
184
+
185
+ if (req.query.ticket_id) {
186
+ query.ticket_id = req.query.ticket_id;
187
+ }
188
+
189
+ // if (req.query.request_id) {
190
+ // console.log('req.query.request_id', req.query.request_id);
191
+ // query.request_id = req.query.request_id;
192
+ // }
193
+
194
+ /**
195
+ **! *** DATE RANGE USECASE 1 ***
196
+ * in the tiledesk dashboard's HISTORY PAGE
197
+ * WHEN THE TRIAL IS EXIPIRED OR THE SUBSCIPTION IS NOT ACTIVE
198
+ * THE SEARCH FOR DATE INTERVAL OF THE HISTORY OF REQUESTS ARE DISABLED AND
199
+ * ARE DISPLAYED ONLY THE REQUESTS OF THE LAST 14 DAYS
200
+ */
201
+ 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)) {
202
+
203
+
204
+ var startdate = moment().subtract(14, "days").format("YYYY-MM-DD");
205
+
206
+ var enddate = moment().format("YYYY-MM-DD");
207
+
208
+ winston.debug('»»» REQUEST ROUTE - startdate ', startdate);
209
+ winston.debug('»»» REQUEST ROUTE - enddate ', enddate);
210
+
211
+ var enddatePlusOneDay= moment(new Date()).add(1, 'days').toDate()
212
+ winston.debug('»»» REQUEST ROUTE - enddate + 1 days: ', enddatePlusOneDay);
213
+
214
+ // var enddatePlusOneDay = "2019-09-17T00:00:00.000Z"
215
+
216
+ query.createdAt = { $gte: new Date(Date.parse(startdate)).toISOString(), $lte: new Date(enddatePlusOneDay).toISOString() }
217
+ winston.debug('REQUEST ROUTE - QUERY CREATED AT ', query.createdAt);
218
+
219
+ }
220
+
221
+ /**
222
+ **! *** DATE RANGE USECASE 2 ***
223
+ * in the tiledesk dashboard's HISTORY PAGE
224
+ * WHEN THE USER SEARCH FOR DATE INTERVAL OF THE HISTORY OF REQUESTS
225
+ */
226
+ if (req.query.start_date && req.query.end_date) {
227
+ winston.debug('REQUEST ROUTE - REQ QUERY start_date ', req.query.start_date);
228
+ winston.debug('REQUEST ROUTE - REQ QUERY end_date ', req.query.end_date);
229
+
230
+ /**
231
+ * USING TIMESTAMP in MS */
232
+ // var formattedStartDate = new Date(+req.query.start_date);
233
+ // var formattedEndDate = new Date(+req.query.end_date);
234
+ // query.createdAt = { $gte: formattedStartDate, $lte: formattedEndDate }
235
+
236
+ /**
237
+ * USING MOMENT */
238
+ var startDate = moment(req.query.start_date, 'DD/MM/YYYY').format('YYYY-MM-DD');
239
+ var endDate = moment(req.query.end_date, 'DD/MM/YYYY').format('YYYY-MM-DD');
240
+
241
+ winston.debug('REQUEST ROUTE - REQ QUERY FORMATTED START DATE ', startDate);
242
+ winston.debug('REQUEST ROUTE - REQ QUERY FORMATTED END DATE ', endDate);
243
+
244
+ // ADD ONE DAY TO THE END DAY
245
+ var date = new Date(endDate);
246
+ var newdate = new Date(date);
247
+ var endDate_plusOneDay = newdate.setDate(newdate.getDate() + 1);
248
+ winston.debug('REQUEST ROUTE - REQ QUERY FORMATTED END DATE + 1 DAY ', endDate_plusOneDay);
249
+ // var endDate_plusOneDay = moment('2018-09-03').add(1, 'd')
250
+ // var endDate_plusOneDay = endDate.add(1).day();
251
+ // var toDate = new Date(Date.parse(endDate_plusOneDay)).toISOString()
252
+
253
+ query.createdAt = { $gte: new Date(Date.parse(startDate)).toISOString(), $lte: new Date(endDate_plusOneDay).toISOString() }
254
+ winston.debug('REQUEST ROUTE - QUERY CREATED AT ', query.createdAt);
255
+
256
+ } else if (req.query.start_date && !req.query.end_date) {
257
+ winston.debug('REQUEST ROUTE - REQ QUERY END DATE IS EMPTY (so search only for start date)');
258
+ var startDate = moment(req.query.start_date, 'DD/MM/YYYY').format('YYYY-MM-DD');
259
+
260
+ var range = { $gte: new Date(Date.parse(startDate)).toISOString() };
261
+ if (req.query.filterRangeField) {
262
+ query[req.query.filterRangeField] = range;
263
+ }else {
264
+ query.createdAt = range;
265
+ }
266
+
267
+ winston.debug('REQUEST ROUTE - QUERY CREATED AT (only for start date)', query.createdAt);
268
+ }
269
+ // }
270
+
271
+
272
+
273
+ if (req.query.snap_department_routing) {
274
+ query["snapshot.department.routing"] = req.query.snap_department_routing;
275
+ winston.debug('REQUEST ROUTE - QUERY snap_department_routing', query.snap_department_routing);
276
+ }
277
+
278
+ if (req.query.snap_department_default) {
279
+ query["snapshot.department.default"] = req.query.snap_department_default;
280
+ winston.debug('REQUEST ROUTE - QUERY snap_department_default', query.snap_department_default);
281
+ }
282
+
283
+
284
+ if (req.query.snap_department_id_bot) {
285
+ query["snapshot.department.id_bot"] = req.query.snap_department_id_bot;
286
+ winston.debug('REQUEST ROUTE - QUERY snap_department_id_bot', query.snap_department_id_bot);
287
+ }
288
+
289
+ if (req.query.snap_department_id_bot_exists) {
290
+ query["snapshot.department.id_bot"] = {"$exists": req.query.snap_department_id_bot_exists}
291
+ winston.debug('REQUEST ROUTE - QUERY snap_department_id_bot_exists', query.snap_department_id_bot_exists);
292
+ }
293
+
294
+ // if (req.query.snap_lead_lead_id) {
295
+ // query["snapshot.lead.lead_id"] = req.query.snap_lead_lead_id;
296
+ // winston.debug('REQUEST ROUTE - QUERY snap_lead_lead_id', query.snap_lead_lead_id);
297
+ // }
298
+
299
+ if (req.query.channel) {
300
+ query["channel.name"] = req.query.channel
301
+ winston.debug('REQUEST ROUTE - QUERY channel', query.channel);
302
+ }
303
+
304
+
305
+ var direction = -1; //-1 descending , 1 ascending
306
+ if (req.query.direction) {
307
+ direction = req.query.direction;
308
+ }
309
+ winston.debug("direction", direction);
310
+
311
+ var sortField = "createdAt";
312
+ if (req.query.sort) {
313
+ sortField = req.query.sort;
314
+ }
315
+ winston.debug("sortField", sortField);
316
+
317
+ var sortQuery = {};
318
+ sortQuery[sortField] = direction;
319
+
320
+ winston.debug("sort query", sortQuery);
321
+
322
+ winston.verbose('REQUEST ROUTE - REQUEST FIND ', query);
323
+
324
+ // requestcachefarequi populaterequired
325
+ var q1 = Request.find(query).
326
+ skip(skip).limit(limit);
327
+
328
+
329
+ winston.debug('REQUEST ROUTE no_populate:' + req.query.no_populate);
330
+
331
+ if (req.query.no_populate != "true" && req.query.no_populate != true) {
332
+ winston.verbose('REQUEST ROUTE - no_polutate false ', req.headers);
333
+ q1.populate('department').
334
+ populate('participatingBots'). //nico già nn gli usa
335
+ populate('participatingAgents'). //nico già nn gli usa
336
+ populate('lead').
337
+ populate({path:'requester',populate:{path:'id_user'}}); //toglilo perche nico lo prende già da snapshot
338
+ }
339
+
340
+ // cache(cacheUtil.defaultTTL, "requests-"+projectId).
341
+
342
+
343
+ // if (req.query.select_snapshot) {
344
+ // winston.info('select_snapshot');
345
+ // q1.select("+snapshot");
346
+ // // q1.select({ "snapshot": 1});
347
+ // }
348
+
349
+ q1.sort(sortQuery);
350
+
351
+ // winston.info('q1',q1);
352
+
353
+
354
+ q1.exec();
355
+
356
+ // TODO if ?onlycount=true do not perform find query but only
357
+ // set q1 to undefined; to skip query
358
+
359
+ var q2 = Request.countDocuments(query).exec();
360
+
361
+ var promises = [
362
+ q1,
363
+ q2
364
+ ];
365
+
366
+ Promise.all(promises).then(function(results) {
367
+ var objectToReturn = {
368
+ perPage: limit,
369
+ count: results[1],
370
+ requests: results[0]
371
+ };
372
+ winston.debug('REQUEST ROUTE - objectToReturn ', objectToReturn);
373
+ return res.json(objectToReturn);
374
+
375
+ }).catch(function(err){
376
+ winston.error('REQUEST ROUTE - REQUEST FIND ERR ', err);
377
+ return res.status(500).send({ success: false, msg: 'Error getting requests.', err: err });
378
+ });
379
+
380
+
381
+ });
382
+
383
+
73
384
  module.exports = router;