tango-app-api-trax 3.2.1 → 3.3.1-airtalai-0
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 +155 -17
- package/src/controllers/gallery.controller.js +124 -31
- package/src/controllers/internalTrax.controller.js +339 -8
- package/src/controllers/mobileTrax.controller.js +200 -40
- package/src/controllers/teaxFlag.controller.js +161 -142
- package/src/controllers/trax.controller.js +1844 -319
- package/src/controllers/traxDashboard.controllers.js +350 -105
- package/src/dtos/dashboardValidation.dtos.js +2 -0
- package/src/dtos/downloadValidation.dtos.js +3 -1
- package/src/dtos/validation.dtos.js +17 -5
- package/src/hbs/login-otp.hbs +943 -943
- package/src/routes/download.router.js +4 -0
- package/src/routes/gallery.routes.js +5 -1
- package/src/routes/internalTraxApi.router.js +4 -1
- package/src/routes/mobileTrax.routes.js +3 -1
- package/src/routes/trax.routes.js +14 -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/processedchecklistconfig.services.js +1 -1
- package/src/services/teams.service.js +30 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { download, logger } from 'tango-app-api-middleware';
|
|
1
|
+
import { download, logger } from 'tango-app-api-middleware'; // getChecklistUsers
|
|
2
2
|
import { aggregate } from '../services/processedchecklist.services.js';
|
|
3
3
|
import dayjs from 'dayjs';
|
|
4
4
|
import * as processedchecklistService from '../services/processedchecklist.services.js';
|
|
@@ -12,6 +12,11 @@ import mongoose from 'mongoose';
|
|
|
12
12
|
|
|
13
13
|
export const overallFlagMetrics = async ( req, res ) => {
|
|
14
14
|
try {
|
|
15
|
+
let requestData = req.body;
|
|
16
|
+
// Get User Based Checklist //
|
|
17
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
18
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
19
|
+
// End: Get User Based Checklist////
|
|
15
20
|
const pipeline = [
|
|
16
21
|
{
|
|
17
22
|
$facet: {
|
|
@@ -20,21 +25,10 @@ export const overallFlagMetrics = async ( req, res ) => {
|
|
|
20
25
|
$match: {
|
|
21
26
|
$and: [
|
|
22
27
|
{ client_id: req.body.clientId },
|
|
23
|
-
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
date_iso: {
|
|
30
|
-
$gte: new Date( req.body.startDate ),
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
date_iso: {
|
|
35
|
-
$lte: new Date( req.body.endDate ),
|
|
36
|
-
},
|
|
37
|
-
},
|
|
28
|
+
{ date_iso: { $gte: new Date( req.body.startDate ) } },
|
|
29
|
+
{ date_iso: { $lte: new Date( req.body.endDate ) } },
|
|
30
|
+
// { store_id: { $in: req.body.stores } },
|
|
31
|
+
{ $or: [ { store_id: { $in: req.body.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
38
32
|
],
|
|
39
33
|
},
|
|
40
34
|
},
|
|
@@ -108,21 +102,10 @@ export const overallFlagMetrics = async ( req, res ) => {
|
|
|
108
102
|
$match: {
|
|
109
103
|
$and: [
|
|
110
104
|
{ client_id: req.body.clientId },
|
|
111
|
-
{
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
date_iso: {
|
|
118
|
-
$gte: dayjs.utc( req.body.endDate ).subtract( 7, 'days' ).startOf( 'day' ).toDate(),
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
date_iso: {
|
|
123
|
-
$lte: dayjs.utc( req.body.startDate ).subtract( 1, 'day' ).startOf( 'day' ).toDate(),
|
|
124
|
-
},
|
|
125
|
-
},
|
|
105
|
+
{ date_iso: { $gte: dayjs.utc( req.body.endDate ).subtract( 7, 'days' ).startOf( 'day' ).toDate() } },
|
|
106
|
+
{ date_iso: { $lte: dayjs.utc( req.body.startDate ).subtract( 1, 'day' ).startOf( 'day' ).toDate() } },
|
|
107
|
+
// { store_id: { $in: req.body.stores } },
|
|
108
|
+
{ $or: [ { store_id: { $in: req.body.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
126
109
|
],
|
|
127
110
|
},
|
|
128
111
|
},
|
|
@@ -271,34 +254,26 @@ export const overallFlagMetrics = async ( req, res ) => {
|
|
|
271
254
|
|
|
272
255
|
export const checklistFlagsTable = async ( req, res ) => {
|
|
273
256
|
try {
|
|
257
|
+
let requestData = req.body;
|
|
258
|
+
// Get User Based Checklist //
|
|
259
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
260
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
261
|
+
// End: Get User Based Checklist////
|
|
274
262
|
const matchStage = {
|
|
275
263
|
$match: {
|
|
276
264
|
$and: [
|
|
277
265
|
{ client_id: req.body.clientId },
|
|
278
|
-
{
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
},
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
date_iso: {
|
|
290
|
-
$lte: new Date( req.body.endDate ),
|
|
291
|
-
},
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
$or: [
|
|
295
|
-
{ timeFlag: { $gt: 0 } },
|
|
296
|
-
{ questionFlag: { $gt: 0 } },
|
|
297
|
-
{ mobileDetectionFlag: { $gt: 0 } },
|
|
298
|
-
{ storeOpenCloseFlag: { $gt: 0 } },
|
|
299
|
-
{ uniformDetectionFlag: { $gt: 0 } },
|
|
300
|
-
],
|
|
301
|
-
},
|
|
266
|
+
{ date_iso: { $gte: new Date( req.body.startDate ) } },
|
|
267
|
+
{ date_iso: { $lte: new Date( req.body.endDate ) } },
|
|
268
|
+
{ $or: [
|
|
269
|
+
{ timeFlag: { $gt: 0 } },
|
|
270
|
+
{ questionFlag: { $gt: 0 } },
|
|
271
|
+
{ mobileDetectionFlag: { $gt: 0 } },
|
|
272
|
+
{ storeOpenCloseFlag: { $gt: 0 } },
|
|
273
|
+
{ uniformDetectionFlag: { $gt: 0 } },
|
|
274
|
+
] },
|
|
275
|
+
// { store_id: { $in: req.body.stores } },
|
|
276
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
302
277
|
],
|
|
303
278
|
},
|
|
304
279
|
};
|
|
@@ -560,12 +535,18 @@ export const flagCardsV1 = async ( req, res ) => {
|
|
|
560
535
|
detectionFlag: { count: 0 },
|
|
561
536
|
};
|
|
562
537
|
|
|
538
|
+
let requestData = req.body;
|
|
539
|
+
// Get User Based Checklist //
|
|
540
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
541
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
542
|
+
// End: Get User Based Checklist////
|
|
563
543
|
const findQuery = [
|
|
564
544
|
{
|
|
565
545
|
$match: {
|
|
566
546
|
client_id: clientId,
|
|
567
|
-
store_id: { $in: storeId },
|
|
547
|
+
// $or: [ { store_id: { $in: storeId } }, { aiStoreList: { $in: storeId } } ],
|
|
568
548
|
date_iso: { $gte: adjustedFromDate, $lte: adjustedToDate },
|
|
549
|
+
$or: [ { store_id: { $in: storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } }, { aiStoreList: { $in: storeId } } ],
|
|
569
550
|
},
|
|
570
551
|
},
|
|
571
552
|
{
|
|
@@ -613,7 +594,7 @@ export const flagCardsV1 = async ( req, res ) => {
|
|
|
613
594
|
{
|
|
614
595
|
client_id: clientId,
|
|
615
596
|
publish: true,
|
|
616
|
-
checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection' ] },
|
|
597
|
+
checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum' ] },
|
|
617
598
|
},
|
|
618
599
|
{ checkListType: 1 },
|
|
619
600
|
);
|
|
@@ -634,7 +615,7 @@ export const flagCardsV1 = async ( req, res ) => {
|
|
|
634
615
|
flagCards.detectionFlag.count += resultData[item];
|
|
635
616
|
}
|
|
636
617
|
} );
|
|
637
|
-
flagCards.totalFlag
|
|
618
|
+
flagCards.totalFlag += flagCards.detectionFlag.count;
|
|
638
619
|
}
|
|
639
620
|
|
|
640
621
|
return res.sendSuccess( { flagCards } );
|
|
@@ -696,8 +677,16 @@ export const flagComparisonCardsV1 = async ( req, res ) => {
|
|
|
696
677
|
rangeTwoToDate.setUTCHours( 23, 59, 59, 59 );
|
|
697
678
|
}
|
|
698
679
|
|
|
680
|
+
// Get User Based Checklist //
|
|
681
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
682
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
683
|
+
// End: Get User Based Checklist////
|
|
699
684
|
const createFindQuery = ( fromDate, toDate ) => [
|
|
700
|
-
{ $match: { client_id: requestData.clientId,
|
|
685
|
+
{ $match: { client_id: requestData.clientId,
|
|
686
|
+
// $or: [ { store_id: { $in: requestData.storeId } }, { aiStoreList: { $in: requestData.storeId } } ],
|
|
687
|
+
date_iso: { $gte: fromDate, $lte: toDate },
|
|
688
|
+
$or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } }, { aiStoreList: { $in: requestData.storeId } } ],
|
|
689
|
+
} },
|
|
701
690
|
{
|
|
702
691
|
$project: {
|
|
703
692
|
timeFlag: 1,
|
|
@@ -721,12 +710,8 @@ export const flagComparisonCardsV1 = async ( req, res ) => {
|
|
|
721
710
|
let comparisonData = Math.abs( ( ( rangeOneVal - rangeTwoVal ) / rangeTwoVal ) * 100 );
|
|
722
711
|
if ( comparisonData === Infinity ) comparisonData = 0;
|
|
723
712
|
comparisonData = comparisonData % 1 === 0 ? comparisonData.toFixed( 0 ) : comparisonData.toFixed( 1 );
|
|
724
|
-
|
|
725
713
|
comparisonData = parseInt( comparisonData );
|
|
726
|
-
|
|
727
|
-
|
|
728
714
|
const ComparisonFlag = rangeOneVal > rangeTwoVal;
|
|
729
|
-
|
|
730
715
|
return { comparisonData, ComparisonFlag };
|
|
731
716
|
};
|
|
732
717
|
|
|
@@ -738,19 +723,16 @@ export const flagComparisonCardsV1 = async ( req, res ) => {
|
|
|
738
723
|
clientId: requestData.clientId,
|
|
739
724
|
};
|
|
740
725
|
|
|
741
|
-
console.log( dayjs( fromDate ).format( 'YYYY-MM-DD' ), 'from date' );
|
|
742
|
-
|
|
743
|
-
console.log( dayjs( toDate ).
|
|
744
|
-
|
|
745
|
-
console.log( dayjs( toDate ).format( 'YYYY-MM-DD' ), 'previous' );
|
|
746
|
-
|
|
747
|
-
console.log( dayjs( toDate ).startOf( 'day' ).subtract( 1, 'day' ).format( 'YYYY-MM-DD' ), 'new start of' );
|
|
726
|
+
// console.log( dayjs( fromDate ).format( 'YYYY-MM-DD' ), 'from date' );
|
|
727
|
+
// console.log( dayjs( toDate ).subtract( 1, 'day' ).format( 'YYYY-MM-DD' ), 'current' );
|
|
728
|
+
// console.log( dayjs( toDate ).format( 'YYYY-MM-DD' ), 'previous' );
|
|
729
|
+
// console.log( dayjs( toDate ).startOf( 'day' ).subtract( 1, 'day' ).format( 'YYYY-MM-DD' ), 'new start of' );
|
|
748
730
|
|
|
749
731
|
const publishedAiChecklists = await checklistconfigService.find(
|
|
750
732
|
{
|
|
751
733
|
client_id: requestData.clientId,
|
|
752
734
|
publish: true,
|
|
753
|
-
checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection' ] },
|
|
735
|
+
checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum' ] },
|
|
754
736
|
},
|
|
755
737
|
{ checkListType: 1 },
|
|
756
738
|
);
|
|
@@ -760,9 +742,7 @@ export const flagComparisonCardsV1 = async ( req, res ) => {
|
|
|
760
742
|
|
|
761
743
|
const LamdaURL = 'https://f65azvtljclaxp6l7rnx65cdmm0lcgvp.lambda-url.ap-south-1.on.aws/';
|
|
762
744
|
const resultData = await LamdaServiceCall( LamdaURL, detectionPayload );
|
|
763
|
-
|
|
764
745
|
const published = publishedAiChecklists.map( ( val ) => val?.checkListType );
|
|
765
|
-
|
|
766
746
|
if ( resultData?.status_code === '200' ) {
|
|
767
747
|
let result = 0;
|
|
768
748
|
published.forEach( ( item ) => {
|
|
@@ -813,17 +793,23 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
813
793
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
814
794
|
let result = {};
|
|
815
795
|
|
|
796
|
+
// Get User Based Checklist //
|
|
797
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
798
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
799
|
+
// End: Get User Based Checklist////
|
|
800
|
+
|
|
816
801
|
let findQuery = [];
|
|
817
802
|
let findAndQuery = [];
|
|
818
803
|
findAndQuery.push(
|
|
819
804
|
{ client_id: requestData.clientId },
|
|
820
|
-
{ $or: [ { store_id: { $in: requestData.storeId } }, { aiStoreList: { $in: requestData.storeId } } ] },
|
|
821
|
-
{ date_iso: { $gte: fromDate } },
|
|
822
|
-
{
|
|
805
|
+
// { $or: [ { store_id: { $in: requestData.storeId } }, { aiStoreList: { $in: requestData.storeId } } ] },
|
|
806
|
+
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
807
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } }, { aiStoreList: { $in: requestData.storeId } } ] },
|
|
823
808
|
);
|
|
824
809
|
|
|
825
810
|
if ( requestData?.filter === 'all' ) {
|
|
826
|
-
findAndQuery.push( { $or: [ { questionFlag: { $gte: 1 } }, { timeFlag: { $gte: 1 } }, { checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection' ] } } ] } );
|
|
811
|
+
// findAndQuery.push( { $or: [ { questionFlag: { $gte: 1 } }, { timeFlag: { $gte: 1 } }, { checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection' ] } } ] } );
|
|
812
|
+
findAndQuery.push( { $or: [ { checkListType: { $in: [ 'custom', 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum' ] } } ] } );
|
|
827
813
|
} else if ( requestData?.filter === 'question' ) {
|
|
828
814
|
findAndQuery.push( { checkListType: 'custom' } );
|
|
829
815
|
findAndQuery.push( { questionFlag: { $gte: 1 } } );
|
|
@@ -831,7 +817,7 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
831
817
|
findAndQuery.push( { checkListType: 'custom' } );
|
|
832
818
|
findAndQuery.push( { timeFlag: { $gte: 1 } } );
|
|
833
819
|
} else if ( requestData?.filter === 'detection' ) {
|
|
834
|
-
findAndQuery.push( { checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection' ] } } );
|
|
820
|
+
findAndQuery.push( { checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum' ] } } );
|
|
835
821
|
}
|
|
836
822
|
|
|
837
823
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -845,6 +831,7 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
845
831
|
sourceCheckList_id: 1,
|
|
846
832
|
checkListId: 1,
|
|
847
833
|
checkListName: 1,
|
|
834
|
+
coverage: 1,
|
|
848
835
|
storeCount: 1,
|
|
849
836
|
createdBy: 1,
|
|
850
837
|
createdByName: 1,
|
|
@@ -867,29 +854,47 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
867
854
|
_id: '$sourceCheckList_id',
|
|
868
855
|
checkListName: { $last: '$checkListName' },
|
|
869
856
|
checkListChar: { $last: { $substr: [ '$checkListName', 0, 2 ] } },
|
|
857
|
+
coverage: { $last: '$coverage' },
|
|
870
858
|
sourceCheckList_id: { $last: '$sourceCheckList_id' },
|
|
871
859
|
checkListType: { $last: '$checkListType' },
|
|
872
860
|
storeCount: { $sum: 1 },
|
|
873
861
|
storeCountAi: { $max: '$storeCount' },
|
|
874
|
-
flaggedStores: {
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
862
|
+
// flaggedStores: {
|
|
863
|
+
// $addToSet: {
|
|
864
|
+
// $cond: [
|
|
865
|
+
// {
|
|
866
|
+
// $or: [
|
|
867
|
+
// { $gt: [ '$timeFlag', 0 ] },
|
|
868
|
+
// { $gt: [ '$questionFlag', 0 ] },
|
|
869
|
+
// { $gt: [ '$mobileDetectionFlag', 0 ] },
|
|
870
|
+
// { $gt: [ '$storeOpenCloseFlag', 0 ] },
|
|
871
|
+
// { $gt: [ '$uniformDetectionFlag', 0 ] },
|
|
872
|
+
// { $gt: [ '$customerUnattended', 0 ] },
|
|
873
|
+
// { $gt: [ '$staffLeftInTheMiddle', 0 ] },
|
|
874
|
+
// ],
|
|
875
|
+
// },
|
|
876
|
+
// '$store_id',
|
|
877
|
+
// '$$REMOVE',
|
|
878
|
+
// ],
|
|
879
|
+
// },
|
|
880
|
+
// },
|
|
881
|
+
flaggedStores: { $sum: { $cond: [
|
|
882
|
+
{
|
|
883
|
+
$or: [
|
|
884
|
+
{ '$gt': [ '$timeFlag', 0 ] },
|
|
885
|
+
{ '$gt': [ '$questionFlag', 0 ] },
|
|
886
|
+
{ '$gt': [ '$mobileDetectionFlag', 0 ] },
|
|
887
|
+
{ '$gt': [ '$storeOpenCloseFlag', 0 ] },
|
|
888
|
+
{ '$gt': [ '$uniformDetectionFlag', 0 ] },
|
|
889
|
+
{ '$gt': [ '$customerUnattended', 0 ] },
|
|
890
|
+
{ '$gt': [ '$staffLeftInTheMiddle', 0 ] },
|
|
891
|
+
{ '$gt': [ '$cleaning', 0 ] },
|
|
892
|
+
{ '$gt': [ '$scrum', 0 ] },
|
|
890
893
|
],
|
|
891
894
|
},
|
|
892
|
-
|
|
895
|
+
1,
|
|
896
|
+
0,
|
|
897
|
+
] } },
|
|
893
898
|
flagCount: {
|
|
894
899
|
$sum: {
|
|
895
900
|
$add: [ '$questionFlag', '$timeFlag' ],
|
|
@@ -927,6 +932,7 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
927
932
|
// },
|
|
928
933
|
},
|
|
929
934
|
aiStoreList: { $max: '$aiStoreList' },
|
|
935
|
+
aiStoreListNew: { $sum: { $size: '$aiStoreList' } },
|
|
930
936
|
submittedQuestionCount: {
|
|
931
937
|
$sum: {
|
|
932
938
|
$cond: [
|
|
@@ -942,14 +948,16 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
942
948
|
findQuery.push( {
|
|
943
949
|
$project: {
|
|
944
950
|
assignedStores: '$storeCount',
|
|
945
|
-
assignedStoresAi: '$
|
|
951
|
+
assignedStoresAi: '$aiStoreListNew',
|
|
946
952
|
checkListName: 1,
|
|
953
|
+
coverage: 1,
|
|
947
954
|
checkListChar: 1,
|
|
948
955
|
sourceCheckList_id: 1,
|
|
949
956
|
checkListType: 1,
|
|
950
957
|
flagType: 1,
|
|
951
958
|
uniqueFlaggedStores: 1,
|
|
952
|
-
flaggedStores: { $size: '$flaggedStores' },
|
|
959
|
+
// flaggedStores: { $size: '$flaggedStores' },
|
|
960
|
+
flaggedStores: '$flaggedStores',
|
|
953
961
|
flagCount: 1,
|
|
954
962
|
questionCount: 1,
|
|
955
963
|
correctAnswers: { $subtract: [ '$submittedQuestionCount', '$questionFlag' ] },
|
|
@@ -970,6 +978,12 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
970
978
|
$project: {
|
|
971
979
|
checkListName: 1,
|
|
972
980
|
checkListChar: 1,
|
|
981
|
+
coverage: {
|
|
982
|
+
$concat: [
|
|
983
|
+
{ $toUpper: { $substr: [ { $ifNull: [ '$coverage', '' ] }, 0, 1 ] } },
|
|
984
|
+
{ $substr: [ { $ifNull: [ '$coverage', '' ] }, 1, { $strLenCP: { $ifNull: [ '$coverage', '' ] } } ] },
|
|
985
|
+
],
|
|
986
|
+
},
|
|
973
987
|
sourceCheckList_id: 1,
|
|
974
988
|
checkListType: 1,
|
|
975
989
|
flagType: 1,
|
|
@@ -1831,7 +1845,6 @@ async function checklistDropdownData( checklistType ) {
|
|
|
1831
1845
|
}
|
|
1832
1846
|
}
|
|
1833
1847
|
|
|
1834
|
-
|
|
1835
1848
|
// Lamda Service Call //
|
|
1836
1849
|
async function LamdaServiceCall( url, data ) {
|
|
1837
1850
|
try {
|
|
@@ -1858,6 +1871,10 @@ async function LamdaServiceCall( url, data ) {
|
|
|
1858
1871
|
export const flagChecklistCardsV1 = async ( req, res ) => {
|
|
1859
1872
|
try {
|
|
1860
1873
|
let reqestData = req.body;
|
|
1874
|
+
// Get User Based Checklist //
|
|
1875
|
+
// let loginUser = { clientId: reqestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
1876
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
1877
|
+
// End: Get User Based Checklist////
|
|
1861
1878
|
|
|
1862
1879
|
if ( reqestData.ChecklistType == 'custom' ) {
|
|
1863
1880
|
const pipeline = [
|
|
@@ -1865,10 +1882,11 @@ export const flagChecklistCardsV1 = async ( req, res ) => {
|
|
|
1865
1882
|
$match: {
|
|
1866
1883
|
$and: [
|
|
1867
1884
|
{ client_id: reqestData?.clientId },
|
|
1868
|
-
{ store_id: { $in: reqestData?.storeId } },
|
|
1869
1885
|
{ date_iso: { $gte: new Date( reqestData?.fromDate ) } },
|
|
1870
1886
|
{ date_iso: { $lte: dayjs.utc( reqestData.toDate ).endOf( 'day' ).toDate() } },
|
|
1871
1887
|
{ sourceCheckList_id: new mongoose.Types.ObjectId( reqestData.sourceCheckList_id ) },
|
|
1888
|
+
// { store_id: { $in: reqestData?.storeId } },
|
|
1889
|
+
{ $or: [ { store_id: { $in: reqestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: reqestData.userEmailes } } ] },
|
|
1872
1890
|
],
|
|
1873
1891
|
},
|
|
1874
1892
|
},
|
|
@@ -1967,18 +1985,12 @@ export const flagChecklistCardsV1 = async ( req, res ) => {
|
|
|
1967
1985
|
const pipeline = [
|
|
1968
1986
|
{
|
|
1969
1987
|
$match:
|
|
1970
|
-
{
|
|
1971
|
-
date_iso: {
|
|
1972
|
-
$gte: new Date( reqestData.fromDate ),
|
|
1973
|
-
},
|
|
1974
|
-
date_iso: {
|
|
1975
|
-
$lte: dayjs.utc( reqestData.toDate ).endOf( 'day' ).toDate(),
|
|
1976
|
-
},
|
|
1977
|
-
store_id: {
|
|
1978
|
-
$in: reqestData.storeId,
|
|
1979
|
-
},
|
|
1988
|
+
{ date_iso: { $gte: new Date( reqestData.fromDate ) },
|
|
1989
|
+
date_iso: { $lte: dayjs.utc( reqestData.toDate ).endOf( 'day' ).toDate() },
|
|
1980
1990
|
client_id: reqestData.clientId,
|
|
1981
1991
|
sourceCheckList_id: new mongoose.Types.ObjectId( reqestData.sourceCheckList_id ),
|
|
1992
|
+
// store_id: { $in: reqestData.storeId },
|
|
1993
|
+
$or: [ { store_id: { $in: reqestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: reqestData.userEmailes } } ],
|
|
1982
1994
|
},
|
|
1983
1995
|
},
|
|
1984
1996
|
{
|
|
@@ -2080,6 +2092,10 @@ export const flagChecklistComparisonCardsV1 = async ( req, res ) => {
|
|
|
2080
2092
|
},
|
|
2081
2093
|
};
|
|
2082
2094
|
|
|
2095
|
+
// Get User Based Checklist //
|
|
2096
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
2097
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
2098
|
+
// End: Get User Based Checklist////
|
|
2083
2099
|
|
|
2084
2100
|
if ( requestData.ChecklistType == 'custom' ) {
|
|
2085
2101
|
const range1pipeline = [
|
|
@@ -2087,10 +2103,11 @@ export const flagChecklistComparisonCardsV1 = async ( req, res ) => {
|
|
|
2087
2103
|
$match: {
|
|
2088
2104
|
$and: [
|
|
2089
2105
|
{ client_id: requestData?.clientId },
|
|
2090
|
-
{ store_id: { $in: requestData?.storeId } },
|
|
2091
2106
|
{ date_iso: { $gte: rangeOneFromDate } },
|
|
2092
2107
|
{ date_iso: { $lte: rangeOneToDate } },
|
|
2093
2108
|
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
|
|
2109
|
+
// { store_id: { $in: requestData?.storeId } },
|
|
2110
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
2094
2111
|
],
|
|
2095
2112
|
},
|
|
2096
2113
|
},
|
|
@@ -2168,10 +2185,11 @@ export const flagChecklistComparisonCardsV1 = async ( req, res ) => {
|
|
|
2168
2185
|
$match: {
|
|
2169
2186
|
$and: [
|
|
2170
2187
|
{ client_id: requestData?.clientId },
|
|
2171
|
-
{ store_id: { $in: requestData?.storeId } },
|
|
2172
2188
|
{ date_iso: { $gte: rangeTwoFromDate } },
|
|
2173
2189
|
{ date_iso: { $lte: rangeTwoToDate } },
|
|
2174
2190
|
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
|
|
2191
|
+
// { store_id: { $in: requestData?.storeId } },
|
|
2192
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ] },
|
|
2175
2193
|
],
|
|
2176
2194
|
},
|
|
2177
2195
|
},
|
|
@@ -2280,18 +2298,12 @@ export const flagChecklistComparisonCardsV1 = async ( req, res ) => {
|
|
|
2280
2298
|
const fromPipeline = [
|
|
2281
2299
|
{
|
|
2282
2300
|
$match:
|
|
2283
|
-
{
|
|
2284
|
-
date_iso: {
|
|
2285
|
-
$gte: rangeOneFromDate,
|
|
2286
|
-
},
|
|
2287
|
-
date_iso: {
|
|
2288
|
-
$lte: rangeOneToDate,
|
|
2289
|
-
},
|
|
2290
|
-
store_id: {
|
|
2291
|
-
$in: requestData.storeId,
|
|
2292
|
-
},
|
|
2301
|
+
{ date_iso: { $gte: rangeOneFromDate },
|
|
2302
|
+
date_iso: { $lte: rangeOneToDate },
|
|
2293
2303
|
client_id: requestData.clientId,
|
|
2294
2304
|
sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ),
|
|
2305
|
+
// store_id: { $in: requestData.storeId },
|
|
2306
|
+
$or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ],
|
|
2295
2307
|
},
|
|
2296
2308
|
},
|
|
2297
2309
|
{
|
|
@@ -2312,18 +2324,12 @@ export const flagChecklistComparisonCardsV1 = async ( req, res ) => {
|
|
|
2312
2324
|
const toPipeline = [
|
|
2313
2325
|
{
|
|
2314
2326
|
$match:
|
|
2315
|
-
{
|
|
2316
|
-
date_iso: {
|
|
2317
|
-
$gte: rangeTwoFromDate,
|
|
2318
|
-
},
|
|
2319
|
-
date_iso: {
|
|
2320
|
-
$lte: rangeTwoToDate,
|
|
2321
|
-
},
|
|
2322
|
-
store_id: {
|
|
2323
|
-
$in: requestData.storeId,
|
|
2324
|
-
},
|
|
2327
|
+
{ date_iso: { $gte: rangeTwoFromDate },
|
|
2328
|
+
date_iso: { $lte: rangeTwoToDate },
|
|
2325
2329
|
client_id: requestData.clientId,
|
|
2326
2330
|
sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ),
|
|
2331
|
+
// store_id: { $in: requestData.storeId },
|
|
2332
|
+
$or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } } ],
|
|
2327
2333
|
},
|
|
2328
2334
|
},
|
|
2329
2335
|
{
|
|
@@ -2366,12 +2372,15 @@ export const flagChecklistComparisonCardsV1 = async ( req, res ) => {
|
|
|
2366
2372
|
export const flagChecklistTableV1 = async ( req, res ) => {
|
|
2367
2373
|
try {
|
|
2368
2374
|
let reqestData = req.body;
|
|
2375
|
+
// Get User Based Checklist //
|
|
2376
|
+
// let loginUser = { clientId: reqestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
2377
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
2378
|
+
// End: Get User Based Checklist////
|
|
2369
2379
|
if ( reqestData.ChecklistType == 'custom' ) {
|
|
2370
2380
|
const match = {
|
|
2371
2381
|
$match: {
|
|
2372
2382
|
$and: [
|
|
2373
2383
|
{ client_id: reqestData?.clientId },
|
|
2374
|
-
{ store_id: { $in: reqestData?.storeId } },
|
|
2375
2384
|
{ date_iso: { $gte: new Date( reqestData?.fromDate ) } },
|
|
2376
2385
|
{ date_iso: { $lte: dayjs.utc( reqestData.toDate ).endOf( 'day' ).toDate() } },
|
|
2377
2386
|
{ sourceCheckList_id: new mongoose.Types.ObjectId( reqestData.sourceCheckList_id ) },
|
|
@@ -2381,6 +2390,8 @@ export const flagChecklistTableV1 = async ( req, res ) => {
|
|
|
2381
2390
|
// { questionFlag: { $gt: 0 } },
|
|
2382
2391
|
// ],
|
|
2383
2392
|
// },
|
|
2393
|
+
// { store_id: { $in: reqestData?.storeId } },
|
|
2394
|
+
{ $or: [ { store_id: { $in: reqestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: reqestData.userEmailes } } ] },
|
|
2384
2395
|
],
|
|
2385
2396
|
},
|
|
2386
2397
|
};
|
|
@@ -2402,6 +2413,7 @@ export const flagChecklistTableV1 = async ( req, res ) => {
|
|
|
2402
2413
|
checklistStatus: 1,
|
|
2403
2414
|
questionFlagCount: '$questionFlag',
|
|
2404
2415
|
timeFlagCount: '$timeFlag',
|
|
2416
|
+
userName: '$userName',
|
|
2405
2417
|
reinitiateStatus: true,
|
|
2406
2418
|
// detections: {
|
|
2407
2419
|
// $sum: {
|
|
@@ -2427,7 +2439,7 @@ export const flagChecklistTableV1 = async ( req, res ) => {
|
|
|
2427
2439
|
];
|
|
2428
2440
|
|
|
2429
2441
|
if ( reqestData.search && reqestData.search != '' ) {
|
|
2430
|
-
pipeline[0].$match.$and.push( { storeName: { $regex: reqestData.search, $options: 'i' } } );
|
|
2442
|
+
pipeline[0].$match.$and.push( { $or: [ { storeName: { $regex: reqestData.search, $options: 'i' } }, { userName: { $regex: reqestData.search, $options: 'i' } }, { userEmail: { $regex: reqestData.search, $options: 'i' } } ] } );
|
|
2431
2443
|
}
|
|
2432
2444
|
|
|
2433
2445
|
const total = await processedchecklistService.aggregate( pipeline );
|
|
@@ -2480,6 +2492,10 @@ export const flagChecklistTableV1 = async ( req, res ) => {
|
|
|
2480
2492
|
if ( resultData ) {
|
|
2481
2493
|
if ( resultData.status_code == '200' ) {
|
|
2482
2494
|
const exportdata = [];
|
|
2495
|
+
console.log( resultData );
|
|
2496
|
+
if ( reqestData.ChecklistType==='scrum'||reqestData.ChecklistType==='cleaning' ) {
|
|
2497
|
+
reqestData.ChecklistType = 'scrumdetection';
|
|
2498
|
+
}
|
|
2483
2499
|
resultData[reqestData.ChecklistType + 'Data'].forEach( ( element ) => {
|
|
2484
2500
|
exportdata.push( {
|
|
2485
2501
|
'Date': element?.date,
|
|
@@ -2497,6 +2513,7 @@ export const flagChecklistTableV1 = async ( req, res ) => {
|
|
|
2497
2513
|
return res.sendError( 'No Content', 204 );
|
|
2498
2514
|
}
|
|
2499
2515
|
}
|
|
2516
|
+
console.log( reqestData );
|
|
2500
2517
|
|
|
2501
2518
|
let LamdaURL = 'https://vpcejaftccr3jzqf5wrdkks7yy0krqix.lambda-url.ap-south-1.on.aws/';
|
|
2502
2519
|
let resultData = await LamdaServiceCall( LamdaURL, reqestData );
|
|
@@ -2633,22 +2650,22 @@ export const checklistDropdownV1 = async ( req, res ) => {
|
|
|
2633
2650
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
2634
2651
|
let result = {};
|
|
2635
2652
|
|
|
2653
|
+
// Get User Based Checklist //
|
|
2654
|
+
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
2655
|
+
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
2656
|
+
// End: Get User Based Checklist////
|
|
2657
|
+
|
|
2636
2658
|
let findQuery = [
|
|
2637
2659
|
{ $match: { $and: [
|
|
2638
2660
|
{ client_id: requestData.clientId },
|
|
2639
|
-
{
|
|
2640
|
-
$or: [
|
|
2641
|
-
{ store_id: { $in: requestData.storeId } },
|
|
2642
|
-
{ aiStoreList: { $in: requestData.storeId } },
|
|
2643
|
-
],
|
|
2644
|
-
},
|
|
2661
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } }, { aiStoreList: { $in: requestData.storeId } } ] },
|
|
2645
2662
|
{ date_iso: { $gte: fromDate } },
|
|
2646
2663
|
{ date_iso: { $lte: toDate } },
|
|
2647
2664
|
{
|
|
2648
2665
|
$or: [
|
|
2649
2666
|
{ questionFlag: { $gte: 1 } },
|
|
2650
2667
|
{ timeFlag: { $gte: 1 } },
|
|
2651
|
-
{ checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection' ] } },
|
|
2668
|
+
{ checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum' ] } },
|
|
2652
2669
|
],
|
|
2653
2670
|
},
|
|
2654
2671
|
] } },
|
|
@@ -2656,12 +2673,14 @@ export const checklistDropdownV1 = async ( req, res ) => {
|
|
|
2656
2673
|
$project: {
|
|
2657
2674
|
sourceCheckList_id: 1,
|
|
2658
2675
|
checkListName: 1,
|
|
2676
|
+
coverage: 1,
|
|
2659
2677
|
},
|
|
2660
2678
|
},
|
|
2661
2679
|
{
|
|
2662
2680
|
$group: {
|
|
2663
2681
|
_id: '$sourceCheckList_id',
|
|
2664
2682
|
checkListName: { $last: '$checkListName' },
|
|
2683
|
+
coverage: { $last: '$coverage' },
|
|
2665
2684
|
},
|
|
2666
2685
|
},
|
|
2667
2686
|
{
|
|
@@ -2669,6 +2688,7 @@ export const checklistDropdownV1 = async ( req, res ) => {
|
|
|
2669
2688
|
_id: 0,
|
|
2670
2689
|
sourceCheckList_id: '$_id',
|
|
2671
2690
|
checkListName: 1,
|
|
2691
|
+
coverage: 1,
|
|
2672
2692
|
},
|
|
2673
2693
|
},
|
|
2674
2694
|
{
|
|
@@ -2697,7 +2717,6 @@ export const checklistDropdownV1 = async ( req, res ) => {
|
|
|
2697
2717
|
scheduleRepeatedType: 1,
|
|
2698
2718
|
scheduleStartTime: 1,
|
|
2699
2719
|
sourceCheckList_id: '$_id',
|
|
2700
|
-
storeCount: 1,
|
|
2701
2720
|
},
|
|
2702
2721
|
},
|
|
2703
2722
|
], as: 'checklistData',
|
|
@@ -2716,7 +2735,7 @@ export const checklistDropdownV1 = async ( req, res ) => {
|
|
|
2716
2735
|
scheduleRepeatedType: '$checklistData.scheduleRepeatedType',
|
|
2717
2736
|
scheduleStartTime: '$checklistData.scheduleStartTime',
|
|
2718
2737
|
sourceCheckList_id: '$checklistData._id',
|
|
2719
|
-
|
|
2738
|
+
coverage: 1,
|
|
2720
2739
|
},
|
|
2721
2740
|
},
|
|
2722
2741
|
];
|