tango-app-api-trax 3.3.1-beta-10 → 3.3.1-beta-12
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/package.json +2 -2
- package/src/controllers/mobileTrax.controller.js +90 -25
- package/src/controllers/teaxFlag.controller.js +116 -349
- package/src/controllers/trax.controller.js +1 -103
- package/src/controllers/traxDashboard.controllers.js +184 -180
- package/src/dtos/validation.dtos.js +2 -2
- package/src/hbs/login-otp.hbs +943 -943
- package/src/routes/trax.routes.js +0 -1
- package/src/routes/traxDashboard.routes.js +1 -3
- package/src/routes/traxFlag.router.js +1 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { logger, download } from 'tango-app-api-middleware';
|
|
1
|
+
import { logger, download, getChecklistUsers } from 'tango-app-api-middleware';
|
|
2
2
|
import * as processedchecklistService from '../services/processedchecklist.services.js';
|
|
3
3
|
import * as processedchecklistconfigService from '../services/processedchecklistconfig.services.js';
|
|
4
4
|
import * as checklistconfigService from '../services/checklist.service.js';
|
|
@@ -277,13 +277,20 @@ export const checklistPerformance = async ( req, res ) => {
|
|
|
277
277
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
278
278
|
let result = {};
|
|
279
279
|
|
|
280
|
+
// Get User Based Checklist //
|
|
281
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
282
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
283
|
+
// End: Get User Based Checklist////
|
|
284
|
+
|
|
280
285
|
let findQuery = [];
|
|
281
286
|
let findAndQuery = [];
|
|
282
287
|
findAndQuery.push(
|
|
283
288
|
{ checkListType: { $eq: 'custom' } },
|
|
284
289
|
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
285
290
|
{ client_id: requestData.clientId },
|
|
286
|
-
{ store_id: { $in: requestData.storeId } },
|
|
291
|
+
// { store_id: { $in: requestData.storeId } },
|
|
292
|
+
{ userEmail: { $in: getUserEmails } },
|
|
293
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
287
294
|
);
|
|
288
295
|
|
|
289
296
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -321,6 +328,7 @@ export const checklistPerformance = async ( req, res ) => {
|
|
|
321
328
|
_id: '$sourceCheckList_id',
|
|
322
329
|
sourceCheckList_id: { $last: '$sourceCheckList_id' },
|
|
323
330
|
checkListName: { $last: '$checkListName' },
|
|
331
|
+
coverage: { $last: '$coverage' },
|
|
324
332
|
checkListChar: { $last: { $substr: [ '$checkListName', 0, 2 ] } },
|
|
325
333
|
scheduleRepeatedType: { $last: '$scheduleRepeatedType' },
|
|
326
334
|
// storeCount: { $max: '$storeCount' },
|
|
@@ -372,6 +380,12 @@ export const checklistPerformance = async ( req, res ) => {
|
|
|
372
380
|
_id: 1,
|
|
373
381
|
sourceCheckList_id: 1,
|
|
374
382
|
checkListName: 1,
|
|
383
|
+
coverage: {
|
|
384
|
+
$concat: [
|
|
385
|
+
{ $toUpper: { $substr: [ { $ifNull: [ '$coverage', '' ] }, 0, 1 ] } },
|
|
386
|
+
{ $substr: [ { $ifNull: [ '$coverage', '' ] }, 1, { $strLenCP: { $ifNull: [ '$coverage', '' ] } } ] },
|
|
387
|
+
],
|
|
388
|
+
},
|
|
375
389
|
checkListChar: 1,
|
|
376
390
|
scheduleRepeatedType: {
|
|
377
391
|
$concat: [
|
|
@@ -417,6 +431,7 @@ export const checklistPerformance = async ( req, res ) => {
|
|
|
417
431
|
getChecklistPerformanceData[0].data.forEach( ( element ) => {
|
|
418
432
|
exportdata.push( {
|
|
419
433
|
'Checklist Name': element.checkListName || '--',
|
|
434
|
+
'Coverage': element.coverage || '--',
|
|
420
435
|
'Scheduled': element.scheduleRepeatedType || '--',
|
|
421
436
|
'Assigned To': element.storeCount || '--',
|
|
422
437
|
'Submitted': element.submittedChecklist || '--',
|
|
@@ -448,14 +463,21 @@ export const storePerformance = async ( req, res ) => {
|
|
|
448
463
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
449
464
|
let result = {};
|
|
450
465
|
|
|
466
|
+
// Get User Based Checklist //
|
|
467
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
468
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
469
|
+
// End: Get User Based Checklist////
|
|
470
|
+
|
|
451
471
|
let findQuery = [];
|
|
452
472
|
let findAndQuery = [];
|
|
453
473
|
findAndQuery.push(
|
|
454
474
|
{ client_id: requestData.clientId },
|
|
455
|
-
{ store_id: { $in: requestData.storeId } },
|
|
456
475
|
{ date_iso: { $gte: fromDate } },
|
|
457
476
|
{ date_iso: { $lte: toDate } },
|
|
458
477
|
{ checkListType: { $eq: 'custom' } },
|
|
478
|
+
// { store_id: { $in: requestData.storeId } },
|
|
479
|
+
{ userEmail: { $in: getUserEmails } },
|
|
480
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
459
481
|
);
|
|
460
482
|
|
|
461
483
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -653,13 +675,20 @@ export const userPerformance = async ( req, res ) => {
|
|
|
653
675
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
654
676
|
let result = {};
|
|
655
677
|
|
|
678
|
+
// Get User Based Checklist //
|
|
679
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
680
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
681
|
+
// End: Get User Based Checklist////
|
|
682
|
+
|
|
656
683
|
let findQuery = [];
|
|
657
684
|
let findAndQuery = [];
|
|
658
685
|
findAndQuery.push(
|
|
659
686
|
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
660
687
|
{ checkListType: { $eq: 'custom' } },
|
|
661
688
|
{ client_id: requestData.clientId },
|
|
662
|
-
{ store_id: { $in: requestData.storeId } },
|
|
689
|
+
// { store_id: { $in: requestData.storeId } },
|
|
690
|
+
{ userEmail: { $in: getUserEmails } },
|
|
691
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
663
692
|
);
|
|
664
693
|
|
|
665
694
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -950,13 +979,20 @@ export const storeDropdown = async ( req, res ) => {
|
|
|
950
979
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
951
980
|
let result = {};
|
|
952
981
|
|
|
982
|
+
// Get User Based Checklist //
|
|
983
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
984
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
985
|
+
// End: Get User Based Checklist////
|
|
986
|
+
|
|
953
987
|
let findQuery = [];
|
|
954
988
|
let findAndQuery = [];
|
|
955
989
|
findAndQuery.push(
|
|
956
990
|
{ client_id: requestData.clientId },
|
|
957
|
-
{ store_id: { $in: requestData.storeId } },
|
|
958
991
|
{ date_iso: { $gte: fromDate } },
|
|
959
992
|
{ date_iso: { $lte: toDate } },
|
|
993
|
+
// { store_id: { $in: requestData.storeId } },
|
|
994
|
+
{ userEmail: { $in: getUserEmails } },
|
|
995
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
960
996
|
);
|
|
961
997
|
|
|
962
998
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -1033,6 +1069,7 @@ export const storeDropdown = async ( req, res ) => {
|
|
|
1033
1069
|
return res.sendError( { error: error }, 500 );
|
|
1034
1070
|
}
|
|
1035
1071
|
};
|
|
1072
|
+
|
|
1036
1073
|
export async function checklistbasedStoreDropdown( req, res ) {
|
|
1037
1074
|
try {
|
|
1038
1075
|
let findQuery = [];
|
|
@@ -1055,6 +1092,7 @@ export async function checklistbasedStoreDropdown( req, res ) {
|
|
|
1055
1092
|
return res.sendError( { error: error }, 500 );
|
|
1056
1093
|
}
|
|
1057
1094
|
}
|
|
1095
|
+
|
|
1058
1096
|
export const userDropdown = async ( req, res ) => {
|
|
1059
1097
|
try {
|
|
1060
1098
|
let requestData = req.body;
|
|
@@ -1065,13 +1103,20 @@ export const userDropdown = async ( req, res ) => {
|
|
|
1065
1103
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
1066
1104
|
let result = {};
|
|
1067
1105
|
|
|
1106
|
+
// Get User Based Checklist //
|
|
1107
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
1108
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
1109
|
+
// End: Get User Based Checklist////
|
|
1110
|
+
|
|
1068
1111
|
let findQuery = [];
|
|
1069
1112
|
let findAndQuery = [];
|
|
1070
1113
|
findAndQuery.push(
|
|
1071
1114
|
{ client_id: requestData.clientId },
|
|
1072
|
-
{ store_id: { $in: requestData.storeId } },
|
|
1073
1115
|
{ date_iso: { $gte: fromDate } },
|
|
1074
1116
|
{ date_iso: { $lte: toDate } },
|
|
1117
|
+
// { store_id: { $in: requestData.storeId } },
|
|
1118
|
+
{ userEmail: { $in: getUserEmails } },
|
|
1119
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
1075
1120
|
);
|
|
1076
1121
|
|
|
1077
1122
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -1162,14 +1207,21 @@ export const checklistInfo = async ( req, res ) => {
|
|
|
1162
1207
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
1163
1208
|
let result = {};
|
|
1164
1209
|
|
|
1210
|
+
// Get User Based Checklist //
|
|
1211
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
1212
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
1213
|
+
// End: Get User Based Checklist////
|
|
1214
|
+
|
|
1165
1215
|
let findQuery = [];
|
|
1166
1216
|
let findAndQuery = [];
|
|
1167
1217
|
findAndQuery.push(
|
|
1168
1218
|
{ client_id: requestData.clientId },
|
|
1169
|
-
{ store_id: { $in: requestData.storeId } },
|
|
1170
1219
|
{ date_iso: { $gte: fromDate } },
|
|
1171
1220
|
{ date_iso: { $lte: toDate } },
|
|
1172
1221
|
{ checkListType: { $eq: 'custom' } },
|
|
1222
|
+
// { store_id: { $in: requestData.storeId } },
|
|
1223
|
+
{ userEmail: { $in: getUserEmails } },
|
|
1224
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
1173
1225
|
);
|
|
1174
1226
|
|
|
1175
1227
|
if ( requestData.checklistStatus && requestData.checklistStatus != 'All' ) {
|
|
@@ -1358,14 +1410,21 @@ export const infoCardsOld = async ( req, res ) => {
|
|
|
1358
1410
|
};
|
|
1359
1411
|
let result = {};
|
|
1360
1412
|
|
|
1413
|
+
// Get User Based Checklist //
|
|
1414
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
1415
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
1416
|
+
// End: Get User Based Checklist////
|
|
1417
|
+
|
|
1361
1418
|
let findQuery = [];
|
|
1362
1419
|
let findUniqueQuery = [];
|
|
1363
1420
|
let findAndQuery = [];
|
|
1364
1421
|
findAndQuery.push(
|
|
1365
1422
|
{ client_id: requestData.clientId },
|
|
1366
|
-
{ store_id: { $in: requestData.storeId } },
|
|
1367
1423
|
{ date_iso: { $gte: fromDate } },
|
|
1368
1424
|
{ date_iso: { $lte: toDate } },
|
|
1425
|
+
// { store_id: { $in: requestData.storeId } },
|
|
1426
|
+
{ userEmail: { $in: getUserEmails } },
|
|
1427
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
1369
1428
|
);
|
|
1370
1429
|
|
|
1371
1430
|
if ( requestData.groupByType == 'checklist' ) {
|
|
@@ -1642,14 +1701,21 @@ export const flagDetectionCards = async ( req, res ) => {
|
|
|
1642
1701
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
1643
1702
|
let result = {};
|
|
1644
1703
|
|
|
1704
|
+
// Get User Based Checklist //
|
|
1705
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
1706
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
1707
|
+
// End: Get User Based Checklist////
|
|
1708
|
+
|
|
1645
1709
|
let findQuery = [];
|
|
1646
1710
|
let findAndQuery = [];
|
|
1647
1711
|
findAndQuery.push(
|
|
1648
1712
|
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
|
|
1649
1713
|
{ client_id: requestData.clientId },
|
|
1650
|
-
{ store_id: { $in: requestData.storeId } },
|
|
1651
1714
|
{ date_iso: { $gte: fromDate } },
|
|
1652
1715
|
{ date_iso: { $lte: toDate } },
|
|
1716
|
+
// { store_id: { $in: requestData.storeId } },
|
|
1717
|
+
{ userEmail: { $in: getUserEmails } },
|
|
1718
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
1653
1719
|
);
|
|
1654
1720
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
1655
1721
|
|
|
@@ -1799,15 +1865,22 @@ export const flagDetectionTables = async ( req, res ) => {
|
|
|
1799
1865
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
1800
1866
|
let result = {};
|
|
1801
1867
|
|
|
1868
|
+
// Get User Based Checklist //
|
|
1869
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
1870
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
1871
|
+
// End: Get User Based Checklist////
|
|
1872
|
+
|
|
1802
1873
|
let findQuery = [];
|
|
1803
1874
|
let findAndQuery = [];
|
|
1804
1875
|
findAndQuery.push(
|
|
1805
1876
|
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
|
|
1806
1877
|
{ client_id: requestData.clientId },
|
|
1807
|
-
{ store_id: { $in: requestData.storeId } },
|
|
1808
1878
|
{ date_iso: { $gte: fromDate } },
|
|
1809
1879
|
{ date_iso: { $lte: toDate } },
|
|
1810
1880
|
{ checklistStatus: { $eq: 'submit' } },
|
|
1881
|
+
// { store_id: { $in: requestData.storeId } },
|
|
1882
|
+
{ userEmail: { $in: getUserEmails } },
|
|
1883
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
1811
1884
|
);
|
|
1812
1885
|
|
|
1813
1886
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -2140,6 +2213,11 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
2140
2213
|
};
|
|
2141
2214
|
let result = {};
|
|
2142
2215
|
|
|
2216
|
+
// Get User Based Checklist //
|
|
2217
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
2218
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
2219
|
+
// End: Get User Based Checklist////
|
|
2220
|
+
|
|
2143
2221
|
let findQuery = [];
|
|
2144
2222
|
let findUniqueQuery = [];
|
|
2145
2223
|
let findAndQuery = [];
|
|
@@ -2147,7 +2225,9 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
2147
2225
|
{ checkListType: { $eq: 'custom' } },
|
|
2148
2226
|
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
2149
2227
|
{ client_id: requestData.clientId },
|
|
2150
|
-
{ store_id: { $in: requestData.storeId } },
|
|
2228
|
+
// { store_id: { $in: requestData.storeId } },
|
|
2229
|
+
{ userEmail: { $in: getUserEmails } },
|
|
2230
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
2151
2231
|
);
|
|
2152
2232
|
|
|
2153
2233
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -2384,13 +2464,20 @@ export const overallComparisonCardsV1 = async ( req, res ) => {
|
|
|
2384
2464
|
'complianceRate': complianceRate,
|
|
2385
2465
|
};
|
|
2386
2466
|
|
|
2467
|
+
// Get User Based Checklist //
|
|
2468
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
2469
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
2470
|
+
// End: Get User Based Checklist////
|
|
2471
|
+
|
|
2387
2472
|
let rangeOneFindQuery = [];
|
|
2388
2473
|
let rangeOneFindAndQuery = [];
|
|
2389
2474
|
rangeOneFindAndQuery.push(
|
|
2390
2475
|
{ checkListType: { $eq: 'custom' } },
|
|
2391
2476
|
{ date_iso: { $gte: rangeOneFromDate, $lte: rangeOneToDate } },
|
|
2392
2477
|
{ client_id: requestData.clientId },
|
|
2393
|
-
{ store_id: { $in: requestData.storeId } },
|
|
2478
|
+
// { store_id: { $in: requestData.storeId } },
|
|
2479
|
+
{ userEmail: { $in: getUserEmails } },
|
|
2480
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
2394
2481
|
);
|
|
2395
2482
|
|
|
2396
2483
|
rangeOneFindQuery.push( { $match: { $and: rangeOneFindAndQuery } } );
|
|
@@ -2487,7 +2574,9 @@ export const overallComparisonCardsV1 = async ( req, res ) => {
|
|
|
2487
2574
|
{ checkListType: { $eq: 'custom' } },
|
|
2488
2575
|
{ date_iso: { $gte: rangeTwoFromDate, $lte: rangeTwoToDate } },
|
|
2489
2576
|
{ client_id: requestData.clientId },
|
|
2490
|
-
{ store_id: { $in: requestData.storeId } },
|
|
2577
|
+
// { store_id: { $in: requestData.storeId } },
|
|
2578
|
+
{ userEmail: { $in: getUserEmails } },
|
|
2579
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
2491
2580
|
);
|
|
2492
2581
|
|
|
2493
2582
|
rangeTwoFindQuery.push( { $match: { $and: rangeTwoFindAndQuery } } );
|
|
@@ -2625,15 +2714,22 @@ export const infoCardsV1 = async ( req, res ) => {
|
|
|
2625
2714
|
};
|
|
2626
2715
|
let result = {};
|
|
2627
2716
|
|
|
2717
|
+
// Get User Based Checklist //
|
|
2718
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
2719
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
2720
|
+
// End: Get User Based Checklist////
|
|
2721
|
+
|
|
2628
2722
|
let findQuery = [];
|
|
2629
2723
|
let findUniqueQuery = [];
|
|
2630
2724
|
let findAndQuery = [];
|
|
2631
2725
|
findAndQuery.push(
|
|
2632
2726
|
{ client_id: requestData.clientId },
|
|
2633
|
-
{ store_id: { $in: requestData.storeId } },
|
|
2634
2727
|
{ date_iso: { $gte: fromDate } },
|
|
2635
2728
|
{ date_iso: { $lte: toDate } },
|
|
2636
2729
|
{ checkListType: { $eq: 'custom' } },
|
|
2730
|
+
// { store_id: { $in: requestData.storeId } },
|
|
2731
|
+
{ userEmail: { $in: getUserEmails } },
|
|
2732
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
2637
2733
|
);
|
|
2638
2734
|
|
|
2639
2735
|
if ( requestData.groupByType == 'Checklist' ) {
|
|
@@ -2903,14 +2999,21 @@ export const infoComparisonCardsV1 = async ( req, res ) => {
|
|
|
2903
2999
|
'complianceRate': complianceRate,
|
|
2904
3000
|
};
|
|
2905
3001
|
|
|
3002
|
+
// Get User Based Checklist //
|
|
3003
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
3004
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
3005
|
+
// End: Get User Based Checklist////
|
|
3006
|
+
|
|
2906
3007
|
let rangeOneFindQuery = [];
|
|
2907
3008
|
let rangeOneFindAndQuery = [];
|
|
2908
3009
|
rangeOneFindAndQuery.push(
|
|
2909
3010
|
{ client_id: requestData.clientId },
|
|
2910
|
-
{ store_id: { $in: requestData.storeId } },
|
|
2911
3011
|
{ date_iso: { $gte: rangeOneFromDate } },
|
|
2912
3012
|
{ date_iso: { $lte: rangeOneToDate } },
|
|
2913
3013
|
{ checkListType: { $eq: 'custom' } },
|
|
3014
|
+
// { store_id: { $in: requestData.storeId } },
|
|
3015
|
+
{ userEmail: { $in: getUserEmails } },
|
|
3016
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
2914
3017
|
);
|
|
2915
3018
|
|
|
2916
3019
|
if ( requestData.groupByType == 'Checklist' ) {
|
|
@@ -3025,10 +3128,12 @@ export const infoComparisonCardsV1 = async ( req, res ) => {
|
|
|
3025
3128
|
let rangeTwoFindAndQuery = [];
|
|
3026
3129
|
rangeTwoFindAndQuery.push(
|
|
3027
3130
|
{ client_id: requestData.clientId },
|
|
3028
|
-
{ store_id: { $in: requestData.storeId } },
|
|
3029
3131
|
{ date_iso: { $gte: rangeTwoFromDate } },
|
|
3030
3132
|
{ date_iso: { $lte: rangeTwoToDate } },
|
|
3031
3133
|
{ checkListType: { $eq: 'custom' } },
|
|
3134
|
+
// { store_id: { $in: requestData.storeId } },
|
|
3135
|
+
{ userEmail: { $in: getUserEmails } },
|
|
3136
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
3032
3137
|
);
|
|
3033
3138
|
if ( requestData.groupByType == 'Checklist' ) {
|
|
3034
3139
|
rangeTwoFindAndQuery.push( { sourceCheckList_id: new mongoose.Types.ObjectId( requestData.groupByValue ) } );
|
|
@@ -3213,14 +3318,22 @@ export const monthlyGraphV1 = async ( req, res ) => {
|
|
|
3213
3318
|
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
3214
3319
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
3215
3320
|
let result = {};
|
|
3321
|
+
|
|
3322
|
+
// Get User Based Checklist //
|
|
3323
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
3324
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
3325
|
+
// End: Get User Based Checklist////
|
|
3326
|
+
|
|
3216
3327
|
let findQuery = [];
|
|
3217
3328
|
let findAndQuery = [];
|
|
3218
3329
|
findAndQuery.push(
|
|
3219
3330
|
{ client_id: requestData.clientId },
|
|
3220
|
-
{ store_id: { $in: requestData.storeId } },
|
|
3221
3331
|
{ date_iso: { $gte: fromDate } },
|
|
3222
3332
|
{ date_iso: { $lte: toDate } },
|
|
3223
3333
|
{ checkListType: { $eq: 'custom' } },
|
|
3334
|
+
// { store_id: { $in: requestData.storeId } },
|
|
3335
|
+
{ userEmail: { $in: getUserEmails } },
|
|
3336
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
3224
3337
|
);
|
|
3225
3338
|
|
|
3226
3339
|
if ( requestData.groupByType == 'Checklist' ) {
|
|
@@ -3449,12 +3562,19 @@ export const checklistDropdown = async ( req, res ) => {
|
|
|
3449
3562
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
3450
3563
|
let result = {};
|
|
3451
3564
|
|
|
3565
|
+
// Get User Based Checklist //
|
|
3566
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
3567
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
3568
|
+
// End: Get User Based Checklist////
|
|
3569
|
+
|
|
3452
3570
|
let findQuery = [
|
|
3453
3571
|
{ $match: { $and: [
|
|
3454
3572
|
{ client_id: requestData.clientId },
|
|
3455
|
-
{ store_id: { $in: requestData.storeId } },
|
|
3456
3573
|
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
3457
3574
|
{ checkListType: 'custom' },
|
|
3575
|
+
// { store_id: { $in: requestData.storeId } },
|
|
3576
|
+
{ userEmail: { $in: getUserEmails } },
|
|
3577
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
3458
3578
|
] } },
|
|
3459
3579
|
{
|
|
3460
3580
|
$project: {
|
|
@@ -3642,165 +3762,49 @@ export async function sendAlert( req, res ) {
|
|
|
3642
3762
|
}
|
|
3643
3763
|
}
|
|
3644
3764
|
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
},
|
|
3692
|
-
},
|
|
3693
|
-
timeFlag: { $sum: '$timeFlag' },
|
|
3694
|
-
questionFlagCount: { $sum: '$questionFlag' },
|
|
3695
|
-
checkListType: { $last: '$checkListType' },
|
|
3696
|
-
redo: { $sum: { $cond: [ { $eq: [ '$redoStatus', true ] }, 1, 0 ] } },
|
|
3697
|
-
task: {
|
|
3698
|
-
$sum: {
|
|
3699
|
-
$reduce: {
|
|
3700
|
-
input: '$questionAnswers',
|
|
3701
|
-
initialValue: 0,
|
|
3702
|
-
in: {
|
|
3703
|
-
$add: [
|
|
3704
|
-
'$$value',
|
|
3705
|
-
{
|
|
3706
|
-
$reduce: {
|
|
3707
|
-
input: { $ifNull: [ '$$this.questions', [] ] },
|
|
3708
|
-
initialValue: 0,
|
|
3709
|
-
in: {
|
|
3710
|
-
$add: [
|
|
3711
|
-
'$$value',
|
|
3712
|
-
{
|
|
3713
|
-
$cond: [
|
|
3714
|
-
{ $ifNull: [ '$$this.taskId', false ] },
|
|
3715
|
-
1,
|
|
3716
|
-
0,
|
|
3717
|
-
],
|
|
3718
|
-
},
|
|
3719
|
-
],
|
|
3720
|
-
},
|
|
3721
|
-
},
|
|
3722
|
-
},
|
|
3723
|
-
],
|
|
3724
|
-
},
|
|
3725
|
-
},
|
|
3726
|
-
},
|
|
3727
|
-
},
|
|
3728
|
-
},
|
|
3729
|
-
} );
|
|
3730
|
-
findQuery.push( {
|
|
3731
|
-
$project: {
|
|
3732
|
-
_id: 1,
|
|
3733
|
-
sourceCheckList_id: 1,
|
|
3734
|
-
checkListName: 1,
|
|
3735
|
-
checkListChar: 1,
|
|
3736
|
-
coverage: {
|
|
3737
|
-
$concat: [
|
|
3738
|
-
{ $toUpper: { $substr: [ { $ifNull: [ '$coverage', '' ] }, 0, 1 ] } },
|
|
3739
|
-
{ $substr: [ { $ifNull: [ '$coverage', '' ] }, 1, { $strLenCP: { $ifNull: [ '$coverage', '' ] } } ] },
|
|
3740
|
-
],
|
|
3741
|
-
},
|
|
3742
|
-
scheduleRepeatedType: {
|
|
3743
|
-
$concat: [
|
|
3744
|
-
{ $toUpper: { $substr: [ '$scheduleRepeatedType', 0, 1 ] } }, // Capitalize the first letter
|
|
3745
|
-
{ $substr: [ '$scheduleRepeatedType', 1, { $strLenCP: '$scheduleRepeatedType' } ] }, // Append the rest of the string
|
|
3746
|
-
],
|
|
3747
|
-
},
|
|
3748
|
-
storeCount: 1,
|
|
3749
|
-
submittedChecklist: 1,
|
|
3750
|
-
flaggedChecklist: { $add: [ '$timeFlag', '$questionFlagCount' ] },
|
|
3751
|
-
checkListType: 1,
|
|
3752
|
-
redo: 1,
|
|
3753
|
-
task: 1,
|
|
3754
|
-
},
|
|
3755
|
-
} );
|
|
3756
|
-
|
|
3757
|
-
if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
|
|
3758
|
-
findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
|
|
3759
|
-
} else {
|
|
3760
|
-
findQuery.push( { $sort: { ['submittedChecklist']: -1 } } );
|
|
3761
|
-
}
|
|
3762
|
-
|
|
3763
|
-
let limit = parseInt( requestData?.limit ) || 10;
|
|
3764
|
-
let skip = limit * ( requestData?.offset ) || 0;
|
|
3765
|
-
|
|
3766
|
-
findQuery.push( {
|
|
3767
|
-
$facet: {
|
|
3768
|
-
data: [
|
|
3769
|
-
{ $skip: skip }, { $limit: limit },
|
|
3770
|
-
],
|
|
3771
|
-
count: [
|
|
3772
|
-
{ $count: 'total' },
|
|
3773
|
-
],
|
|
3774
|
-
},
|
|
3775
|
-
} );
|
|
3776
|
-
let getChecklistPerformanceData = await processedchecklistService.aggregate( findQuery );
|
|
3777
|
-
if ( !getChecklistPerformanceData[0].data.length ) {
|
|
3778
|
-
return res.sendError( 'no data found', 204 );
|
|
3779
|
-
}
|
|
3780
|
-
|
|
3781
|
-
if ( requestData.export ) {
|
|
3782
|
-
const exportdata = [];
|
|
3783
|
-
getChecklistPerformanceData[0].data.forEach( ( element ) => {
|
|
3784
|
-
exportdata.push( {
|
|
3785
|
-
'Checklist Name': element.checkListName || '--',
|
|
3786
|
-
'Coverage': element.coverage || '--',
|
|
3787
|
-
'Scheduled': element.scheduleRepeatedType || '--',
|
|
3788
|
-
'Assigned To': element.storeCount || '--',
|
|
3789
|
-
'Submitted': element.submittedChecklist || '--',
|
|
3790
|
-
'Flags': element.flaggedChecklist || '--',
|
|
3791
|
-
'Tasks': element.task || '--',
|
|
3792
|
-
'ReDo': element.redo || '--',
|
|
3793
|
-
} );
|
|
3794
|
-
} );
|
|
3795
|
-
return await download( exportdata, res );
|
|
3796
|
-
}
|
|
3797
|
-
|
|
3798
|
-
result.totalCount = getChecklistPerformanceData[0].count[0].total;
|
|
3799
|
-
result.checklistPerformance = getChecklistPerformanceData[0].data;
|
|
3800
|
-
return res.sendSuccess( result );
|
|
3801
|
-
} catch ( error ) {
|
|
3802
|
-
console.log( 'error =>', error );
|
|
3803
|
-
logger.error( { error: error, message: req.query, function: 'checklistPerformance' } );
|
|
3804
|
-
return res.sendError( { error: error }, 500 );
|
|
3805
|
-
}
|
|
3806
|
-
};
|
|
3765
|
+
// async function getChecklistUsers( loginUser ) {
|
|
3766
|
+
// try {
|
|
3767
|
+
// // userType, role, clientId, userEmail All Key Required Fields
|
|
3768
|
+
// if ( loginUser.userType == 'tango' || loginUser.role == 'superadmin' ) {
|
|
3769
|
+
// // //return All users Emails
|
|
3770
|
+
// const userQuery = [
|
|
3771
|
+
// { $match: { isActive: true, clientId: loginUser.clientId } },
|
|
3772
|
+
// { $group: { _id: '$clientId', email: { $push: '$email' } } },
|
|
3773
|
+
// { $project: { email: 1, _id: 0 } },
|
|
3774
|
+
// ];
|
|
3775
|
+
// let getUsersData = await userService.aggregate( userQuery );
|
|
3776
|
+
// if ( getUsersData.length > 0 ) {
|
|
3777
|
+
// let getUsers = getUsersData[0].email;
|
|
3778
|
+
// if ( loginUser.userType == 'client' ) {
|
|
3779
|
+
// getUsers.push( loginUser.userEmail );
|
|
3780
|
+
// }
|
|
3781
|
+
// return getUsers;
|
|
3782
|
+
// } else {
|
|
3783
|
+
// if ( loginUser.userType == 'client' ) {
|
|
3784
|
+
// return [ loginUser.userEmail ];
|
|
3785
|
+
// } else {
|
|
3786
|
+
// return [ ];
|
|
3787
|
+
// }
|
|
3788
|
+
// }
|
|
3789
|
+
// } else if ( loginUser.role == 'admin' || loginUser.role == 'user' ) {
|
|
3790
|
+
// // //return Find Teams and Get Users
|
|
3791
|
+
// let findTeamsMembersQuery = [
|
|
3792
|
+
// { $match: { clientId: loginUser.clientId, Teamlead: { $elemMatch: { email: loginUser.userEmail } } } },
|
|
3793
|
+
// { $unwind: '$users' },
|
|
3794
|
+
// { $group: { _id: null, emails: { $push: '$users.email' } } },
|
|
3795
|
+
// { $project: { _id: 0, emails: 1 } },
|
|
3796
|
+
// ];
|
|
3797
|
+
// let getUsers = await findteams.aggregateTeams( findTeamsMembersQuery );
|
|
3798
|
+
// if ( getUsers.length > 0 ) {
|
|
3799
|
+
// getUsers[0].emails.push( loginUser.userEmail );
|
|
3800
|
+
// return getUsers[0].emails;
|
|
3801
|
+
// } else {
|
|
3802
|
+
// return [ loginUser.userEmail ];
|
|
3803
|
+
// }
|
|
3804
|
+
// }
|
|
3805
|
+
// } catch ( error ) {
|
|
3806
|
+
// console.log( 'error getChecklistUsers=>', error );
|
|
3807
|
+
// logger.error( { error: error, function: 'getChecklistUsers' } );
|
|
3808
|
+
// return [ ];
|
|
3809
|
+
// }
|
|
3810
|
+
// }
|
|
@@ -114,7 +114,7 @@ export const publishValidation = {
|
|
|
114
114
|
};
|
|
115
115
|
|
|
116
116
|
export const dashboardSchema = joi.object( {
|
|
117
|
-
store_id: joi.string().
|
|
117
|
+
store_id: joi.string().optional().allow( '' ),
|
|
118
118
|
date: joi.string().required(),
|
|
119
119
|
} );
|
|
120
120
|
|
|
@@ -126,7 +126,7 @@ export const mobileChecklistSchema = joi.object( {
|
|
|
126
126
|
limit: joi.string().optional(),
|
|
127
127
|
offset: joi.string().optional(),
|
|
128
128
|
date: joi.string().optional(),
|
|
129
|
-
store_id: joi.string().optional(),
|
|
129
|
+
store_id: joi.string().optional().allow( '' ),
|
|
130
130
|
checklistStatus: joi.string().optional().allow( '' ),
|
|
131
131
|
searchValue: joi.string().optional().allow( '' ),
|
|
132
132
|
} );
|