tango-app-api-trax 3.6.1-runai-1 → 3.6.1-runai-3

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-1",
3
+ "version": "3.6.1-runai-3",
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
+ }
@@ -534,7 +534,6 @@ export const flagCardsV1 = async ( req, res ) => {
534
534
  questionFlag: { count: 0 },
535
535
  delayInSubmission: { count: 0 },
536
536
  detectionFlag: { count: 0 },
537
- runAIFlag: { flagCount: 0, list: [] },
538
537
  };
539
538
 
540
539
  let requestData = req.body;
@@ -582,7 +581,6 @@ export const flagCardsV1 = async ( req, res ) => {
582
581
  'detectionFlag': {
583
582
  'count': 0,
584
583
  },
585
- 'runAIFlag': { flagCount: 0, list: [] },
586
584
  },
587
585
  };
588
586
  return res.sendSuccess( resVal );
@@ -619,7 +617,11 @@ export const flagCardsV1 = async ( req, res ) => {
619
617
  }
620
618
  } );
621
619
  flagCards.totalFlag += flagCards.detectionFlag.count;
622
- flagCards.runAIFlag = resultData?.runAI;
620
+ if ( resultData?.runAI ) {
621
+ resultData.runAI.flagCount = resultData.runaiflags;
622
+ flagCards.runAIFlag = resultData?.runAI;
623
+ flagCards.totalFlag += resultData.runaiflags;
624
+ }
623
625
  }
624
626
 
625
627
  return res.sendSuccess( { flagCards } );
@@ -2527,7 +2529,7 @@ export const flagChecklistTableV1 = async ( req, res ) => {
2527
2529
  if ( reqestData?.filter === 'runAI' ) {
2528
2530
  resultData.aiFlagData.forEach( ( element ) => {
2529
2531
  exportdata.push( {
2530
- 'Date': element?.dateString,
2532
+ 'Date': dayjs( element.dateString ).format( 'DD MMM, YYYY' ),
2531
2533
  'Store Name': element?.storeName,
2532
2534
  'User Email': element?.spocEmail,
2533
2535
  'Detections': element?.detections,
@@ -2562,7 +2564,7 @@ export const flagChecklistTableV1 = async ( req, res ) => {
2562
2564
  if ( resultData.status_code == '200' ) {
2563
2565
  if ( reqestData?.filter === 'runAI' ) {
2564
2566
  resultData.aiFlagData = resultData.aiFlagData.map( ( ele ) => {
2565
- ele = { ...ele, date: ele.dateString, storeSpocEmail: ele?.spocEmail, checklistStatus: 'submit' };
2567
+ ele = { ...ele, date: dayjs( ele.dateString ).format( 'DD MMM, YYYY' ), storeSpocEmail: ele?.spocEmail, checklistStatus: 'submit' };
2566
2568
  return ele;
2567
2569
  } );
2568
2570
  resultData = { customData: resultData.aiFlagData, totalCount: resultData.totalCount };
@@ -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
  ] } },
@@ -3001,7 +3006,7 @@ export const flagTablesV2 = async ( req, res ) => {
3001
3006
  } else if ( requestData?.filter === 'detection' ) {
3002
3007
  findAndQuery.push( { checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum' ] } } );
3003
3008
  } else if ( requestData?.filter === 'runAI' ) {
3004
- findAndQuery.push( { runAIQuestionCount: { $gte: 1 } } );
3009
+ findAndQuery.push( { checkListName: { $in: req.body.runAIChecklistName } } );
3005
3010
  }
3006
3011
 
3007
3012
  findQuery.push( { $match: { $and: findAndQuery } } );
@@ -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
+ };