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