shuttlepro-shared 1.4.19 → 1.4.21
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.
|
@@ -279,36 +279,41 @@ class CallRepository {
|
|
|
279
279
|
|
|
280
280
|
/* ----------------- Reporting & Analytics ----------------- */
|
|
281
281
|
|
|
282
|
-
// Stats grouped by agent
|
|
283
282
|
// Stats grouped by agent
|
|
284
283
|
async getAgentStats({ from, to }, filters = {}) {
|
|
285
|
-
|
|
284
|
+
// Pakistan offset (+5 hours)
|
|
285
|
+
const PAK_OFFSET = 5 * 60 * 60 * 1000;
|
|
286
|
+
|
|
287
|
+
// convert input to Date objects
|
|
288
|
+
const fromDate = new Date(new Date(from).getTime() - PAK_OFFSET);
|
|
289
|
+
const toDate = new Date(new Date(to).getTime() - PAK_OFFSET);
|
|
290
|
+
|
|
291
|
+
// set end of day in Pakistan time
|
|
292
|
+
toDate.setHours(23, 59, 59, 999);
|
|
293
|
+
|
|
294
|
+
console.log({ fromDate, toDate }, filters);
|
|
295
|
+
|
|
296
|
+
const matchStage = {
|
|
297
|
+
createdAt: { $gte: fromDate, $lte: toDate },
|
|
298
|
+
...filters,
|
|
299
|
+
};
|
|
300
|
+
|
|
286
301
|
const result = await Call.aggregate([
|
|
287
|
-
{
|
|
288
|
-
$match: {
|
|
289
|
-
createdAt: { $gte: from, $lte: to },
|
|
290
|
-
...filters,
|
|
291
|
-
},
|
|
292
|
-
},
|
|
302
|
+
{ $match: matchStage },
|
|
293
303
|
{
|
|
294
304
|
$group: {
|
|
295
|
-
_id: "$agentId",
|
|
305
|
+
_id: filters.agentId ? "$agentId" : null,
|
|
296
306
|
totalCalls: { $sum: 1 },
|
|
297
|
-
pending: {
|
|
298
|
-
$sum: { $cond: [{ $eq: ["$status", "pending"] }, 1, 0] },
|
|
299
|
-
},
|
|
307
|
+
pending: { $sum: { $cond: [{ $eq: ["$status", "pending"] }, 1, 0] } },
|
|
300
308
|
abandoned: {
|
|
301
309
|
$sum: { $cond: [{ $eq: ["$status", "abandoned"] }, 1, 0] },
|
|
302
310
|
},
|
|
303
|
-
ended: {
|
|
304
|
-
$sum: { $cond: [{ $eq: ["$status", "ended"] }, 1, 0] },
|
|
305
|
-
},
|
|
311
|
+
ended: { $sum: { $cond: [{ $eq: ["$status", "ended"] }, 1, 0] } },
|
|
306
312
|
},
|
|
307
313
|
},
|
|
308
314
|
{
|
|
309
315
|
$project: {
|
|
310
316
|
_id: 0,
|
|
311
|
-
agentId: "$_id",
|
|
312
317
|
totalCalls: 1,
|
|
313
318
|
pending: 1,
|
|
314
319
|
abandoned: 1,
|
|
@@ -317,26 +322,11 @@ class CallRepository {
|
|
|
317
322
|
},
|
|
318
323
|
]);
|
|
319
324
|
|
|
320
|
-
console.log(result, "result");
|
|
321
|
-
|
|
322
|
-
if (filters.agentId) {
|
|
323
|
-
return (
|
|
324
|
-
result.find((r) => r.agentId === filters.agentId) || {
|
|
325
|
-
agentId: filters.agentId,
|
|
326
|
-
totalCalls: 0,
|
|
327
|
-
pending: 0,
|
|
328
|
-
abandoned: 0,
|
|
329
|
-
ended: 0,
|
|
330
|
-
}
|
|
331
|
-
);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
// multi-agent case
|
|
335
325
|
if (result.length === 0) {
|
|
336
|
-
return
|
|
326
|
+
return { totalCalls: 0, pending: 0, abandoned: 0, ended: 0 };
|
|
337
327
|
}
|
|
338
328
|
|
|
339
|
-
return result;
|
|
329
|
+
return result[0];
|
|
340
330
|
}
|
|
341
331
|
|
|
342
332
|
// Daily call summary
|