tango-app-api-trax 3.6.1-runai-2 → 3.6.1-runai-4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-trax",
3
- "version": "3.6.1-runai-2",
3
+ "version": "3.6.1-runai-4",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -2516,3 +2516,43 @@ export async function insertAINotification( req, res ) {
2516
2516
  else res.sendError( e, 500 );
2517
2517
  }
2518
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
+ }
@@ -618,7 +618,9 @@ export const flagCardsV1 = async ( req, res ) => {
618
618
  } );
619
619
  flagCards.totalFlag += flagCards.detectionFlag.count;
620
620
  if ( resultData?.runAI ) {
621
+ resultData.runAI.flagCount = resultData.runaiflags;
621
622
  flagCards.runAIFlag = resultData?.runAI;
623
+ flagCards.totalFlag += resultData.runaiflags;
622
624
  }
623
625
  }
624
626
 
@@ -2713,6 +2715,9 @@ export const checklistDropdownV1 = async ( req, res ) => {
2713
2715
  { questionFlag: { $gte: 1 } },
2714
2716
  { timeFlag: { $gte: 1 } },
2715
2717
  { checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum' ] } },
2718
+ {
2719
+ runAIQuestionCount: { $gte: 1 },
2720
+ },
2716
2721
  ],
2717
2722
  },
2718
2723
  ] } },
@@ -3174,7 +3179,7 @@ export const flagTablesV2 = async ( req, res ) => {
3174
3179
  if ( resultData.status_code == '200' ) {
3175
3180
  for ( let index = 0; index < getChecklistPerformanceData.length; index++ ) {
3176
3181
  if ( [ 'runAI', 'all' ].includes( requestData?.filter ) ) {
3177
- let findCheckList = resultData.runAI.list.find( ( ele ) => ele.checkListName == getChecklistPerformanceData[index].checkListName );
3182
+ let findCheckList = resultData?.runAI?.list?.find( ( ele ) => ele.checkListName == getChecklistPerformanceData[index].checkListName );
3178
3183
  if ( findCheckList ) {
3179
3184
  if ( requestData?.filter == 'all' ) {
3180
3185
  getChecklistPerformanceData[index].runAIFlag = findCheckList.flagCount;
@@ -3186,7 +3191,7 @@ export const flagTablesV2 = async ( req, res ) => {
3186
3191
  } else {
3187
3192
  if ( requestData?.filter == 'all' ) {
3188
3193
  getChecklistPerformanceData[index].runAIFlag = 0;
3189
- getChecklistPerformanceData[index].runAIFlagStore = 0;
3194
+ getChecklistPerformanceData[index].flaggedStores = 0;
3190
3195
  } else {
3191
3196
  getChecklistPerformanceData[index].flagCount = 0;
3192
3197
  getChecklistPerformanceData[index].flaggedStores = 0;
@@ -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
+ };