tango-app-api-trax 3.6.2-bulktask-8 → 3.6.2-bulktask-9
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/gallery.controller.js +5 -5
- package/src/controllers/internalTrax.controller.js +42 -0
- package/src/controllers/mobileTrax.controller.js +1 -1
- package/src/controllers/teaxFlag.controller.js +118 -40
- package/src/controllers/trax.controller.js +11 -1
- package/src/routes/internalTraxApi.router.js +2 -1
- package/src/services/processedchecklist.services.js +4 -0
package/package.json
CHANGED
|
@@ -562,9 +562,9 @@ export async function redomultiChecklist( req, res ) {
|
|
|
562
562
|
let findcomment = {};
|
|
563
563
|
if ( !inputBody.payload.showcomment ) {
|
|
564
564
|
if ( inputBody.payload?.coverage === 'store' ) {
|
|
565
|
-
findcomment = inputBody.payload.excelData.find( ( ele ) => ele
|
|
565
|
+
findcomment = inputBody.payload.excelData.find( ( ele ) => ele['Store Name'] === originalData.storeName );
|
|
566
566
|
} else if ( inputBody.payload?.coverage === 'users' ) {
|
|
567
|
-
findcomment = inputBody.payload.excelData.find( ( ele ) => ele
|
|
567
|
+
findcomment = inputBody.payload.excelData.find( ( ele ) => ele['User Email'] === originalData.userEmail );
|
|
568
568
|
}
|
|
569
569
|
}
|
|
570
570
|
console.log( '****************', findcomment );
|
|
@@ -583,7 +583,7 @@ export async function redomultiChecklist( req, res ) {
|
|
|
583
583
|
|
|
584
584
|
let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.qno == req.body.payload.qno );
|
|
585
585
|
|
|
586
|
-
let data = { ...question[sectionIndex].questions[findQuestion], redo: true, redoComment: req.body.payload?.showcomment ? req.body.payload?.checklistDescription : findcomment?.
|
|
586
|
+
let data = { ...question[sectionIndex].questions[findQuestion], redo: true, redoComment: req.body.payload?.showcomment ? req.body.payload?.checklistDescription : findcomment?.Comments };
|
|
587
587
|
// if ( checklistDetails.client_id == '458' ) {
|
|
588
588
|
data.answers.forEach( ( item ) => {
|
|
589
589
|
if ( item.showLinked ) {
|
|
@@ -1162,7 +1162,7 @@ export async function taskvalidateUserData( req, res ) {
|
|
|
1162
1162
|
let error = [];
|
|
1163
1163
|
if ( req.body.coverage === 'store' ) {
|
|
1164
1164
|
for ( let [ index, store ] of req.body.assignedData.entries() ) {
|
|
1165
|
-
let findstore = await storeService.findOne( { clientId: req.body.clientId, storeName: store
|
|
1165
|
+
let findstore = await storeService.findOne( { clientId: req.body.clientId, storeName: store['Store Name'] } );
|
|
1166
1166
|
console.log( findstore );
|
|
1167
1167
|
if ( !findstore ) {
|
|
1168
1168
|
error.push( `Invalid StoreName - C${index + 2}` );
|
|
@@ -1171,7 +1171,7 @@ export async function taskvalidateUserData( req, res ) {
|
|
|
1171
1171
|
}
|
|
1172
1172
|
if ( req.body.coverage === 'users' ) {
|
|
1173
1173
|
for ( let [ index, user ] of req.body.assignedData.entries() ) {
|
|
1174
|
-
let finduser = await findOne( { clientId: req.body.clientId, email: user
|
|
1174
|
+
let finduser = await findOne( { clientId: req.body.clientId, email: user['User Email'] } );
|
|
1175
1175
|
if ( !finduser ) {
|
|
1176
1176
|
error.push( `Invalid userEmail - C${index + 2}` );
|
|
1177
1177
|
}
|
|
@@ -281,6 +281,7 @@ export async function PCLconfigCreation( req, res ) {
|
|
|
281
281
|
insertdata.checkListType = getCLconfig.checkListType;
|
|
282
282
|
insertdata.storeCount = getCLconfig.storeCount;
|
|
283
283
|
insertdata.questionCount = getCLconfig.questionCount;
|
|
284
|
+
insertdata.runAIQuestionCount = getCLconfig.runAIQuestionCount;
|
|
284
285
|
insertdata.publishDate = getCLconfig.publishDate;
|
|
285
286
|
insertdata.locationCount = getCLconfig.locationCount;
|
|
286
287
|
insertdata.scheduleRepeatedType = getCLconfig.scheduleRepeatedType;
|
|
@@ -559,6 +560,7 @@ export async function PCLconfigCreation( req, res ) {
|
|
|
559
560
|
element4.checkListType = getCLconfig.checkListType;
|
|
560
561
|
element4.storeCount = getCLconfig.storeCount;
|
|
561
562
|
element4.questionCount = getCLconfig.questionCount;
|
|
563
|
+
element4.runAIQuestionCount = getCLconfig.runAIQuestionCount;
|
|
562
564
|
element4.publishDate = getCLconfig.publishDate;
|
|
563
565
|
element4.locationCount = getCLconfig.locationCount;
|
|
564
566
|
element4.scheduleRepeatedType = getCLconfig.scheduleRepeatedType;
|
|
@@ -2514,3 +2516,43 @@ export async function insertAINotification( req, res ) {
|
|
|
2514
2516
|
else res.sendError( e, 500 );
|
|
2515
2517
|
}
|
|
2516
2518
|
}
|
|
2519
|
+
|
|
2520
|
+
export async function updateRunAI( req, res ) {
|
|
2521
|
+
try {
|
|
2522
|
+
if ( !req.body.id ) {
|
|
2523
|
+
return res.sendError( 'Checklist id is required', 400 );
|
|
2524
|
+
}
|
|
2525
|
+
if ( !req.body.sectionId ) {
|
|
2526
|
+
return res.sendError( 'Section id is required', 400 );
|
|
2527
|
+
}
|
|
2528
|
+
if ( !req.body.qName ) {
|
|
2529
|
+
return res.sendError( 'Question name is required', 400 );
|
|
2530
|
+
}
|
|
2531
|
+
let getDetails = await processedchecklist.findOne( { _id: req.body.id } );
|
|
2532
|
+
if ( !getDetails ) {
|
|
2533
|
+
return res.sendError( 'No data found', 204 );
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2536
|
+
let updateData = {};
|
|
2537
|
+
|
|
2538
|
+
for ( let k of Object.keys( req.body.data ) ) {
|
|
2539
|
+
let keyPath = `questionAnswers.$[section].questions.$[question].userAnswer.0.${k}`;
|
|
2540
|
+
updateData[keyPath] = req.body.data[k];
|
|
2541
|
+
}
|
|
2542
|
+
|
|
2543
|
+
await processedchecklist.updateArrayKey(
|
|
2544
|
+
{ _id: req.body.id },
|
|
2545
|
+
{ $set: updateData },
|
|
2546
|
+
{
|
|
2547
|
+
arrayFilters: [
|
|
2548
|
+
{ 'section.section_id': new ObjectId( req.body.sectionId ) },
|
|
2549
|
+
{ 'question.qname': req.body.qName },
|
|
2550
|
+
],
|
|
2551
|
+
},
|
|
2552
|
+
);
|
|
2553
|
+
return res.sendSuccess( 'RunAI details updated successfully' );
|
|
2554
|
+
} catch ( e ) {
|
|
2555
|
+
logger.error( { functionName: 'updateRunAI', error: e } );
|
|
2556
|
+
return res.sendError( e, 500 );
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
@@ -2610,7 +2610,7 @@ export async function dashboardv1( req, res ) {
|
|
|
2610
2610
|
...storeMatch,
|
|
2611
2611
|
};
|
|
2612
2612
|
|
|
2613
|
-
console.log( 'taskBaseMatch =>', taskBaseMatch );
|
|
2613
|
+
// console.log( 'taskBaseMatch =>', taskBaseMatch );
|
|
2614
2614
|
const taskBuildPipeline = ( matchExtraConditions = {} ) => [
|
|
2615
2615
|
{ $match: { ...taskBaseMatch, ...matchExtraConditions } },
|
|
2616
2616
|
{
|
|
@@ -617,6 +617,11 @@ export const flagCardsV1 = async ( req, res ) => {
|
|
|
617
617
|
}
|
|
618
618
|
} );
|
|
619
619
|
flagCards.totalFlag += flagCards.detectionFlag.count;
|
|
620
|
+
if ( resultData?.runAI ) {
|
|
621
|
+
resultData.runAI.flagCount = resultData.runaiflags;
|
|
622
|
+
flagCards.runAIFlag = resultData?.runAI;
|
|
623
|
+
flagCards.totalFlag += resultData.runaiflags;
|
|
624
|
+
}
|
|
620
625
|
}
|
|
621
626
|
|
|
622
627
|
return res.sendSuccess( { flagCards } );
|
|
@@ -819,6 +824,8 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
819
824
|
findAndQuery.push( { timeFlag: { $gte: 1 } } );
|
|
820
825
|
} else if ( requestData?.filter === 'detection' ) {
|
|
821
826
|
findAndQuery.push( { checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum' ] } } );
|
|
827
|
+
} else if ( requestData?.filter === 'runAI' ) {
|
|
828
|
+
findAndQuery.push( { runAIQuestionCount: { $gte: 1 } } );
|
|
822
829
|
}
|
|
823
830
|
|
|
824
831
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -1033,7 +1040,7 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
1033
1040
|
if ( getChecklistPerformanceData.length ) {
|
|
1034
1041
|
const detectionChecklists = getChecklistPerformanceData?.filter( ( val ) => val?.checkListType !== 'custom' );
|
|
1035
1042
|
|
|
1036
|
-
if ( detectionChecklists?.length ) {
|
|
1043
|
+
if ( detectionChecklists?.length || requestData?.filter === 'runAI' ) {
|
|
1037
1044
|
const detectionPayload = {
|
|
1038
1045
|
'fromDate': requestData.fromDate,
|
|
1039
1046
|
'toDate': requestData.toDate,
|
|
@@ -1046,13 +1053,23 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
1046
1053
|
if ( resultData ) {
|
|
1047
1054
|
if ( resultData.status_code == '200' ) {
|
|
1048
1055
|
for ( let index = 0; index < getChecklistPerformanceData.length; index++ ) {
|
|
1049
|
-
if (
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
+
if ( requestData?.filter === 'runAI' ) {
|
|
1057
|
+
let findCheckList = resultData.runAI.list.find( ( ele ) => ele.checkListName == getChecklistPerformanceData[index].getChecklistPerformanceData );
|
|
1058
|
+
if ( findCheckList ) {
|
|
1059
|
+
getChecklistPerformanceData[index].flaggedStores = findCheckList.flagCount;
|
|
1060
|
+
getChecklistPerformanceData[index].complianceRate = ( 100- ( getChecklistPerformanceData[index].flaggedStores / getChecklistPerformanceData[index].assignedStores ) * 100 );
|
|
1061
|
+
getChecklistPerformanceData[index].complianceRate = Math.min( 100, Math.max( 0, getChecklistPerformanceData[index].complianceRate ) );
|
|
1062
|
+
getChecklistPerformanceData[index].complianceRate = ( getChecklistPerformanceData[index].complianceRate % 1 === 0 ) ? getChecklistPerformanceData[index].complianceRate.toFixed( 0 ) : getChecklistPerformanceData[index].complianceRate.toFixed( 2 );
|
|
1063
|
+
}
|
|
1064
|
+
} else {
|
|
1065
|
+
if ( getChecklistPerformanceData[index].checkListType !== 'custom' ) {
|
|
1066
|
+
getChecklistPerformanceData[index].flagCount = resultData?.[getChecklistPerformanceData[index]?.checkListType] || 0;
|
|
1067
|
+
getChecklistPerformanceData[index].flaggedStores = resultData?.[`${getChecklistPerformanceData[index]?.checkListType}_flaggedstores`] || 0;
|
|
1068
|
+
getChecklistPerformanceData[index].assignedStores = getChecklistPerformanceData[index]?.aiStoreList?.filter( ( element ) => requestData.storeId.includes( element ) )?.length || 0;
|
|
1069
|
+
getChecklistPerformanceData[index].complianceRate = ( 100- ( getChecklistPerformanceData[index].flaggedStores / getChecklistPerformanceData[index].assignedStores ) * 100 );
|
|
1070
|
+
getChecklistPerformanceData[index].complianceRate = Math.min( 100, Math.max( 0, getChecklistPerformanceData[index].complianceRate ) );
|
|
1071
|
+
getChecklistPerformanceData[index].complianceRate = ( getChecklistPerformanceData[index].complianceRate % 1 === 0 ) ? getChecklistPerformanceData[index].complianceRate.toFixed( 0 ) : getChecklistPerformanceData[index].complianceRate.toFixed( 2 );
|
|
1072
|
+
}
|
|
1056
1073
|
}
|
|
1057
1074
|
}
|
|
1058
1075
|
}
|
|
@@ -2388,7 +2405,7 @@ export const flagChecklistTableV1 = async ( req, res ) => {
|
|
|
2388
2405
|
// let loginUser = { clientId: reqestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
2389
2406
|
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
2390
2407
|
// End: Get User Based Checklist////
|
|
2391
|
-
if ( reqestData.ChecklistType == 'custom' ) {
|
|
2408
|
+
if ( reqestData.ChecklistType == 'custom' && reqestData?.filter !== 'runAI' ) {
|
|
2392
2409
|
const match = {
|
|
2393
2410
|
$match: {
|
|
2394
2411
|
$and: [
|
|
@@ -2500,7 +2517,7 @@ export const flagChecklistTableV1 = async ( req, res ) => {
|
|
|
2500
2517
|
if ( reqestData.export ) {
|
|
2501
2518
|
reqestData.limit = 10000;
|
|
2502
2519
|
reqestData.offset = 0;
|
|
2503
|
-
let LamdaURL = 'https://
|
|
2520
|
+
let LamdaURL = 'https://vpcejaftccr3jzqf5wrdkks7yy0krqix.lambda-url.ap-south-1.on.aws/';
|
|
2504
2521
|
let resultData = await LamdaServiceCall( LamdaURL, reqestData );
|
|
2505
2522
|
if ( resultData ) {
|
|
2506
2523
|
if ( resultData.status_code == '200' ) {
|
|
@@ -2509,16 +2526,27 @@ export const flagChecklistTableV1 = async ( req, res ) => {
|
|
|
2509
2526
|
if ( reqestData.ChecklistType==='scrum'||reqestData.ChecklistType==='cleaning' ) {
|
|
2510
2527
|
reqestData.ChecklistType = 'scrumdetection';
|
|
2511
2528
|
}
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2529
|
+
if ( reqestData?.filter === 'runAI' ) {
|
|
2530
|
+
resultData.aiFlagData.forEach( ( element ) => {
|
|
2531
|
+
exportdata.push( {
|
|
2532
|
+
'Date': dayjs( element.dateString ).format( 'DD MMM, YYYY' ),
|
|
2533
|
+
'Store Name': element?.storeName,
|
|
2534
|
+
'User Email': element?.spocEmail,
|
|
2535
|
+
'Detections': element?.detections,
|
|
2536
|
+
} );
|
|
2520
2537
|
} );
|
|
2521
|
-
}
|
|
2538
|
+
} else {
|
|
2539
|
+
resultData[reqestData.ChecklistType + 'Data'].forEach( ( element ) => {
|
|
2540
|
+
exportdata.push( {
|
|
2541
|
+
'Date': element?.date,
|
|
2542
|
+
'Store Name': element?.storeName,
|
|
2543
|
+
'Store Id': element?.storeId,
|
|
2544
|
+
// 'Store Spoc Email': element?.SpocEmail,
|
|
2545
|
+
'Detections': element?.detections,
|
|
2546
|
+
'Detection Status': element?.detectionStatus,
|
|
2547
|
+
} );
|
|
2548
|
+
} );
|
|
2549
|
+
}
|
|
2522
2550
|
return await download( exportdata, res );
|
|
2523
2551
|
} else {
|
|
2524
2552
|
return res.sendError( 'No Content', 204 );
|
|
@@ -2529,11 +2557,18 @@ export const flagChecklistTableV1 = async ( req, res ) => {
|
|
|
2529
2557
|
}
|
|
2530
2558
|
// console.log( reqestData );
|
|
2531
2559
|
|
|
2532
|
-
let LamdaURL = 'https://
|
|
2560
|
+
let LamdaURL = 'https://vpcejaftccr3jzqf5wrdkks7yy0krqix.lambda-url.ap-south-1.on.aws/';
|
|
2533
2561
|
let resultData = await LamdaServiceCall( LamdaURL, reqestData );
|
|
2534
2562
|
// console.log( 'resultData =>', resultData );
|
|
2535
2563
|
if ( resultData ) {
|
|
2536
2564
|
if ( resultData.status_code == '200' ) {
|
|
2565
|
+
if ( reqestData?.filter === 'runAI' ) {
|
|
2566
|
+
resultData.aiFlagData = resultData.aiFlagData.map( ( ele ) => {
|
|
2567
|
+
ele = { ...ele, date: dayjs( ele.dateString ).format( 'DD MMM, YYYY' ), storeSpocEmail: ele?.spocEmail, checklistStatus: 'submit' };
|
|
2568
|
+
return ele;
|
|
2569
|
+
} );
|
|
2570
|
+
resultData = { customData: resultData.aiFlagData, totalCount: resultData.totalCount };
|
|
2571
|
+
}
|
|
2537
2572
|
return res.sendSuccess( resultData );
|
|
2538
2573
|
} else {
|
|
2539
2574
|
return res.sendError( 'No Content', 204 );
|
|
@@ -2680,6 +2715,9 @@ export const checklistDropdownV1 = async ( req, res ) => {
|
|
|
2680
2715
|
{ questionFlag: { $gte: 1 } },
|
|
2681
2716
|
{ timeFlag: { $gte: 1 } },
|
|
2682
2717
|
{ checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum' ] } },
|
|
2718
|
+
{
|
|
2719
|
+
runAIQuestionCount: { $gte: 1 },
|
|
2720
|
+
},
|
|
2683
2721
|
],
|
|
2684
2722
|
},
|
|
2685
2723
|
] } },
|
|
@@ -2871,21 +2909,25 @@ export const flagComparisonCardsV2 = async ( req, res ) => {
|
|
|
2871
2909
|
},
|
|
2872
2910
|
{ checkListType: 1 },
|
|
2873
2911
|
);
|
|
2874
|
-
if ( !publishedAiChecklists?.length ) {
|
|
2875
|
-
|
|
2876
|
-
}
|
|
2912
|
+
// if ( !publishedAiChecklists?.length ) {
|
|
2913
|
+
// return 0;
|
|
2914
|
+
// }
|
|
2877
2915
|
|
|
2878
2916
|
const LamdaURL = 'https://f65azvtljclaxp6l7rnx65cdmm0lcgvp.lambda-url.ap-south-1.on.aws/';
|
|
2879
2917
|
const resultData = await LamdaServiceCall( LamdaURL, detectionPayload );
|
|
2880
2918
|
const published = publishedAiChecklists.map( ( val ) => val?.checkListType );
|
|
2881
2919
|
if ( resultData?.status_code === '200' ) {
|
|
2882
2920
|
let result = 0;
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2921
|
+
let ai = 0;
|
|
2922
|
+
if ( !publishedAiChecklists?.length ) {
|
|
2923
|
+
published.forEach( ( item ) => {
|
|
2924
|
+
if ( resultData[item] ) {
|
|
2925
|
+
result += resultData[item];
|
|
2926
|
+
}
|
|
2927
|
+
} );
|
|
2928
|
+
}
|
|
2929
|
+
ai = resultData?.runAI?.flagCount || 0;
|
|
2930
|
+
return { result, ai };
|
|
2889
2931
|
}
|
|
2890
2932
|
return 0;
|
|
2891
2933
|
};
|
|
@@ -2910,15 +2952,17 @@ export const flagComparisonCardsV2 = async ( req, res ) => {
|
|
|
2910
2952
|
questionComparisonFlag: { comparisonData: 0, ComparisonFlag: false },
|
|
2911
2953
|
delayInSubmissionComparisonFlag: { comparisonData: 0, ComparisonFlag: false },
|
|
2912
2954
|
detectionComparisonFlag: { comparisonData: 0, ComparisonFlag: false },
|
|
2955
|
+
runAIComparisonFlag: { comparisonData: 0, ComparisonFlag: false },
|
|
2913
2956
|
};
|
|
2914
2957
|
|
|
2915
2958
|
if ( rangeOneData.length && rangeTwoData.length ) {
|
|
2916
|
-
let rangeOneTotalFlag = rangeOneData[0].totalFlag + rangeOneDetectionCount || 0;
|
|
2917
|
-
let rangeTwoTotalFlag = rangeTwoData[0].totalFlag + rangeTwoDetectionCount || 0;
|
|
2959
|
+
let rangeOneTotalFlag = rangeOneData[0].totalFlag + rangeOneDetectionCount.result || 0;
|
|
2960
|
+
let rangeTwoTotalFlag = rangeTwoData[0].totalFlag + rangeTwoDetectionCount.result || 0;
|
|
2918
2961
|
flagComparisonCards.totalComparisonFlag = calculateComparison( rangeOneTotalFlag, rangeTwoTotalFlag );
|
|
2919
2962
|
flagComparisonCards.questionComparisonFlag = calculateComparison( rangeOneData[0].questionFlag, rangeTwoData[0].questionFlag );
|
|
2920
2963
|
flagComparisonCards.delayInSubmissionComparisonFlag = calculateComparison( rangeOneData[0].delayInSubmission, rangeTwoData[0].delayInSubmission );
|
|
2921
|
-
flagComparisonCards.detectionComparisonFlag = calculateComparison( rangeOneDetectionCount, rangeTwoDetectionCount );
|
|
2964
|
+
flagComparisonCards.detectionComparisonFlag = calculateComparison( rangeOneDetectionCount.result, rangeTwoDetectionCount.result );
|
|
2965
|
+
flagComparisonCards.runAIComparisonFlag = calculateComparison( rangeOneDetectionCount.ai, rangeTwoDetectionCount.ai );
|
|
2922
2966
|
}
|
|
2923
2967
|
flagComparisonCards.traxMonthlyComparison = false;
|
|
2924
2968
|
let traxMonthlyComparisonData = await clientService.findOne( { clientId: requestData.clientId }, { traxMonthlyComparison: 1 } );
|
|
@@ -2961,6 +3005,8 @@ export const flagTablesV2 = async ( req, res ) => {
|
|
|
2961
3005
|
findAndQuery.push( { timeFlag: { $gte: 1 } } );
|
|
2962
3006
|
} else if ( requestData?.filter === 'detection' ) {
|
|
2963
3007
|
findAndQuery.push( { checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum' ] } } );
|
|
3008
|
+
} else if ( requestData?.filter === 'runAI' ) {
|
|
3009
|
+
findAndQuery.push( { checkListName: { $in: req.body.runAIChecklistName } } );
|
|
2964
3010
|
}
|
|
2965
3011
|
|
|
2966
3012
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -2989,6 +3035,7 @@ export const flagTablesV2 = async ( req, res ) => {
|
|
|
2989
3035
|
scheduleRepeatedType: 1,
|
|
2990
3036
|
store_id: 1,
|
|
2991
3037
|
aiStoreList: 1,
|
|
3038
|
+
runAIQuestionCount: 1,
|
|
2992
3039
|
},
|
|
2993
3040
|
} );
|
|
2994
3041
|
|
|
@@ -3035,6 +3082,7 @@ export const flagTablesV2 = async ( req, res ) => {
|
|
|
3035
3082
|
aiStoreList: { $max: '$aiStoreList' },
|
|
3036
3083
|
aiStoreListNew: { $sum: { $size: '$aiStoreList' } },
|
|
3037
3084
|
submittedQuestionCount: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionCount', 0 ] } },
|
|
3085
|
+
runAIQuestionCount: { $last: '$runAIQuestionCount' },
|
|
3038
3086
|
},
|
|
3039
3087
|
} );
|
|
3040
3088
|
|
|
@@ -3056,6 +3104,7 @@ export const flagTablesV2 = async ( req, res ) => {
|
|
|
3056
3104
|
customQuestionFlagCount: '$questionFlag',
|
|
3057
3105
|
customTimeFlagCount: '$timeFlag',
|
|
3058
3106
|
aiStoreList: 1,
|
|
3107
|
+
runAIQuestionCount: 1,
|
|
3059
3108
|
},
|
|
3060
3109
|
} );
|
|
3061
3110
|
|
|
@@ -3089,6 +3138,7 @@ export const flagTablesV2 = async ( req, res ) => {
|
|
|
3089
3138
|
customQuestionFlagCount: 1,
|
|
3090
3139
|
customTimeFlagCount: 1,
|
|
3091
3140
|
aiStoreList: 1,
|
|
3141
|
+
runAIQuestionCount: 1,
|
|
3092
3142
|
},
|
|
3093
3143
|
} );
|
|
3094
3144
|
|
|
@@ -3115,7 +3165,7 @@ export const flagTablesV2 = async ( req, res ) => {
|
|
|
3115
3165
|
if ( getChecklistPerformanceData.length ) {
|
|
3116
3166
|
const detectionChecklists = getChecklistPerformanceData?.filter( ( val ) => val?.checkListType !== 'custom' );
|
|
3117
3167
|
|
|
3118
|
-
if ( detectionChecklists?.length ) {
|
|
3168
|
+
if ( detectionChecklists?.length || [ 'runAI', 'all' ].includes( requestData?.filter ) ) {
|
|
3119
3169
|
const detectionPayload = {
|
|
3120
3170
|
'fromDate': requestData.fromDate,
|
|
3121
3171
|
'toDate': requestData.toDate,
|
|
@@ -3128,13 +3178,37 @@ export const flagTablesV2 = async ( req, res ) => {
|
|
|
3128
3178
|
if ( resultData ) {
|
|
3129
3179
|
if ( resultData.status_code == '200' ) {
|
|
3130
3180
|
for ( let index = 0; index < getChecklistPerformanceData.length; index++ ) {
|
|
3131
|
-
if (
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3181
|
+
if ( [ 'runAI', 'all' ].includes( requestData?.filter ) ) {
|
|
3182
|
+
let findCheckList = resultData?.runAI?.list?.find( ( ele ) => ele.checkListName == getChecklistPerformanceData[index].checkListName );
|
|
3183
|
+
if ( findCheckList ) {
|
|
3184
|
+
if ( requestData?.filter == 'all' ) {
|
|
3185
|
+
getChecklistPerformanceData[index].runAIFlag = findCheckList.flagCount;
|
|
3186
|
+
getChecklistPerformanceData[index].flaggedStores = getChecklistPerformanceData[index].flaggedStores + findCheckList.flagCount;
|
|
3187
|
+
} else {
|
|
3188
|
+
getChecklistPerformanceData[index].flagCount = findCheckList.flagCount;
|
|
3189
|
+
getChecklistPerformanceData[index].flaggedStores = findCheckList.flagCount;
|
|
3190
|
+
}
|
|
3191
|
+
} else {
|
|
3192
|
+
if ( requestData?.filter == 'all' ) {
|
|
3193
|
+
getChecklistPerformanceData[index].runAIFlag = 0;
|
|
3194
|
+
getChecklistPerformanceData[index].flaggedStores = 0;
|
|
3195
|
+
} else {
|
|
3196
|
+
getChecklistPerformanceData[index].flagCount = 0;
|
|
3197
|
+
getChecklistPerformanceData[index].flaggedStores = 0;
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3135
3200
|
getChecklistPerformanceData[index].complianceRate = ( 100- ( getChecklistPerformanceData[index].flaggedStores / getChecklistPerformanceData[index].assignedStores ) * 100 );
|
|
3136
3201
|
getChecklistPerformanceData[index].complianceRate = Math.min( 100, Math.max( 0, getChecklistPerformanceData[index].complianceRate ) );
|
|
3137
3202
|
getChecklistPerformanceData[index].complianceRate = ( getChecklistPerformanceData[index].complianceRate % 1 === 0 ) ? getChecklistPerformanceData[index].complianceRate.toFixed( 0 ) : getChecklistPerformanceData[index].complianceRate.toFixed( 2 );
|
|
3203
|
+
} else {
|
|
3204
|
+
if ( getChecklistPerformanceData[index].checkListType !== 'custom' ) {
|
|
3205
|
+
getChecklistPerformanceData[index].flagCount = resultData?.[getChecklistPerformanceData[index]?.checkListType] || 0;
|
|
3206
|
+
getChecklistPerformanceData[index].flaggedStores = resultData?.[`${getChecklistPerformanceData[index]?.checkListType}_flaggedstores`] || 0;
|
|
3207
|
+
getChecklistPerformanceData[index].assignedStores = getChecklistPerformanceData[index]?.aiStoreList?.filter( ( element ) => requestData.storeId.includes( element ) )?.length || 0;
|
|
3208
|
+
getChecklistPerformanceData[index].complianceRate = ( 100- ( getChecklistPerformanceData[index].flaggedStores / getChecklistPerformanceData[index].assignedStores ) * 100 );
|
|
3209
|
+
getChecklistPerformanceData[index].complianceRate = Math.min( 100, Math.max( 0, getChecklistPerformanceData[index].complianceRate ) );
|
|
3210
|
+
getChecklistPerformanceData[index].complianceRate = ( getChecklistPerformanceData[index].complianceRate % 1 === 0 ) ? getChecklistPerformanceData[index].complianceRate.toFixed( 0 ) : getChecklistPerformanceData[index].complianceRate.toFixed( 2 );
|
|
3211
|
+
}
|
|
3138
3212
|
}
|
|
3139
3213
|
}
|
|
3140
3214
|
}
|
|
@@ -3147,12 +3221,13 @@ export const flagTablesV2 = async ( req, res ) => {
|
|
|
3147
3221
|
getChecklistPerformanceData.forEach( ( element ) => {
|
|
3148
3222
|
const data = {
|
|
3149
3223
|
'Checklist Name': element.checkListName,
|
|
3150
|
-
'Question Flags': element?.customQuestionFlagCount,
|
|
3151
|
-
'Not Submitted Flags': element?.customTimeFlagCount,
|
|
3152
|
-
'Detection Flags': element?.flagCount,
|
|
3153
3224
|
'Coverage': element?.coverage,
|
|
3154
3225
|
'Assigned Stores': element?.checkListType === 'custom' ? element?.assignedStores : element?.assignedStoresAi,
|
|
3155
3226
|
'Flagged Stores': element?.flaggedStores,
|
|
3227
|
+
'Question Flags': element?.customQuestionFlagCount,
|
|
3228
|
+
...( element.runAIFlag ? { 'Run AI Flag': element.runAIFlag } : {} ),
|
|
3229
|
+
'Not Submitted Flags': element?.customTimeFlagCount,
|
|
3230
|
+
'Detection Flags': element?.flagCount,
|
|
3156
3231
|
'Compliance': element?.complianceRate,
|
|
3157
3232
|
// 'Flag Type': element?.checkListType === 'custom' ? 'Question' : 'Detection',
|
|
3158
3233
|
};
|
|
@@ -3162,18 +3237,21 @@ export const flagTablesV2 = async ( req, res ) => {
|
|
|
3162
3237
|
delete data['Flagged Count'];
|
|
3163
3238
|
delete data['Not Submitted Flags'];
|
|
3164
3239
|
delete data['Detection Flags'];
|
|
3240
|
+
delete data['Run AI Flag'];
|
|
3165
3241
|
} else if ( requestData?.filter === 'time' ) {
|
|
3166
3242
|
data['Flags'] = data['Not Submitted Flags'];
|
|
3167
3243
|
delete data['Question Flags'];
|
|
3168
3244
|
delete data['Flagged Count'];
|
|
3169
3245
|
delete data['Not Submitted Flags'];
|
|
3170
3246
|
delete data['Detection Flags'];
|
|
3247
|
+
delete data['Run AI Flag'];
|
|
3171
3248
|
} else if ( requestData?.filter === 'detection' ) {
|
|
3172
3249
|
data['Flags'] = data['Detection Flags'];
|
|
3173
3250
|
delete data['Question Flags'];
|
|
3174
3251
|
delete data['Flagged Count'];
|
|
3175
3252
|
delete data['Not Submitted Flags'];
|
|
3176
3253
|
delete data['Detection Flags'];
|
|
3254
|
+
delete data['Run AI Flag'];
|
|
3177
3255
|
}
|
|
3178
3256
|
exportdata.push( data );
|
|
3179
3257
|
} );
|
|
@@ -174,6 +174,8 @@ export const create = async ( req, res ) => {
|
|
|
174
174
|
checkNumber = 1;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
let runAIQuestionCount = 0;
|
|
178
|
+
|
|
177
179
|
inputBody.sections.forEach( async ( element ) => {
|
|
178
180
|
if ( !element?.questions?.length && inputBody.submitType == 'configure' ) {
|
|
179
181
|
return res.sendError( { message: 'Question is Required' }, 400 );
|
|
@@ -181,6 +183,8 @@ export const create = async ( req, res ) => {
|
|
|
181
183
|
if ( element?.questions?.length ) {
|
|
182
184
|
questionCount = questionCount + element?.questions?.length;
|
|
183
185
|
}
|
|
186
|
+
let runAiQuestions = element?.questions.filter( ( qn ) => qn.runAI );
|
|
187
|
+
runAIQuestionCount +=runAiQuestions.length;
|
|
184
188
|
} );
|
|
185
189
|
|
|
186
190
|
let checkListDetails = {
|
|
@@ -193,6 +197,7 @@ export const create = async ( req, res ) => {
|
|
|
193
197
|
questionCount: questionCount,
|
|
194
198
|
client_id: req.body?.clientId,
|
|
195
199
|
owner: req.user.userType == 'client' ? [ { name: req.user.userName, value: req.user.email } ] : [],
|
|
200
|
+
runAIQuestionCount: runAIQuestionCount,
|
|
196
201
|
// configStartDate:new Date(),
|
|
197
202
|
// configEndDate:new Date(),
|
|
198
203
|
};
|
|
@@ -812,7 +817,7 @@ export const update = async ( req, res ) => {
|
|
|
812
817
|
}
|
|
813
818
|
|
|
814
819
|
let getExistQuestions = await questionService.findSort( { checkListId: req.params.checklistId, client_id: req.body.clientId }, {}, { sectionNumber: 1 } );
|
|
815
|
-
|
|
820
|
+
let runAIQuestionCount = 0;
|
|
816
821
|
inputBody.sections.forEach( async ( element ) => {
|
|
817
822
|
if ( !element.questions.length && inputBody.submitType == 'configure' ) {
|
|
818
823
|
return res.sendError( { message: 'Question is Required' }, 400 );
|
|
@@ -821,6 +826,8 @@ export const update = async ( req, res ) => {
|
|
|
821
826
|
if ( element.questions.length ) {
|
|
822
827
|
questionCount = questionCount + element.questions.length;
|
|
823
828
|
}
|
|
829
|
+
let runAiQuestions = element?.questions.filter( ( qn ) => qn.runAI );
|
|
830
|
+
runAIQuestionCount +=runAiQuestions.length;
|
|
824
831
|
} );
|
|
825
832
|
|
|
826
833
|
|
|
@@ -828,6 +835,7 @@ export const update = async ( req, res ) => {
|
|
|
828
835
|
checkListName: inputBody.checklistName,
|
|
829
836
|
checkListDescription: inputBody.checklistDescription,
|
|
830
837
|
questionCount: questionCount,
|
|
838
|
+
runAIQuestionCount: runAIQuestionCount,
|
|
831
839
|
};
|
|
832
840
|
|
|
833
841
|
await checklistService.updateOne( { _id: req.params.checklistId }, params );
|
|
@@ -2951,6 +2959,7 @@ export async function insertSingleProcessData( checklistId, processId = 0, oldDa
|
|
|
2951
2959
|
insertdata.checkListType = getCLconfig.checkListType;
|
|
2952
2960
|
insertdata.storeCount = getCLconfig.storeCount;
|
|
2953
2961
|
insertdata.questionCount = getCLconfig.questionCount;
|
|
2962
|
+
insertdata.runAIQuestionCount = getCLconfig.runAIQuestionCount;
|
|
2954
2963
|
insertdata.publishDate = getCLconfig.publishDate;
|
|
2955
2964
|
insertdata.locationCount = getCLconfig.locationCount;
|
|
2956
2965
|
insertdata.scheduleRepeatedType = getCLconfig.scheduleRepeatedType;
|
|
@@ -3671,6 +3680,7 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3671
3680
|
element4.checkListType = getCLconfig.checkListType;
|
|
3672
3681
|
element4.storeCount = getCLconfig.storeCount;
|
|
3673
3682
|
element4.questionCount = getCLconfig.questionCount;
|
|
3683
|
+
element4.runAIQuestionCount = getCLconfig.runAIQuestionCount;
|
|
3674
3684
|
element4.publishDate = getCLconfig.publishDate;
|
|
3675
3685
|
element4.locationCount = getCLconfig.locationCount;
|
|
3676
3686
|
element4.scheduleRepeatedType = getCLconfig.scheduleRepeatedType;
|
|
@@ -25,6 +25,7 @@ internalTraxRouter
|
|
|
25
25
|
.post( '/sendAiPushNotification', isAllowedInternalAPIHandler, internalController.internalAISendPushNotification )
|
|
26
26
|
.post( '/getLiveChecklistClients', isAllowedInternalAPIHandler, internalController.getLiveChecklistClients )
|
|
27
27
|
.post( '/notificationCreate', isAllowedInternalAPIHandler, internalController.notificationCreate )
|
|
28
|
-
.post( '/insertAINotification', isAllowedInternalAPIHandler, internalController.insertAINotification )
|
|
28
|
+
.post( '/insertAINotification', isAllowedInternalAPIHandler, internalController.insertAINotification )
|
|
29
|
+
.post( '/updateRunAI', isAllowedInternalAPIHandler, internalController.updateRunAI );
|
|
29
30
|
|
|
30
31
|
|
|
@@ -42,3 +42,7 @@ export const findLimit = ( query = {}, record = {}, offset, limit ) => {
|
|
|
42
42
|
export const getCount = ( query = {} ) => {
|
|
43
43
|
return model.processedchecklistModel.count( query );
|
|
44
44
|
};
|
|
45
|
+
|
|
46
|
+
export const updateArrayKey = ( query = {}, record = {}, arrayFilter={} ) => {
|
|
47
|
+
return model.processedchecklistModel.updateOne( query, record, arrayFilter );
|
|
48
|
+
};
|