tango-app-api-trax 3.2.1 → 3.3.1-airtel-1
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 +3 -3
- package/src/controllers/download.controller.js +154 -17
- package/src/controllers/gallery.controller.js +124 -31
- package/src/controllers/internalTrax.controller.js +284 -5
- package/src/controllers/mobileTrax.controller.js +200 -40
- package/src/controllers/teaxFlag.controller.js +161 -142
- package/src/controllers/trax.controller.js +1477 -153
- package/src/controllers/traxDashboard.controllers.js +350 -105
- package/src/dtos/dashboardValidation.dtos.js +2 -0
- package/src/dtos/downloadValidation.dtos.js +3 -0
- package/src/dtos/validation.dtos.js +17 -5
- package/src/routes/download.router.js +4 -0
- package/src/routes/gallery.routes.js +5 -1
- package/src/routes/internalTraxApi.router.js +3 -1
- package/src/routes/mobileTrax.routes.js +3 -1
- package/src/routes/trax.routes.js +12 -2
- package/src/routes/traxDashboard.routes.js +3 -1
- package/src/services/checklistAssign.service.js +8 -0
- package/src/services/planogram.service.js +5 -0
- package/src/services/teams.service.js +30 -0
|
@@ -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,19 @@ 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
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
287
293
|
);
|
|
288
294
|
|
|
289
295
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -321,6 +327,7 @@ export const checklistPerformance = async ( req, res ) => {
|
|
|
321
327
|
_id: '$sourceCheckList_id',
|
|
322
328
|
sourceCheckList_id: { $last: '$sourceCheckList_id' },
|
|
323
329
|
checkListName: { $last: '$checkListName' },
|
|
330
|
+
coverage: { $last: '$coverage' },
|
|
324
331
|
checkListChar: { $last: { $substr: [ '$checkListName', 0, 2 ] } },
|
|
325
332
|
scheduleRepeatedType: { $last: '$scheduleRepeatedType' },
|
|
326
333
|
// storeCount: { $max: '$storeCount' },
|
|
@@ -372,6 +379,12 @@ export const checklistPerformance = async ( req, res ) => {
|
|
|
372
379
|
_id: 1,
|
|
373
380
|
sourceCheckList_id: 1,
|
|
374
381
|
checkListName: 1,
|
|
382
|
+
coverage: {
|
|
383
|
+
$concat: [
|
|
384
|
+
{ $toUpper: { $substr: [ { $ifNull: [ '$coverage', '' ] }, 0, 1 ] } },
|
|
385
|
+
{ $substr: [ { $ifNull: [ '$coverage', '' ] }, 1, { $strLenCP: { $ifNull: [ '$coverage', '' ] } } ] },
|
|
386
|
+
],
|
|
387
|
+
},
|
|
375
388
|
checkListChar: 1,
|
|
376
389
|
scheduleRepeatedType: {
|
|
377
390
|
$concat: [
|
|
@@ -417,6 +430,7 @@ export const checklistPerformance = async ( req, res ) => {
|
|
|
417
430
|
getChecklistPerformanceData[0].data.forEach( ( element ) => {
|
|
418
431
|
exportdata.push( {
|
|
419
432
|
'Checklist Name': element.checkListName || '--',
|
|
433
|
+
'Coverage': element.coverage || '--',
|
|
420
434
|
'Scheduled': element.scheduleRepeatedType || '--',
|
|
421
435
|
'Assigned To': element.storeCount || '--',
|
|
422
436
|
'Submitted': element.submittedChecklist || '--',
|
|
@@ -448,14 +462,21 @@ export const storePerformance = async ( req, res ) => {
|
|
|
448
462
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
449
463
|
let result = {};
|
|
450
464
|
|
|
465
|
+
// Get User Based Checklist //
|
|
466
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
467
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
468
|
+
// End: Get User Based Checklist////
|
|
469
|
+
|
|
451
470
|
let findQuery = [];
|
|
452
471
|
let findAndQuery = [];
|
|
453
472
|
findAndQuery.push(
|
|
454
473
|
{ client_id: requestData.clientId },
|
|
455
|
-
{ store_id: { $in: requestData.storeId } },
|
|
456
474
|
{ date_iso: { $gte: fromDate } },
|
|
457
475
|
{ date_iso: { $lte: toDate } },
|
|
458
476
|
{ checkListType: { $eq: 'custom' } },
|
|
477
|
+
// { store_id: { $in: requestData.storeId } },
|
|
478
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
479
|
+
{ coverage: { $eq: 'store' } },
|
|
459
480
|
);
|
|
460
481
|
|
|
461
482
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -653,13 +674,19 @@ export const userPerformance = async ( req, res ) => {
|
|
|
653
674
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
654
675
|
let result = {};
|
|
655
676
|
|
|
677
|
+
// Get User Based Checklist //
|
|
678
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
679
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
680
|
+
// End: Get User Based Checklist////
|
|
681
|
+
|
|
656
682
|
let findQuery = [];
|
|
657
683
|
let findAndQuery = [];
|
|
658
684
|
findAndQuery.push(
|
|
659
685
|
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
660
686
|
{ checkListType: { $eq: 'custom' } },
|
|
661
687
|
{ client_id: requestData.clientId },
|
|
662
|
-
{ store_id: { $in: requestData.storeId } },
|
|
688
|
+
// { store_id: { $in: requestData.storeId } },
|
|
689
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
663
690
|
);
|
|
664
691
|
|
|
665
692
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -709,121 +736,93 @@ export const userPerformance = async ( req, res ) => {
|
|
|
709
736
|
_id: '$userName',
|
|
710
737
|
totalChecklist: { $sum: 1 },
|
|
711
738
|
userEmail: { $last: '$userEmail' },
|
|
712
|
-
checkListCount: { $sum:
|
|
739
|
+
checkListCount: { $sum: 1 },
|
|
713
740
|
timeFlag: { $sum: '$timeFlag' },
|
|
714
|
-
submittedChecklist: {
|
|
715
|
-
$sum: {
|
|
716
|
-
$cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ],
|
|
717
|
-
},
|
|
718
|
-
},
|
|
741
|
+
submittedChecklist: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ] } },
|
|
719
742
|
checkListType: { $last: '$checkListType' },
|
|
720
|
-
// questionFlag: { $sum: '$questionFlag' },
|
|
721
743
|
questionFlag: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionFlag', 0 ] } },
|
|
722
744
|
questionCount: { $sum: '$questionCount' },
|
|
723
|
-
submittedChecklistQuestionCount: {
|
|
745
|
+
submittedChecklistQuestionCount: {
|
|
746
|
+
$sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionCount', 0 ] },
|
|
747
|
+
},
|
|
724
748
|
},
|
|
725
749
|
} );
|
|
726
750
|
|
|
751
|
+
|
|
727
752
|
findQuery.push( {
|
|
728
|
-
$
|
|
753
|
+
$addFields: {
|
|
729
754
|
userName: '$_id',
|
|
730
|
-
userEmail: 1,
|
|
731
|
-
checkListCount: { $sum: '$totalChecklist' },
|
|
732
755
|
flaggedCount: { $add: [ '$timeFlag', '$questionFlag' ] },
|
|
733
|
-
|
|
734
|
-
timeFlag: 1,
|
|
735
|
-
checkListType: 1,
|
|
736
|
-
questionCount: 1,
|
|
737
|
-
questionFlag: 1,
|
|
756
|
+
correctAnswers: { $subtract: [ '$submittedChecklistQuestionCount', '$questionFlag' ] },
|
|
738
757
|
completion: {
|
|
739
|
-
$round: [
|
|
740
|
-
|
|
758
|
+
$round: [
|
|
759
|
+
{ $multiply: [ { $divide: [ '$submittedChecklist', '$totalChecklist' ] }, 100 ] },
|
|
760
|
+
0,
|
|
761
|
+
],
|
|
741
762
|
},
|
|
742
|
-
correctAnswers: { $subtract: [ '$submittedChecklistQuestionCount', '$questionFlag' ] },
|
|
743
763
|
},
|
|
744
764
|
} );
|
|
745
765
|
|
|
766
|
+
|
|
746
767
|
findQuery.push( {
|
|
747
|
-
$
|
|
748
|
-
userName: 1,
|
|
749
|
-
userEmail: 1,
|
|
750
|
-
checkListCount: 1,
|
|
751
|
-
flaggedCount: 1,
|
|
752
|
-
submittedChecklist: 1,
|
|
753
|
-
checkListType: 1,
|
|
754
|
-
questionCount: 1,
|
|
755
|
-
questionFlag: 1,
|
|
756
|
-
timeFlag: 1,
|
|
757
|
-
completion: 1,
|
|
758
|
-
compliance: 1,
|
|
768
|
+
$addFields: {
|
|
759
769
|
compliance: {
|
|
760
770
|
$cond: {
|
|
761
771
|
if: { $eq: [ '$questionCount', 0 ] },
|
|
762
772
|
then: 0,
|
|
763
773
|
else: {
|
|
764
774
|
$round: [ { $multiply: [ { $divide: [ '$correctAnswers', '$questionCount' ] }, 100 ] }, 0 ],
|
|
765
|
-
// $multiply: [ { $divide: [ '$correctAnswers', '$questionCount' ] }, 100 ],
|
|
766
775
|
},
|
|
767
776
|
},
|
|
768
777
|
},
|
|
778
|
+
lowercaseUserName: { $toLower: '$userName' },
|
|
769
779
|
},
|
|
770
780
|
} );
|
|
771
781
|
|
|
772
782
|
findQuery.push( {
|
|
773
|
-
$
|
|
774
|
-
userName: 1,
|
|
775
|
-
lowercaseUserName: { $toLower: '$userName' },
|
|
776
|
-
userEmail: 1,
|
|
777
|
-
checkListCount: 1,
|
|
778
|
-
flaggedCount: 1,
|
|
779
|
-
submittedChecklist: 1,
|
|
780
|
-
checkListType: 1,
|
|
781
|
-
questionCount: 1,
|
|
782
|
-
questionFlag: 1,
|
|
783
|
-
timeFlag: 1,
|
|
784
|
-
correctAnswers: 1,
|
|
785
|
-
completion: 1,
|
|
786
|
-
compliance: 1,
|
|
783
|
+
$addFields: {
|
|
787
784
|
performance: { $round: [ { $divide: [ { $add: [ '$completion', '$compliance' ] }, 2 ] }, 0 ] },
|
|
788
|
-
// performance: { $divide: [ { $add: [ '$completion', '$compliance' ] }, 2 ] },
|
|
789
785
|
},
|
|
790
786
|
} );
|
|
791
787
|
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
|
|
798
|
-
if ( requestData.sortColumnName == 'userName' ) {
|
|
799
|
-
findQuery.push( { $sort: { ['lowercaseUserName']: requestData.sortBy } } );
|
|
800
|
-
} else {
|
|
801
|
-
findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
|
|
802
|
-
}
|
|
788
|
+
if ( requestData.sortColumnName && requestData.sortBy ) {
|
|
789
|
+
const sortField =
|
|
790
|
+
requestData.sortColumnName === 'userName' ? 'lowercaseUserName' : requestData.sortColumnName;
|
|
791
|
+
findQuery.push( { $sort: { [sortField]: requestData.sortBy } } );
|
|
803
792
|
} else {
|
|
804
|
-
findQuery.push( { $sort: {
|
|
793
|
+
findQuery.push( { $sort: { userName: -1 } } );
|
|
805
794
|
}
|
|
806
795
|
|
|
807
796
|
let limit = parseInt( requestData?.limit ) || 10;
|
|
808
|
-
let skip = limit * ( requestData?.offset
|
|
797
|
+
let skip = limit * ( requestData?.offset || 0 );
|
|
809
798
|
findQuery.push( {
|
|
810
799
|
$facet: {
|
|
811
|
-
data: [
|
|
812
|
-
|
|
813
|
-
],
|
|
814
|
-
count: [
|
|
815
|
-
{ $count: 'total' },
|
|
816
|
-
],
|
|
800
|
+
data: [ { $skip: skip }, { $limit: limit } ],
|
|
801
|
+
count: [ { $count: 'total' } ],
|
|
817
802
|
},
|
|
818
|
-
}
|
|
819
|
-
|
|
803
|
+
} );
|
|
804
|
+
|
|
820
805
|
|
|
821
806
|
let getUserPerformanceData = await processedchecklistService.aggregate( findQuery );
|
|
822
807
|
|
|
823
808
|
if ( !getUserPerformanceData[0].data.length ) {
|
|
824
809
|
return res.sendError( { error: 'No Data Found' }, 204 );
|
|
825
810
|
}
|
|
826
|
-
|
|
811
|
+
if ( requestData.export ) {
|
|
812
|
+
const exportdata = [];
|
|
813
|
+
getUserPerformanceData[0].data.forEach( ( element ) => {
|
|
814
|
+
exportdata.push( {
|
|
815
|
+
'User Name': element.userName || '--',
|
|
816
|
+
'Email': element.userEmail || '--',
|
|
817
|
+
'Checklist Assigned': element.checkListCount || '--',
|
|
818
|
+
'Flags': element.flaggedCount || '--',
|
|
819
|
+
'Completion %': element.completion || '--',
|
|
820
|
+
'Compliance %': element.compliance || '--',
|
|
821
|
+
'Performance %': element.performance || '--',
|
|
822
|
+
} );
|
|
823
|
+
} );
|
|
824
|
+
return await download( exportdata, res );
|
|
825
|
+
}
|
|
827
826
|
result.totalCount = getUserPerformanceData[0].count[0].total;
|
|
828
827
|
result.userPerformance = getUserPerformanceData[0].data;
|
|
829
828
|
return res.sendSuccess( result );
|
|
@@ -950,13 +949,19 @@ export const storeDropdown = async ( req, res ) => {
|
|
|
950
949
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
951
950
|
let result = {};
|
|
952
951
|
|
|
952
|
+
// Get User Based Checklist //
|
|
953
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
954
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
955
|
+
// End: Get User Based Checklist////
|
|
956
|
+
|
|
953
957
|
let findQuery = [];
|
|
954
958
|
let findAndQuery = [];
|
|
955
959
|
findAndQuery.push(
|
|
956
960
|
{ client_id: requestData.clientId },
|
|
957
|
-
{ store_id: { $in: requestData.storeId } },
|
|
958
961
|
{ date_iso: { $gte: fromDate } },
|
|
959
962
|
{ date_iso: { $lte: toDate } },
|
|
963
|
+
// { store_id: { $in: requestData.storeId } },
|
|
964
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
960
965
|
);
|
|
961
966
|
|
|
962
967
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -1033,6 +1038,7 @@ export const storeDropdown = async ( req, res ) => {
|
|
|
1033
1038
|
return res.sendError( { error: error }, 500 );
|
|
1034
1039
|
}
|
|
1035
1040
|
};
|
|
1041
|
+
|
|
1036
1042
|
export async function checklistbasedStoreDropdown( req, res ) {
|
|
1037
1043
|
try {
|
|
1038
1044
|
let findQuery = [];
|
|
@@ -1055,6 +1061,7 @@ export async function checklistbasedStoreDropdown( req, res ) {
|
|
|
1055
1061
|
return res.sendError( { error: error }, 500 );
|
|
1056
1062
|
}
|
|
1057
1063
|
}
|
|
1064
|
+
|
|
1058
1065
|
export const userDropdown = async ( req, res ) => {
|
|
1059
1066
|
try {
|
|
1060
1067
|
let requestData = req.body;
|
|
@@ -1065,13 +1072,19 @@ export const userDropdown = async ( req, res ) => {
|
|
|
1065
1072
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
1066
1073
|
let result = {};
|
|
1067
1074
|
|
|
1075
|
+
// Get User Based Checklist //
|
|
1076
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
1077
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
1078
|
+
// End: Get User Based Checklist////
|
|
1079
|
+
|
|
1068
1080
|
let findQuery = [];
|
|
1069
1081
|
let findAndQuery = [];
|
|
1070
1082
|
findAndQuery.push(
|
|
1071
1083
|
{ client_id: requestData.clientId },
|
|
1072
|
-
{ store_id: { $in: requestData.storeId } },
|
|
1073
1084
|
{ date_iso: { $gte: fromDate } },
|
|
1074
1085
|
{ date_iso: { $lte: toDate } },
|
|
1086
|
+
// { store_id: { $in: requestData.storeId } },
|
|
1087
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
1075
1088
|
);
|
|
1076
1089
|
|
|
1077
1090
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -1162,14 +1175,20 @@ export const checklistInfo = async ( req, res ) => {
|
|
|
1162
1175
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
1163
1176
|
let result = {};
|
|
1164
1177
|
|
|
1178
|
+
// Get User Based Checklist //
|
|
1179
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
1180
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
1181
|
+
// End: Get User Based Checklist////
|
|
1182
|
+
|
|
1165
1183
|
let findQuery = [];
|
|
1166
1184
|
let findAndQuery = [];
|
|
1167
1185
|
findAndQuery.push(
|
|
1168
1186
|
{ client_id: requestData.clientId },
|
|
1169
|
-
{ store_id: { $in: requestData.storeId } },
|
|
1170
1187
|
{ date_iso: { $gte: fromDate } },
|
|
1171
1188
|
{ date_iso: { $lte: toDate } },
|
|
1172
1189
|
{ checkListType: { $eq: 'custom' } },
|
|
1190
|
+
// { store_id: { $in: requestData.storeId } },
|
|
1191
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
1173
1192
|
);
|
|
1174
1193
|
|
|
1175
1194
|
if ( requestData.checklistStatus && requestData.checklistStatus != 'All' ) {
|
|
@@ -1203,7 +1222,11 @@ export const checklistInfo = async ( req, res ) => {
|
|
|
1203
1222
|
findQuery.push( { $addFields: { store: { $toLower: '$storeName' } } } );
|
|
1204
1223
|
query = { store: { $in: storeList } };
|
|
1205
1224
|
} else {
|
|
1206
|
-
query = {
|
|
1225
|
+
query = { $or: [
|
|
1226
|
+
{ storeName: { $regex: requestData.searchValue.trim(), $options: 'i' } },
|
|
1227
|
+
{ userEmail: { $regex: requestData.searchValue.trim(), $options: 'i' } },
|
|
1228
|
+
{ userName: { $regex: requestData.searchValue.trim(), $options: 'i' } },
|
|
1229
|
+
] };
|
|
1207
1230
|
}
|
|
1208
1231
|
findQuery.push( { $match: { $or: [ query ] } } );
|
|
1209
1232
|
} else {
|
|
@@ -1219,33 +1242,72 @@ export const checklistInfo = async ( req, res ) => {
|
|
|
1219
1242
|
findQuery.push( { $match: { $or: [ query ] } } );
|
|
1220
1243
|
}
|
|
1221
1244
|
}
|
|
1245
|
+
findQuery.push( { $sort: { _id: -1 } } );
|
|
1246
|
+
|
|
1247
|
+
findQuery.push( {
|
|
1248
|
+
$group: {
|
|
1249
|
+
_id: { store: '$store_id', email: '$userEmail', checklistId: '$sourceCheckList_id' },
|
|
1250
|
+
checkListName: { $first: '$checkListName' },
|
|
1251
|
+
coverage: { $first: '$coverage' },
|
|
1252
|
+
createdByName: { $first: '$createdByName' },
|
|
1253
|
+
userName: { $first: '$userName' },
|
|
1254
|
+
userEmail: { $first: '$userEmail' },
|
|
1255
|
+
checklistStatus: { $last: '$checklistStatus' },
|
|
1256
|
+
submitTime_string: { $push: '$submitTime_string' },
|
|
1257
|
+
storeName: { $first: '$storeName' },
|
|
1258
|
+
checkListType: { $first: '$checkListType' },
|
|
1259
|
+
scheduleRepeatedType: { $first: '$scheduleRepeatedType' },
|
|
1260
|
+
timeFlag: { $sum: '$timeFlag' },
|
|
1261
|
+
questionFlag: { $sum: '$questionFlag' },
|
|
1262
|
+
date_iso: { $first: '$date_iso' },
|
|
1263
|
+
store_id: { $first: '$store_id' },
|
|
1264
|
+
date_string: { $first: '$date_string' },
|
|
1265
|
+
sourceCheckList_id: { $first: '$sourceCheckList_id' },
|
|
1266
|
+
reinitiateStatus: { $first: '$reinitiateStatus' },
|
|
1267
|
+
redoStatus: { $first: '$redoStatus' },
|
|
1268
|
+
submitCount: { $sum: {
|
|
1269
|
+
$cond: {
|
|
1270
|
+
if: { $eq: [ '$checklistStatus', 'submit' ] },
|
|
1271
|
+
then: 1,
|
|
1272
|
+
else: 0,
|
|
1273
|
+
},
|
|
1274
|
+
} },
|
|
1275
|
+
idList: { $push: '$_id' },
|
|
1276
|
+
},
|
|
1277
|
+
} );
|
|
1222
1278
|
|
|
1223
1279
|
findQuery.push( {
|
|
1224
1280
|
$project: {
|
|
1281
|
+
_id: 0,
|
|
1282
|
+
idList: 1,
|
|
1225
1283
|
checkListName: 1,
|
|
1284
|
+
coverage: 1,
|
|
1226
1285
|
createdByName: 1,
|
|
1227
1286
|
userName: 1,
|
|
1228
|
-
userEmail:
|
|
1287
|
+
userEmail: '$_id.email',
|
|
1229
1288
|
checklistStatus: 1,
|
|
1230
|
-
submitTime_string:
|
|
1289
|
+
submitTime_string: { $arrayElemAt: [ '$submitTime_string', 0 ] },
|
|
1231
1290
|
storeName: 1,
|
|
1232
1291
|
checkListType: 1,
|
|
1233
1292
|
scheduleRepeatedType: 1,
|
|
1234
1293
|
timeFlag: 1,
|
|
1235
1294
|
questionFlag: 1,
|
|
1236
1295
|
date_iso: 1,
|
|
1237
|
-
store_id:
|
|
1296
|
+
store_id: '$_id.store',
|
|
1238
1297
|
timeFlag: 1,
|
|
1239
1298
|
date_string: 1,
|
|
1240
1299
|
sourceCheckList_id: 1,
|
|
1241
1300
|
reinitiateStatus: 1,
|
|
1242
1301
|
redoStatus: 1,
|
|
1302
|
+
submitCount: 1,
|
|
1243
1303
|
},
|
|
1244
1304
|
} );
|
|
1245
1305
|
|
|
1246
1306
|
findQuery.push( {
|
|
1247
1307
|
$project: {
|
|
1308
|
+
idList: 1,
|
|
1248
1309
|
checkListName: 1,
|
|
1310
|
+
coverage: 1,
|
|
1249
1311
|
checkListChar: { $substr: [ '$checkListName', 0, 2 ] },
|
|
1250
1312
|
createdByName: 1,
|
|
1251
1313
|
userName: 1,
|
|
@@ -1285,30 +1347,83 @@ export const checklistInfo = async ( req, res ) => {
|
|
|
1285
1347
|
sourceCheckList_id: 1,
|
|
1286
1348
|
reinitiateStatus: 1,
|
|
1287
1349
|
redoStatus: 1,
|
|
1350
|
+
submitCount: 1,
|
|
1288
1351
|
},
|
|
1289
1352
|
} );
|
|
1290
1353
|
|
|
1291
|
-
let getTotalCount = await processedchecklistService.aggregate( findQuery );
|
|
1292
|
-
if ( !getTotalCount.length ) {
|
|
1293
|
-
|
|
1294
|
-
}
|
|
1354
|
+
// let getTotalCount = await processedchecklistService.aggregate( findQuery );
|
|
1355
|
+
// if ( !getTotalCount.length ) {
|
|
1356
|
+
// return res.sendError( { error: 'No Data Found' }, 204 );
|
|
1357
|
+
// }
|
|
1295
1358
|
|
|
1296
1359
|
if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
|
|
1297
1360
|
findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
|
|
1298
|
-
} else {
|
|
1299
|
-
findQuery.push( { $sort: { ['date_iso']: -1 } } );
|
|
1300
1361
|
}
|
|
1301
|
-
|
|
1302
1362
|
let limit = parseInt( requestData?.limit ) || 10;
|
|
1303
1363
|
let skip = limit * ( requestData?.offset ) || 0;
|
|
1304
|
-
|
|
1364
|
+
|
|
1365
|
+
findQuery.push(
|
|
1366
|
+
{
|
|
1367
|
+
$facet: {
|
|
1368
|
+
data: [
|
|
1369
|
+
{ $skip: skip }, { $limit: limit },
|
|
1370
|
+
],
|
|
1371
|
+
count: [
|
|
1372
|
+
{ $count: 'total' },
|
|
1373
|
+
],
|
|
1374
|
+
},
|
|
1375
|
+
},
|
|
1376
|
+
);
|
|
1377
|
+
|
|
1378
|
+
|
|
1305
1379
|
let getChecklistPerformanceData = await processedchecklistService.aggregate( findQuery );
|
|
1380
|
+
if ( !getChecklistPerformanceData[0].data.length ) {
|
|
1381
|
+
return res.sendError( 'No data found', 204 );
|
|
1382
|
+
}
|
|
1383
|
+
result = {
|
|
1384
|
+
totalCount: getChecklistPerformanceData?.[0]?.count?.[0]?.total || 0,
|
|
1385
|
+
checklistInfo: getChecklistPerformanceData?.[0]?.data || [],
|
|
1386
|
+
};
|
|
1306
1387
|
|
|
1307
|
-
result.
|
|
1308
|
-
|
|
1309
|
-
|
|
1388
|
+
result.checklistInfo.forEach( ( item ) => {
|
|
1389
|
+
item.date_string = dayjs( item.date_string, 'YYYY-MM-DD' ).format( 'DD MMM YYYY' );
|
|
1390
|
+
} );
|
|
1391
|
+
if ( requestData.export ) {
|
|
1392
|
+
const exportdata = [];
|
|
1393
|
+
result.checklistInfo.forEach( ( element ) => {
|
|
1394
|
+
if ( requestData.groupByType==='Checklist' ) {
|
|
1395
|
+
exportdata.push( {
|
|
1396
|
+
'Date': element.date_string || '--',
|
|
1397
|
+
'Store Name': element.storeName || '--',
|
|
1398
|
+
'Checklist Owner': element.userName || '--',
|
|
1399
|
+
'Submitted By': element.userName || '--',
|
|
1400
|
+
'Status': element.checklistStatus || '--',
|
|
1401
|
+
'Submitted On': element.submitTime_string || '--',
|
|
1402
|
+
'Flags': element.flaggedChecklist || '--',
|
|
1403
|
+
} );
|
|
1404
|
+
} else if ( requestData.groupByType==='Store' ) {
|
|
1405
|
+
exportdata.push( {
|
|
1406
|
+
'CheckList Name': element.checkListName || '--',
|
|
1407
|
+
'Checklist Owner': element.userName || '--',
|
|
1408
|
+
'Submitted By': element.userName || '--',
|
|
1409
|
+
'Status': element.checklistStatus || '--',
|
|
1410
|
+
'Submitted On': element.submitTime_string || '--',
|
|
1411
|
+
'Flags': element.flaggedChecklist || '--',
|
|
1412
|
+
} );
|
|
1413
|
+
} else {
|
|
1414
|
+
exportdata.push( {
|
|
1415
|
+
'Date': element.date_string || '--',
|
|
1416
|
+
'CheckList Name': element.checkListName || '--',
|
|
1417
|
+
'Store Name': element.storeName || '--',
|
|
1418
|
+
'Checklist Owner': element.userName || '--',
|
|
1419
|
+
'Status': element.checklistStatus || '--',
|
|
1420
|
+
'Submitted On': element.submitTime_string || '--',
|
|
1421
|
+
'Flags': element.flaggedChecklist || '--',
|
|
1422
|
+
} );
|
|
1423
|
+
}
|
|
1424
|
+
} );
|
|
1425
|
+
return await download( exportdata, res );
|
|
1310
1426
|
}
|
|
1311
|
-
result.checklistInfo = getChecklistPerformanceData;
|
|
1312
1427
|
return res.sendSuccess( result );
|
|
1313
1428
|
} catch ( error ) {
|
|
1314
1429
|
console.log( 'error =>', error );
|
|
@@ -1358,14 +1473,20 @@ export const infoCardsOld = async ( req, res ) => {
|
|
|
1358
1473
|
};
|
|
1359
1474
|
let result = {};
|
|
1360
1475
|
|
|
1476
|
+
// Get User Based Checklist //
|
|
1477
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
1478
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
1479
|
+
// End: Get User Based Checklist////
|
|
1480
|
+
|
|
1361
1481
|
let findQuery = [];
|
|
1362
1482
|
let findUniqueQuery = [];
|
|
1363
1483
|
let findAndQuery = [];
|
|
1364
1484
|
findAndQuery.push(
|
|
1365
1485
|
{ client_id: requestData.clientId },
|
|
1366
|
-
{ store_id: { $in: requestData.storeId } },
|
|
1367
1486
|
{ date_iso: { $gte: fromDate } },
|
|
1368
1487
|
{ date_iso: { $lte: toDate } },
|
|
1488
|
+
// { store_id: { $in: requestData.storeId } },
|
|
1489
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
1369
1490
|
);
|
|
1370
1491
|
|
|
1371
1492
|
if ( requestData.groupByType == 'checklist' ) {
|
|
@@ -1642,14 +1763,20 @@ export const flagDetectionCards = async ( req, res ) => {
|
|
|
1642
1763
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
1643
1764
|
let result = {};
|
|
1644
1765
|
|
|
1766
|
+
// Get User Based Checklist //
|
|
1767
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
1768
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
1769
|
+
// End: Get User Based Checklist////
|
|
1770
|
+
|
|
1645
1771
|
let findQuery = [];
|
|
1646
1772
|
let findAndQuery = [];
|
|
1647
1773
|
findAndQuery.push(
|
|
1648
1774
|
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
|
|
1649
1775
|
{ client_id: requestData.clientId },
|
|
1650
|
-
{ store_id: { $in: requestData.storeId } },
|
|
1651
1776
|
{ date_iso: { $gte: fromDate } },
|
|
1652
1777
|
{ date_iso: { $lte: toDate } },
|
|
1778
|
+
// { store_id: { $in: requestData.storeId } },
|
|
1779
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
1653
1780
|
);
|
|
1654
1781
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
1655
1782
|
|
|
@@ -1799,15 +1926,21 @@ export const flagDetectionTables = async ( req, res ) => {
|
|
|
1799
1926
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
1800
1927
|
let result = {};
|
|
1801
1928
|
|
|
1929
|
+
// Get User Based Checklist //
|
|
1930
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
1931
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
1932
|
+
// End: Get User Based Checklist////
|
|
1933
|
+
|
|
1802
1934
|
let findQuery = [];
|
|
1803
1935
|
let findAndQuery = [];
|
|
1804
1936
|
findAndQuery.push(
|
|
1805
1937
|
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
|
|
1806
1938
|
{ client_id: requestData.clientId },
|
|
1807
|
-
{ store_id: { $in: requestData.storeId } },
|
|
1808
1939
|
{ date_iso: { $gte: fromDate } },
|
|
1809
1940
|
{ date_iso: { $lte: toDate } },
|
|
1810
1941
|
{ checklistStatus: { $eq: 'submit' } },
|
|
1942
|
+
// { store_id: { $in: requestData.storeId } },
|
|
1943
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
1811
1944
|
);
|
|
1812
1945
|
|
|
1813
1946
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -2140,6 +2273,11 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
2140
2273
|
};
|
|
2141
2274
|
let result = {};
|
|
2142
2275
|
|
|
2276
|
+
// Get User Based Checklist //
|
|
2277
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
2278
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
2279
|
+
// End: Get User Based Checklist////
|
|
2280
|
+
|
|
2143
2281
|
let findQuery = [];
|
|
2144
2282
|
let findUniqueQuery = [];
|
|
2145
2283
|
let findAndQuery = [];
|
|
@@ -2147,7 +2285,8 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
2147
2285
|
{ checkListType: { $eq: 'custom' } },
|
|
2148
2286
|
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
2149
2287
|
{ client_id: requestData.clientId },
|
|
2150
|
-
{ store_id: { $in: requestData.storeId } },
|
|
2288
|
+
// { store_id: { $in: requestData.storeId } },
|
|
2289
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
2151
2290
|
);
|
|
2152
2291
|
|
|
2153
2292
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -2384,13 +2523,19 @@ export const overallComparisonCardsV1 = async ( req, res ) => {
|
|
|
2384
2523
|
'complianceRate': complianceRate,
|
|
2385
2524
|
};
|
|
2386
2525
|
|
|
2526
|
+
// Get User Based Checklist //
|
|
2527
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
2528
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
2529
|
+
// End: Get User Based Checklist////
|
|
2530
|
+
|
|
2387
2531
|
let rangeOneFindQuery = [];
|
|
2388
2532
|
let rangeOneFindAndQuery = [];
|
|
2389
2533
|
rangeOneFindAndQuery.push(
|
|
2390
2534
|
{ checkListType: { $eq: 'custom' } },
|
|
2391
2535
|
{ date_iso: { $gte: rangeOneFromDate, $lte: rangeOneToDate } },
|
|
2392
2536
|
{ client_id: requestData.clientId },
|
|
2393
|
-
{ store_id: { $in: requestData.storeId } },
|
|
2537
|
+
// { store_id: { $in: requestData.storeId } },
|
|
2538
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
2394
2539
|
);
|
|
2395
2540
|
|
|
2396
2541
|
rangeOneFindQuery.push( { $match: { $and: rangeOneFindAndQuery } } );
|
|
@@ -2487,7 +2632,8 @@ export const overallComparisonCardsV1 = async ( req, res ) => {
|
|
|
2487
2632
|
{ checkListType: { $eq: 'custom' } },
|
|
2488
2633
|
{ date_iso: { $gte: rangeTwoFromDate, $lte: rangeTwoToDate } },
|
|
2489
2634
|
{ client_id: requestData.clientId },
|
|
2490
|
-
{ store_id: { $in: requestData.storeId } },
|
|
2635
|
+
// { store_id: { $in: requestData.storeId } },
|
|
2636
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
2491
2637
|
);
|
|
2492
2638
|
|
|
2493
2639
|
rangeTwoFindQuery.push( { $match: { $and: rangeTwoFindAndQuery } } );
|
|
@@ -2625,15 +2771,21 @@ export const infoCardsV1 = async ( req, res ) => {
|
|
|
2625
2771
|
};
|
|
2626
2772
|
let result = {};
|
|
2627
2773
|
|
|
2774
|
+
// Get User Based Checklist //
|
|
2775
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
2776
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
2777
|
+
// End: Get User Based Checklist////
|
|
2778
|
+
|
|
2628
2779
|
let findQuery = [];
|
|
2629
2780
|
let findUniqueQuery = [];
|
|
2630
2781
|
let findAndQuery = [];
|
|
2631
2782
|
findAndQuery.push(
|
|
2632
2783
|
{ client_id: requestData.clientId },
|
|
2633
|
-
{ store_id: { $in: requestData.storeId } },
|
|
2634
2784
|
{ date_iso: { $gte: fromDate } },
|
|
2635
2785
|
{ date_iso: { $lte: toDate } },
|
|
2636
2786
|
{ checkListType: { $eq: 'custom' } },
|
|
2787
|
+
// { store_id: { $in: requestData.storeId } },
|
|
2788
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
2637
2789
|
);
|
|
2638
2790
|
|
|
2639
2791
|
if ( requestData.groupByType == 'Checklist' ) {
|
|
@@ -2903,14 +3055,20 @@ export const infoComparisonCardsV1 = async ( req, res ) => {
|
|
|
2903
3055
|
'complianceRate': complianceRate,
|
|
2904
3056
|
};
|
|
2905
3057
|
|
|
3058
|
+
// Get User Based Checklist //
|
|
3059
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
3060
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
3061
|
+
// End: Get User Based Checklist////
|
|
3062
|
+
|
|
2906
3063
|
let rangeOneFindQuery = [];
|
|
2907
3064
|
let rangeOneFindAndQuery = [];
|
|
2908
3065
|
rangeOneFindAndQuery.push(
|
|
2909
3066
|
{ client_id: requestData.clientId },
|
|
2910
|
-
{ store_id: { $in: requestData.storeId } },
|
|
2911
3067
|
{ date_iso: { $gte: rangeOneFromDate } },
|
|
2912
3068
|
{ date_iso: { $lte: rangeOneToDate } },
|
|
2913
3069
|
{ checkListType: { $eq: 'custom' } },
|
|
3070
|
+
// { store_id: { $in: requestData.storeId } },
|
|
3071
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
2914
3072
|
);
|
|
2915
3073
|
|
|
2916
3074
|
if ( requestData.groupByType == 'Checklist' ) {
|
|
@@ -3025,10 +3183,11 @@ export const infoComparisonCardsV1 = async ( req, res ) => {
|
|
|
3025
3183
|
let rangeTwoFindAndQuery = [];
|
|
3026
3184
|
rangeTwoFindAndQuery.push(
|
|
3027
3185
|
{ client_id: requestData.clientId },
|
|
3028
|
-
{ store_id: { $in: requestData.storeId } },
|
|
3029
3186
|
{ date_iso: { $gte: rangeTwoFromDate } },
|
|
3030
3187
|
{ date_iso: { $lte: rangeTwoToDate } },
|
|
3031
3188
|
{ checkListType: { $eq: 'custom' } },
|
|
3189
|
+
// { store_id: { $in: requestData.storeId } },
|
|
3190
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
3032
3191
|
);
|
|
3033
3192
|
if ( requestData.groupByType == 'Checklist' ) {
|
|
3034
3193
|
rangeTwoFindAndQuery.push( { sourceCheckList_id: new mongoose.Types.ObjectId( requestData.groupByValue ) } );
|
|
@@ -3213,14 +3372,21 @@ export const monthlyGraphV1 = async ( req, res ) => {
|
|
|
3213
3372
|
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
3214
3373
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
3215
3374
|
let result = {};
|
|
3375
|
+
|
|
3376
|
+
// Get User Based Checklist //
|
|
3377
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
3378
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
3379
|
+
// End: Get User Based Checklist////
|
|
3380
|
+
|
|
3216
3381
|
let findQuery = [];
|
|
3217
3382
|
let findAndQuery = [];
|
|
3218
3383
|
findAndQuery.push(
|
|
3219
3384
|
{ client_id: requestData.clientId },
|
|
3220
|
-
{ store_id: { $in: requestData.storeId } },
|
|
3221
3385
|
{ date_iso: { $gte: fromDate } },
|
|
3222
3386
|
{ date_iso: { $lte: toDate } },
|
|
3223
3387
|
{ checkListType: { $eq: 'custom' } },
|
|
3388
|
+
// { store_id: { $in: requestData.storeId } },
|
|
3389
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
3224
3390
|
);
|
|
3225
3391
|
|
|
3226
3392
|
if ( requestData.groupByType == 'Checklist' ) {
|
|
@@ -3449,23 +3615,32 @@ export const checklistDropdown = async ( req, res ) => {
|
|
|
3449
3615
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
3450
3616
|
let result = {};
|
|
3451
3617
|
|
|
3618
|
+
// Get User Based Checklist //
|
|
3619
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
3620
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
3621
|
+
// End: Get User Based Checklist////
|
|
3622
|
+
|
|
3452
3623
|
let findQuery = [
|
|
3453
3624
|
{ $match: { $and: [
|
|
3454
3625
|
{ client_id: requestData.clientId },
|
|
3455
|
-
{ store_id: { $in: requestData.storeId } },
|
|
3456
3626
|
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
3457
3627
|
{ checkListType: 'custom' },
|
|
3628
|
+
// { store_id: { $in: requestData.storeId } },
|
|
3629
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
3458
3630
|
] } },
|
|
3459
3631
|
{
|
|
3460
3632
|
$project: {
|
|
3461
3633
|
sourceCheckList_id: 1,
|
|
3462
3634
|
checkListName: 1,
|
|
3635
|
+
coverage: 1,
|
|
3463
3636
|
},
|
|
3464
3637
|
},
|
|
3465
3638
|
{
|
|
3466
3639
|
$group: {
|
|
3467
3640
|
_id: '$sourceCheckList_id',
|
|
3468
3641
|
checkListName: { $last: '$checkListName' },
|
|
3642
|
+
storeCount: { $sum: 1 },
|
|
3643
|
+
coverage: { $last: '$coverage' },
|
|
3469
3644
|
},
|
|
3470
3645
|
},
|
|
3471
3646
|
{
|
|
@@ -3473,6 +3648,8 @@ export const checklistDropdown = async ( req, res ) => {
|
|
|
3473
3648
|
_id: 0,
|
|
3474
3649
|
sourceCheckList_id: '$_id',
|
|
3475
3650
|
checkListName: 1,
|
|
3651
|
+
storeCount: 1,
|
|
3652
|
+
coverage: 1,
|
|
3476
3653
|
},
|
|
3477
3654
|
},
|
|
3478
3655
|
{
|
|
@@ -3501,7 +3678,7 @@ export const checklistDropdown = async ( req, res ) => {
|
|
|
3501
3678
|
scheduleRepeatedType: 1,
|
|
3502
3679
|
scheduleStartTime: 1,
|
|
3503
3680
|
sourceCheckList_id: '$_id',
|
|
3504
|
-
|
|
3681
|
+
allowedMultiSubmit: 1,
|
|
3505
3682
|
},
|
|
3506
3683
|
},
|
|
3507
3684
|
], as: 'checklistData',
|
|
@@ -3520,7 +3697,10 @@ export const checklistDropdown = async ( req, res ) => {
|
|
|
3520
3697
|
scheduleRepeatedType: '$checklistData.scheduleRepeatedType',
|
|
3521
3698
|
scheduleStartTime: '$checklistData.scheduleStartTime',
|
|
3522
3699
|
sourceCheckList_id: '$checklistData._id',
|
|
3523
|
-
storeCount:
|
|
3700
|
+
storeCount: 1,
|
|
3701
|
+
coverage: 1,
|
|
3702
|
+
allowedMultiSubmit: '$checklistData.allowedMultiSubmit',
|
|
3703
|
+
|
|
3524
3704
|
},
|
|
3525
3705
|
},
|
|
3526
3706
|
];
|
|
@@ -3641,3 +3821,68 @@ export async function sendAlert( req, res ) {
|
|
|
3641
3821
|
return res.sendError( e, 500 );
|
|
3642
3822
|
}
|
|
3643
3823
|
}
|
|
3824
|
+
|
|
3825
|
+
export async function getUserEmails( req, res ) {
|
|
3826
|
+
try {
|
|
3827
|
+
let requestData = req.body;
|
|
3828
|
+
// Get User Based Checklist //
|
|
3829
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
3830
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
3831
|
+
// End: Get User Based Checklist////
|
|
3832
|
+
if ( !getUserEmails.length ) {
|
|
3833
|
+
return res.sendError( { error: 'No Users Found' }, 204 );
|
|
3834
|
+
} else {
|
|
3835
|
+
return res.sendSuccess( { userEmailData: getUserEmails } );
|
|
3836
|
+
}
|
|
3837
|
+
} catch ( e ) {
|
|
3838
|
+
logger.error( { function: 'getUserEmails', error: e, message: req.body } );
|
|
3839
|
+
return res.sendError( e, 500 );
|
|
3840
|
+
}
|
|
3841
|
+
}
|
|
3842
|
+
|
|
3843
|
+
// async function getChecklistUsers( loginUser ) {
|
|
3844
|
+
// try {
|
|
3845
|
+
// // userType, role, clientId, userEmail All Key Required Fields
|
|
3846
|
+
// if ( loginUser.userType == 'tango' || loginUser.role == 'superadmin' ) {
|
|
3847
|
+
// // //return All users Emails
|
|
3848
|
+
// const userQuery = [
|
|
3849
|
+
// { $match: { isActive: true, clientId: loginUser.clientId } },
|
|
3850
|
+
// { $group: { _id: '$clientId', email: { $push: '$email' } } },
|
|
3851
|
+
// { $project: { email: 1, _id: 0 } },
|
|
3852
|
+
// ];
|
|
3853
|
+
// let getUsersData = await userService.aggregate( userQuery );
|
|
3854
|
+
// if ( getUsersData.length > 0 ) {
|
|
3855
|
+
// let getUsers = getUsersData[0].email;
|
|
3856
|
+
// if ( loginUser.userType == 'client' ) {
|
|
3857
|
+
// getUsers.push( loginUser.userEmail );
|
|
3858
|
+
// }
|
|
3859
|
+
// return getUsers;
|
|
3860
|
+
// } else {
|
|
3861
|
+
// if ( loginUser.userType == 'client' ) {
|
|
3862
|
+
// return [ loginUser.userEmail ];
|
|
3863
|
+
// } else {
|
|
3864
|
+
// return [ ];
|
|
3865
|
+
// }
|
|
3866
|
+
// }
|
|
3867
|
+
// } else if ( loginUser.role == 'admin' || loginUser.role == 'user' ) {
|
|
3868
|
+
// // //return Find Teams and Get Users
|
|
3869
|
+
// let findTeamsMembersQuery = [
|
|
3870
|
+
// { $match: { clientId: loginUser.clientId, Teamlead: { $elemMatch: { email: loginUser.userEmail } } } },
|
|
3871
|
+
// { $unwind: '$users' },
|
|
3872
|
+
// { $group: { _id: null, emails: { $push: '$users.email' } } },
|
|
3873
|
+
// { $project: { _id: 0, emails: 1 } },
|
|
3874
|
+
// ];
|
|
3875
|
+
// let getUsers = await findteams.aggregateTeams( findTeamsMembersQuery );
|
|
3876
|
+
// if ( getUsers.length > 0 ) {
|
|
3877
|
+
// getUsers[0].emails.push( loginUser.userEmail );
|
|
3878
|
+
// return getUsers[0].emails;
|
|
3879
|
+
// } else {
|
|
3880
|
+
// return [ loginUser.userEmail ];
|
|
3881
|
+
// }
|
|
3882
|
+
// }
|
|
3883
|
+
// } catch ( error ) {
|
|
3884
|
+
// console.log( 'error getChecklistUsers=>', error );
|
|
3885
|
+
// logger.error( { error: error, function: 'getChecklistUsers' } );
|
|
3886
|
+
// return [ ];
|
|
3887
|
+
// }
|
|
3888
|
+
// }
|