tango-app-api-trax 3.3.1-hotfix-8 → 3.4.0-flag-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 +1 -1
- package/src/controllers/teaxFlag.controller.js +398 -0
- package/src/hbs/login-otp.hbs +943 -943
- package/src/routes/traxFlag.router.js +9 -1
package/package.json
CHANGED
|
@@ -2756,3 +2756,401 @@ export const checklistDropdownV1 = async ( req, res ) => {
|
|
|
2756
2756
|
return res.sendError( { error: error }, 500 );
|
|
2757
2757
|
}
|
|
2758
2758
|
};
|
|
2759
|
+
|
|
2760
|
+
export const flagComparisonCardsV2 = async ( req, res ) => {
|
|
2761
|
+
try {
|
|
2762
|
+
let requestData = req.body;
|
|
2763
|
+
let toDate = new Date( requestData.toDate );
|
|
2764
|
+
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
2765
|
+
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
2766
|
+
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
2767
|
+
|
|
2768
|
+
let rangeOneFromDate;
|
|
2769
|
+
let rangeOneToDate;
|
|
2770
|
+
let rangeTwoFromDate;
|
|
2771
|
+
let rangeTwoToDate;
|
|
2772
|
+
if ( requestData.dateType == 'weekly' ) {
|
|
2773
|
+
rangeOneFromDate = new Date( requestData.toDate );
|
|
2774
|
+
rangeOneFromDate.setDate( rangeOneFromDate.getDate() - 6 );
|
|
2775
|
+
rangeOneToDate = new Date( requestData.toDate );
|
|
2776
|
+
rangeOneToDate = new Date( rangeOneToDate.getTime() - userTimezoneOffset );
|
|
2777
|
+
rangeOneToDate.setUTCHours( 23, 59, 59, 59 );
|
|
2778
|
+
rangeTwoToDate = new Date( requestData.toDate );
|
|
2779
|
+
rangeTwoToDate.setDate( rangeTwoToDate.getDate() - 7 );
|
|
2780
|
+
rangeTwoFromDate = new Date( rangeTwoToDate );
|
|
2781
|
+
rangeTwoFromDate.setDate( rangeTwoFromDate.getDate() - 6 );
|
|
2782
|
+
rangeTwoToDate = new Date( rangeTwoToDate.getTime() - userTimezoneOffset );
|
|
2783
|
+
rangeTwoToDate.setUTCHours( 23, 59, 59, 59 );
|
|
2784
|
+
} else if ( requestData.dateType == 'monthly' ) {
|
|
2785
|
+
rangeOneFromDate = new Date( requestData.toDate );
|
|
2786
|
+
rangeOneFromDate.setDate( rangeOneFromDate.getDate() - 30 );
|
|
2787
|
+
rangeOneToDate = new Date( requestData.toDate );
|
|
2788
|
+
rangeOneToDate = new Date( rangeOneToDate.getTime() - userTimezoneOffset );
|
|
2789
|
+
rangeOneToDate.setUTCHours( 23, 59, 59, 59 );
|
|
2790
|
+
rangeTwoToDate = new Date( requestData.toDate );
|
|
2791
|
+
rangeTwoToDate.setDate( rangeTwoToDate.getDate() - 31 );
|
|
2792
|
+
rangeTwoFromDate = new Date( rangeTwoToDate );
|
|
2793
|
+
rangeTwoFromDate.setDate( rangeTwoFromDate.getDate() - 30 );
|
|
2794
|
+
rangeTwoToDate = new Date( rangeTwoToDate.getTime() - userTimezoneOffset );
|
|
2795
|
+
rangeTwoToDate.setUTCHours( 23, 59, 59, 59 );
|
|
2796
|
+
} else {
|
|
2797
|
+
rangeOneFromDate = new Date( requestData.toDate );
|
|
2798
|
+
rangeOneFromDate.setDate( rangeOneFromDate.getDate() - 0 );
|
|
2799
|
+
rangeOneToDate = new Date( requestData.toDate );
|
|
2800
|
+
rangeOneToDate = new Date( rangeOneToDate.getTime() - userTimezoneOffset );
|
|
2801
|
+
rangeOneToDate.setUTCHours( 23, 59, 59, 59 );
|
|
2802
|
+
rangeTwoToDate = new Date( requestData.toDate );
|
|
2803
|
+
rangeTwoToDate.setDate( rangeTwoToDate.getDate() - 1 );
|
|
2804
|
+
rangeTwoFromDate = new Date( rangeTwoToDate );
|
|
2805
|
+
rangeTwoFromDate.setDate( rangeTwoFromDate.getDate() - 0 );
|
|
2806
|
+
rangeTwoToDate = new Date( rangeTwoToDate.getTime() - userTimezoneOffset );
|
|
2807
|
+
rangeTwoToDate.setUTCHours( 23, 59, 59, 59 );
|
|
2808
|
+
}
|
|
2809
|
+
|
|
2810
|
+
const createFindQuery = ( fromDate, toDate ) => [
|
|
2811
|
+
{ $match: { client_id: requestData.clientId,
|
|
2812
|
+
date_iso: { $gte: fromDate, $lte: toDate },
|
|
2813
|
+
$or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } }, { aiStoreList: { $in: requestData.storeId } } ],
|
|
2814
|
+
} },
|
|
2815
|
+
{
|
|
2816
|
+
$project: {
|
|
2817
|
+
timeFlag: 1,
|
|
2818
|
+
questionFlag: 1,
|
|
2819
|
+
},
|
|
2820
|
+
},
|
|
2821
|
+
{
|
|
2822
|
+
$group: {
|
|
2823
|
+
_id: '',
|
|
2824
|
+
totalFlag: { $sum: { $add: [ '$questionFlag', '$timeFlag' ] } },
|
|
2825
|
+
questionFlag: { $sum: '$questionFlag' },
|
|
2826
|
+
delayInSubmission: { $sum: '$timeFlag' },
|
|
2827
|
+
},
|
|
2828
|
+
},
|
|
2829
|
+
];
|
|
2830
|
+
|
|
2831
|
+
const calculateComparison = ( rangeOneVal, rangeTwoVal ) => {
|
|
2832
|
+
if ( rangeOneVal === 0 ) {
|
|
2833
|
+
return { comparisonData: 0, ComparisonFlag: false };
|
|
2834
|
+
}
|
|
2835
|
+
|
|
2836
|
+
let comparisonData = Math.abs( ( ( rangeOneVal - rangeTwoVal ) / rangeTwoVal ) * 100 );
|
|
2837
|
+
if ( comparisonData === Infinity ) comparisonData = 0;
|
|
2838
|
+
comparisonData = comparisonData % 1 === 0 ? comparisonData.toFixed( 0 ) : comparisonData.toFixed( 1 );
|
|
2839
|
+
comparisonData = parseInt( comparisonData );
|
|
2840
|
+
const ComparisonFlag = rangeOneVal > rangeTwoVal;
|
|
2841
|
+
return { comparisonData, ComparisonFlag };
|
|
2842
|
+
};
|
|
2843
|
+
|
|
2844
|
+
const getDetectionCount = async ( fromDate, toDate ) => {
|
|
2845
|
+
const detectionPayload = {
|
|
2846
|
+
fromDate: dayjs( fromDate ).format( 'YYYY-MM-DD' ),
|
|
2847
|
+
toDate: dayjs( toDate ).startOf( 'day' ).format( 'YYYY-MM-DD' ),
|
|
2848
|
+
storeId: requestData.storeId,
|
|
2849
|
+
clientId: requestData.clientId,
|
|
2850
|
+
};
|
|
2851
|
+
|
|
2852
|
+
const publishedAiChecklists = await checklistconfigService.find(
|
|
2853
|
+
{
|
|
2854
|
+
client_id: requestData.clientId,
|
|
2855
|
+
publish: true,
|
|
2856
|
+
checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum' ] },
|
|
2857
|
+
},
|
|
2858
|
+
{ checkListType: 1 },
|
|
2859
|
+
);
|
|
2860
|
+
if ( !publishedAiChecklists?.length ) {
|
|
2861
|
+
return 0;
|
|
2862
|
+
}
|
|
2863
|
+
|
|
2864
|
+
const LamdaURL = 'https://f65azvtljclaxp6l7rnx65cdmm0lcgvp.lambda-url.ap-south-1.on.aws/';
|
|
2865
|
+
const resultData = await LamdaServiceCall( LamdaURL, detectionPayload );
|
|
2866
|
+
const published = publishedAiChecklists.map( ( val ) => val?.checkListType );
|
|
2867
|
+
if ( resultData?.status_code === '200' ) {
|
|
2868
|
+
let result = 0;
|
|
2869
|
+
published.forEach( ( item ) => {
|
|
2870
|
+
if ( resultData[item] ) {
|
|
2871
|
+
result += resultData[item];
|
|
2872
|
+
}
|
|
2873
|
+
} );
|
|
2874
|
+
return result;
|
|
2875
|
+
}
|
|
2876
|
+
return 0;
|
|
2877
|
+
};
|
|
2878
|
+
|
|
2879
|
+
const [ rangeOneData, rangeTwoData, rangeOneDetectionCount, rangeTwoDetectionCount ] = await Promise.all( [
|
|
2880
|
+
processedchecklistService.aggregate( createFindQuery( rangeOneFromDate, rangeOneToDate ) ),
|
|
2881
|
+
processedchecklistService.aggregate( createFindQuery( rangeTwoFromDate, rangeTwoToDate ) ),
|
|
2882
|
+
getDetectionCount( rangeOneFromDate, rangeOneToDate ),
|
|
2883
|
+
getDetectionCount( rangeTwoFromDate, rangeTwoToDate ),
|
|
2884
|
+
] );
|
|
2885
|
+
|
|
2886
|
+
const flagComparisonCards = {
|
|
2887
|
+
totalComparisonFlag: { comparisonData: 0, ComparisonFlag: false },
|
|
2888
|
+
questionComparisonFlag: { comparisonData: 0, ComparisonFlag: false },
|
|
2889
|
+
delayInSubmissionComparisonFlag: { comparisonData: 0, ComparisonFlag: false },
|
|
2890
|
+
detectionComparisonFlag: { comparisonData: 0, ComparisonFlag: false },
|
|
2891
|
+
};
|
|
2892
|
+
|
|
2893
|
+
let rangeOneTotalFlag = rangeOneData[0].totalFlag + rangeOneDetectionCount;
|
|
2894
|
+
let rangeTwoTotalFlag = rangeTwoData[0].totalFlag + rangeTwoDetectionCount;
|
|
2895
|
+
if ( rangeOneData.length && rangeTwoData.length ) {
|
|
2896
|
+
flagComparisonCards.totalComparisonFlag = calculateComparison( rangeOneTotalFlag, rangeTwoTotalFlag );
|
|
2897
|
+
flagComparisonCards.questionComparisonFlag = calculateComparison( rangeOneData[0].questionFlag, rangeTwoData[0].questionFlag );
|
|
2898
|
+
flagComparisonCards.delayInSubmissionComparisonFlag = calculateComparison( rangeOneData[0].delayInSubmission, rangeTwoData[0].delayInSubmission );
|
|
2899
|
+
flagComparisonCards.detectionComparisonFlag = calculateComparison( rangeOneDetectionCount, rangeTwoDetectionCount );
|
|
2900
|
+
}
|
|
2901
|
+
|
|
2902
|
+
return res.sendSuccess( { flagComparisonCards } );
|
|
2903
|
+
} catch ( error ) {
|
|
2904
|
+
console.log( 'error =>', error );
|
|
2905
|
+
logger.error( { error, function: 'flagComparisonCardsV1' } );
|
|
2906
|
+
return res.sendError( error, 500 );
|
|
2907
|
+
}
|
|
2908
|
+
};
|
|
2909
|
+
|
|
2910
|
+
export const flagTablesV2 = async ( req, res ) => {
|
|
2911
|
+
try {
|
|
2912
|
+
let requestData = req.body;
|
|
2913
|
+
let fromDate = new Date( requestData.fromDate );
|
|
2914
|
+
let toDate = new Date( requestData.toDate );
|
|
2915
|
+
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
2916
|
+
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
2917
|
+
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
2918
|
+
let result = {};
|
|
2919
|
+
|
|
2920
|
+
let findQuery = [];
|
|
2921
|
+
let findAndQuery = [];
|
|
2922
|
+
findAndQuery.push(
|
|
2923
|
+
{ client_id: requestData.clientId },
|
|
2924
|
+
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
2925
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes } }, { aiStoreList: { $in: requestData.storeId } } ] },
|
|
2926
|
+
);
|
|
2927
|
+
|
|
2928
|
+
if ( requestData?.filter === 'all' ) {
|
|
2929
|
+
findAndQuery.push( { $or: [ { checkListType: { $in: [ 'custom', 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum' ] } } ] } );
|
|
2930
|
+
} else if ( requestData?.filter === 'question' ) {
|
|
2931
|
+
findAndQuery.push( { checkListType: 'custom' } );
|
|
2932
|
+
findAndQuery.push( { questionFlag: { $gte: 1 } } );
|
|
2933
|
+
} else if ( requestData?.filter === 'time' ) {
|
|
2934
|
+
findAndQuery.push( { checkListType: 'custom' } );
|
|
2935
|
+
findAndQuery.push( { timeFlag: { $gte: 1 } } );
|
|
2936
|
+
} else if ( requestData?.filter === 'detection' ) {
|
|
2937
|
+
findAndQuery.push( { checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum' ] } } );
|
|
2938
|
+
}
|
|
2939
|
+
|
|
2940
|
+
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
2941
|
+
|
|
2942
|
+
if ( requestData.searchValue && requestData.searchValue != '' ) {
|
|
2943
|
+
findQuery.push( { $match: { $or: [ { checkListName: { $regex: requestData.searchValue, $options: 'i' } } ] } } );
|
|
2944
|
+
}
|
|
2945
|
+
|
|
2946
|
+
findQuery.push( {
|
|
2947
|
+
$project: {
|
|
2948
|
+
sourceCheckList_id: 1,
|
|
2949
|
+
checkListId: 1,
|
|
2950
|
+
checkListName: 1,
|
|
2951
|
+
coverage: 1,
|
|
2952
|
+
storeCount: 1,
|
|
2953
|
+
createdBy: 1,
|
|
2954
|
+
createdByName: 1,
|
|
2955
|
+
checklistStatus: 1,
|
|
2956
|
+
timeFlag: 1,
|
|
2957
|
+
questionFlag: 1,
|
|
2958
|
+
questionCount: 1,
|
|
2959
|
+
mobileDetectionFlag: 1,
|
|
2960
|
+
storeOpenCloseFlag: 1,
|
|
2961
|
+
uniformDetectionFlag: 1,
|
|
2962
|
+
checkListType: 1,
|
|
2963
|
+
scheduleRepeatedType: 1,
|
|
2964
|
+
store_id: 1,
|
|
2965
|
+
aiStoreList: 1,
|
|
2966
|
+
},
|
|
2967
|
+
} );
|
|
2968
|
+
|
|
2969
|
+
findQuery.push( {
|
|
2970
|
+
$group: {
|
|
2971
|
+
_id: '$sourceCheckList_id',
|
|
2972
|
+
checkListName: { $last: '$checkListName' },
|
|
2973
|
+
checkListChar: { $last: { $substr: [ '$checkListName', 0, 2 ] } },
|
|
2974
|
+
coverage: { $last: '$coverage' },
|
|
2975
|
+
sourceCheckList_id: { $last: '$sourceCheckList_id' },
|
|
2976
|
+
checkListType: { $last: '$checkListType' },
|
|
2977
|
+
storeCount: { $sum: 1 },
|
|
2978
|
+
storeCountAi: { $max: '$storeCount' },
|
|
2979
|
+
flaggedStores: { $sum: { $cond: [
|
|
2980
|
+
{
|
|
2981
|
+
$or: [
|
|
2982
|
+
{ '$gt': [ '$timeFlag', 0 ] },
|
|
2983
|
+
{ '$gt': [ '$questionFlag', 0 ] },
|
|
2984
|
+
{ '$gt': [ '$mobileDetectionFlag', 0 ] },
|
|
2985
|
+
{ '$gt': [ '$storeOpenCloseFlag', 0 ] },
|
|
2986
|
+
{ '$gt': [ '$uniformDetectionFlag', 0 ] },
|
|
2987
|
+
{ '$gt': [ '$customerUnattended', 0 ] },
|
|
2988
|
+
{ '$gt': [ '$staffLeftInTheMiddle', 0 ] },
|
|
2989
|
+
{ '$gt': [ '$cleaning', 0 ] },
|
|
2990
|
+
{ '$gt': [ '$scrum', 0 ] },
|
|
2991
|
+
],
|
|
2992
|
+
},
|
|
2993
|
+
1,
|
|
2994
|
+
0,
|
|
2995
|
+
] } },
|
|
2996
|
+
flagCount: {
|
|
2997
|
+
$sum: {
|
|
2998
|
+
$add: [ '$questionFlag', '$timeFlag' ],
|
|
2999
|
+
},
|
|
3000
|
+
},
|
|
3001
|
+
submittedChecklist: {
|
|
3002
|
+
$sum: {
|
|
3003
|
+
$cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ],
|
|
3004
|
+
},
|
|
3005
|
+
},
|
|
3006
|
+
questionFlag: { $sum: '$questionFlag' },
|
|
3007
|
+
timeFlag: { $sum: '$timeFlag' },
|
|
3008
|
+
questionCount: { $sum: '$questionCount' },
|
|
3009
|
+
aiStoreList: { $max: '$aiStoreList' },
|
|
3010
|
+
aiStoreListNew: { $sum: { $size: '$aiStoreList' } },
|
|
3011
|
+
submittedQuestionCount: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionCount', 0 ] } },
|
|
3012
|
+
},
|
|
3013
|
+
} );
|
|
3014
|
+
|
|
3015
|
+
findQuery.push( {
|
|
3016
|
+
$project: {
|
|
3017
|
+
assignedStores: '$storeCount',
|
|
3018
|
+
assignedStoresAi: '$aiStoreListNew',
|
|
3019
|
+
checkListName: 1,
|
|
3020
|
+
coverage: 1,
|
|
3021
|
+
checkListChar: 1,
|
|
3022
|
+
sourceCheckList_id: 1,
|
|
3023
|
+
checkListType: 1,
|
|
3024
|
+
flagType: 1,
|
|
3025
|
+
uniqueFlaggedStores: 1,
|
|
3026
|
+
flaggedStores: '$flaggedStores',
|
|
3027
|
+
flagCount: 1,
|
|
3028
|
+
questionCount: 1,
|
|
3029
|
+
correctAnswers: { $subtract: [ '$submittedQuestionCount', '$questionFlag' ] },
|
|
3030
|
+
customQuestionFlagCount: '$questionFlag',
|
|
3031
|
+
customTimeFlagCount: '$timeFlag',
|
|
3032
|
+
aiStoreList: 1,
|
|
3033
|
+
},
|
|
3034
|
+
} );
|
|
3035
|
+
|
|
3036
|
+
findQuery.push( {
|
|
3037
|
+
$project: {
|
|
3038
|
+
checkListName: 1,
|
|
3039
|
+
checkListChar: 1,
|
|
3040
|
+
coverage: {
|
|
3041
|
+
$concat: [
|
|
3042
|
+
{ $toUpper: { $substr: [ { $ifNull: [ '$coverage', '' ] }, 0, 1 ] } },
|
|
3043
|
+
{ $substr: [ { $ifNull: [ '$coverage', '' ] }, 1, { $strLenCP: { $ifNull: [ '$coverage', '' ] } } ] },
|
|
3044
|
+
],
|
|
3045
|
+
},
|
|
3046
|
+
sourceCheckList_id: 1,
|
|
3047
|
+
checkListType: 1,
|
|
3048
|
+
flagType: 1,
|
|
3049
|
+
assignedStores: 1,
|
|
3050
|
+
assignedStoresAi: 1,
|
|
3051
|
+
flaggedStores: 1,
|
|
3052
|
+
flagCount: 1,
|
|
3053
|
+
uniqueFlaggedStores: 1,
|
|
3054
|
+
complianceRate: {
|
|
3055
|
+
$cond: {
|
|
3056
|
+
if: { $eq: [ '$questionCount', 0 ] },
|
|
3057
|
+
then: 0,
|
|
3058
|
+
else: {
|
|
3059
|
+
$round: [ { $multiply: [ { $divide: [ '$correctAnswers', '$questionCount' ] }, 100 ] }, 2 ],
|
|
3060
|
+
},
|
|
3061
|
+
},
|
|
3062
|
+
},
|
|
3063
|
+
customQuestionFlagCount: 1,
|
|
3064
|
+
customTimeFlagCount: 1,
|
|
3065
|
+
aiStoreList: 1,
|
|
3066
|
+
},
|
|
3067
|
+
} );
|
|
3068
|
+
|
|
3069
|
+
let getTotalCount = await processedchecklistService.aggregate( findQuery );
|
|
3070
|
+
if ( !getTotalCount.length ) {
|
|
3071
|
+
return res.sendError( { error: 'No Data Found' }, 204 );
|
|
3072
|
+
}
|
|
3073
|
+
|
|
3074
|
+
if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
|
|
3075
|
+
findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
|
|
3076
|
+
} else {
|
|
3077
|
+
findQuery.push( { $sort: { ['submittedChecklist']: -1 } } );
|
|
3078
|
+
}
|
|
3079
|
+
|
|
3080
|
+
if ( !requestData.export ) {
|
|
3081
|
+
let limit = parseInt( requestData?.limit ) || 10;
|
|
3082
|
+
let skip = limit * ( requestData?.offset ) || 0;
|
|
3083
|
+
findQuery.push( { $skip: skip }, { $limit: limit } );
|
|
3084
|
+
}
|
|
3085
|
+
|
|
3086
|
+
|
|
3087
|
+
let getChecklistPerformanceData = await processedchecklistService.aggregate( findQuery );
|
|
3088
|
+
|
|
3089
|
+
if ( getChecklistPerformanceData.length ) {
|
|
3090
|
+
const detectionChecklists = getChecklistPerformanceData?.filter( ( val ) => val?.checkListType !== 'custom' );
|
|
3091
|
+
|
|
3092
|
+
if ( detectionChecklists?.length ) {
|
|
3093
|
+
const detectionPayload = {
|
|
3094
|
+
'fromDate': requestData.fromDate,
|
|
3095
|
+
'toDate': requestData.toDate,
|
|
3096
|
+
'storeId': requestData.storeId,
|
|
3097
|
+
'clientId': requestData.clientId,
|
|
3098
|
+
};
|
|
3099
|
+
|
|
3100
|
+
let LamdaURL = 'https://f65azvtljclaxp6l7rnx65cdmm0lcgvp.lambda-url.ap-south-1.on.aws/';
|
|
3101
|
+
let resultData = await LamdaServiceCall( LamdaURL, detectionPayload );
|
|
3102
|
+
if ( resultData ) {
|
|
3103
|
+
if ( resultData.status_code == '200' ) {
|
|
3104
|
+
for ( let index = 0; index < getChecklistPerformanceData.length; index++ ) {
|
|
3105
|
+
if ( getChecklistPerformanceData[index].checkListType !== 'custom' ) {
|
|
3106
|
+
getChecklistPerformanceData[index].flagCount = resultData?.[getChecklistPerformanceData[index]?.checkListType] || 0;
|
|
3107
|
+
getChecklistPerformanceData[index].flaggedStores = resultData?.[`${getChecklistPerformanceData[index]?.checkListType}_flaggedstores`] || 0;
|
|
3108
|
+
getChecklistPerformanceData[index].assignedStores = getChecklistPerformanceData[index]?.aiStoreList?.filter( ( element ) => requestData.storeId.includes( element ) )?.length || 0;
|
|
3109
|
+
getChecklistPerformanceData[index].complianceRate = ( 100- ( getChecklistPerformanceData[index].flaggedStores / getChecklistPerformanceData[index].assignedStores ) * 100 );
|
|
3110
|
+
getChecklistPerformanceData[index].complianceRate = Math.min( 100, Math.max( 0, getChecklistPerformanceData[index].complianceRate ) );
|
|
3111
|
+
getChecklistPerformanceData[index].complianceRate = ( getChecklistPerformanceData[index].complianceRate % 1 === 0 ) ? getChecklistPerformanceData[index].complianceRate.toFixed( 0 ) : getChecklistPerformanceData[index].complianceRate.toFixed( 2 );
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
|
|
3119
|
+
if ( requestData.export ) {
|
|
3120
|
+
const exportdata = [];
|
|
3121
|
+
getChecklistPerformanceData.forEach( ( element ) => {
|
|
3122
|
+
const data = {
|
|
3123
|
+
'Checklist Name': element.checkListName,
|
|
3124
|
+
'Question Flags': element?.customQuestionFlagCount,
|
|
3125
|
+
'Not Submitted Flags': element?.customTimeFlagCount,
|
|
3126
|
+
'Flagged Count': element?.flagCount,
|
|
3127
|
+
'Coverage': element?.coverage,
|
|
3128
|
+
'Assigned Stores': element?.assignedStores,
|
|
3129
|
+
'Flagged Stores': element?.flaggedStores,
|
|
3130
|
+
'Compliance': element?.complianceRate,
|
|
3131
|
+
// 'Flag Type': element?.checkListType === 'custom' ? 'Question' : 'Detection',
|
|
3132
|
+
};
|
|
3133
|
+
if ( requestData?.filter === 'question' ) {
|
|
3134
|
+
delete data['Flagged Count'];
|
|
3135
|
+
delete data['Not Submitted Flags'];
|
|
3136
|
+
} else if ( requestData?.filter === 'time' ) {
|
|
3137
|
+
delete data['Flagged Count'];
|
|
3138
|
+
delete data['Question Flags'];
|
|
3139
|
+
} else if ( requestData?.filter === 'detection' ) {
|
|
3140
|
+
delete data['Not Submitted Flags'];
|
|
3141
|
+
delete data['Question Flags'];
|
|
3142
|
+
}
|
|
3143
|
+
exportdata.push( data );
|
|
3144
|
+
} );
|
|
3145
|
+
return await download( exportdata, res );
|
|
3146
|
+
}
|
|
3147
|
+
|
|
3148
|
+
result.totalCount = getTotalCount.length;
|
|
3149
|
+
result.checklistPerformance = getChecklistPerformanceData;
|
|
3150
|
+
return res.sendSuccess( result );
|
|
3151
|
+
} catch ( error ) {
|
|
3152
|
+
console.log( 'error =>', error );
|
|
3153
|
+
logger.error( { error: error, message: req.query, function: 'flagTablesV2' } );
|
|
3154
|
+
return res.sendError( { error: error }, 500 );
|
|
3155
|
+
}
|
|
3156
|
+
};
|