shuttlepro-shared 1.4.19 → 1.4.20
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,35 @@ 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
|
+
const fromDate = new Date(from);
|
|
285
|
+
const toDate = new Date(to);
|
|
286
|
+
toDate.setHours(23, 59, 59, 999);
|
|
287
|
+
|
|
288
|
+
const matchStage = {
|
|
289
|
+
createdAt: { $gte: fromDate, $lte: toDate },
|
|
290
|
+
...filters,
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
console.log(matchStage, "matchStage query");
|
|
294
|
+
|
|
286
295
|
const result = await Call.aggregate([
|
|
287
|
-
{
|
|
288
|
-
$match: {
|
|
289
|
-
createdAt: { $gte: from, $lte: to },
|
|
290
|
-
...filters,
|
|
291
|
-
},
|
|
292
|
-
},
|
|
296
|
+
{ $match: matchStage },
|
|
293
297
|
{
|
|
294
298
|
$group: {
|
|
295
|
-
_id: "$agentId",
|
|
299
|
+
_id: filters.agentId ? "$agentId" : null,
|
|
296
300
|
totalCalls: { $sum: 1 },
|
|
297
|
-
pending: {
|
|
298
|
-
$sum: { $cond: [{ $eq: ["$status", "pending"] }, 1, 0] },
|
|
299
|
-
},
|
|
301
|
+
pending: { $sum: { $cond: [{ $eq: ["$status", "pending"] }, 1, 0] } },
|
|
300
302
|
abandoned: {
|
|
301
303
|
$sum: { $cond: [{ $eq: ["$status", "abandoned"] }, 1, 0] },
|
|
302
304
|
},
|
|
303
|
-
ended: {
|
|
304
|
-
$sum: { $cond: [{ $eq: ["$status", "ended"] }, 1, 0] },
|
|
305
|
-
},
|
|
305
|
+
ended: { $sum: { $cond: [{ $eq: ["$status", "ended"] }, 1, 0] } },
|
|
306
306
|
},
|
|
307
307
|
},
|
|
308
308
|
{
|
|
309
309
|
$project: {
|
|
310
310
|
_id: 0,
|
|
311
|
-
agentId: "$_id",
|
|
312
311
|
totalCalls: 1,
|
|
313
312
|
pending: 1,
|
|
314
313
|
abandoned: 1,
|
|
@@ -317,26 +316,11 @@ class CallRepository {
|
|
|
317
316
|
},
|
|
318
317
|
]);
|
|
319
318
|
|
|
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
319
|
if (result.length === 0) {
|
|
336
|
-
return
|
|
320
|
+
return { totalCalls: 0, pending: 0, abandoned: 0, ended: 0 };
|
|
337
321
|
}
|
|
338
322
|
|
|
339
|
-
return result;
|
|
323
|
+
return result[0];
|
|
340
324
|
}
|
|
341
325
|
|
|
342
326
|
// Daily call summary
|