tango-app-api-trax 3.7.4-airtelv2-4 → 3.7.4-runai-airtelv2-1

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.7.4-airtelv2-4",
3
+ "version": "3.7.4-runai-airtelv2-1",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -2556,3 +2556,28 @@ export async function updateRunAI( req, res ) {
2556
2556
  return res.sendError( e, 500 );
2557
2557
  }
2558
2558
  }
2559
+
2560
+ export async function countUpdateRunAI( req, res ) {
2561
+ try {
2562
+ if ( !req.body.id ) {
2563
+ return res.sendError( 'Checklist id is required', 400 );
2564
+ }
2565
+ if ( !req.body.runAICount ) {
2566
+ return res.sendError( 'runAICount is required', 400 );
2567
+ }
2568
+ let getDetails = await processedchecklist.findOne( { _id: req.body.id } );
2569
+ if ( !getDetails ) {
2570
+ return res.sendError( 'No data found', 204 );
2571
+ }
2572
+
2573
+ let updateData = {
2574
+ runAIFlag: req.body.runAICount,
2575
+ };
2576
+
2577
+ await processedchecklist.updateOne( { _id: req.body.id }, updateData );
2578
+ return res.sendSuccess( 'RunAI Count updated successfully' );
2579
+ } catch ( e ) {
2580
+ logger.error( { functionName: 'updateRunAI', error: e } );
2581
+ return res.sendError( e, 500 );
2582
+ }
2583
+ }
@@ -1334,12 +1334,14 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1334
1334
  newAnswer.validationType = '';
1335
1335
  newAnswer.referenceImage = '';
1336
1336
  newAnswer.allowUploadfromGallery = false;
1337
- newAnswer.runAI = false;
1338
1337
  newAnswer.descriptivetype = '';
1339
1338
  newAnswer.showLinked = false;
1340
1339
  newAnswer.linkedQuestion = 0;
1341
1340
  newAnswer.nestedQuestion = [];
1342
1341
  newAnswer.index = s;
1342
+ newAnswer.runAI = qaAnswers[j].answers[0]?.runAI || false;
1343
+ newAnswer.runAIFeatures = qaAnswers[j].answers[0]?.runAIFeatures || [];
1344
+ newAnswer.runAIDescription = qaAnswers[j].answers[0]?.runAIDescription || '';
1343
1345
  mcmi.push( newAnswer );
1344
1346
  }
1345
1347
  }
@@ -1400,6 +1402,9 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1400
1402
  multiReferenceImage: qaAnswers[j].answers[0].multiReferenceImage || [],
1401
1403
  showLinked: qaAnswers[j].answers[0].showLinked,
1402
1404
  linkedQuestion: qaAnswers[j].answers[0].linkedQuestion,
1405
+ runAI: qaAnswers[j].answers[0]?.runAI || false,
1406
+ runAIFeatures: qaAnswers[j]?.answers[0]?.runAIFeatures || [],
1407
+ runAIDescription: qaAnswers[j].answers[0]?.runAIDescription || '',
1403
1408
  };
1404
1409
  if ( qaAnswers[j].answerType == 'date' ) {
1405
1410
  ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
@@ -23,6 +23,8 @@ dayjs.extend( utc );
23
23
  dayjs.extend( customParseFormat );
24
24
  import * as clusterServices from '../services/cluster.service.js';
25
25
  import * as teamsServices from '../services/teams.service.js';
26
+ import * as runAIFeatureServices from '../services/runAIFeatures.services.js';
27
+ import * as runAIRequestServices from '../services/runAIRequest.services.js';
26
28
 
27
29
 
28
30
  export const checklist = async ( req, res ) => {
@@ -334,6 +336,36 @@ export const create = async ( req, res ) => {
334
336
  insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, logObj );
335
337
  }
336
338
 
339
+ let runAIData = [];
340
+ inputBody.sections.forEach( ( element, secIdx ) => {
341
+ if ( element.questions.length ) {
342
+ element.questions.forEach( ( question ) => {
343
+ question.answers.forEach( ( ans ) => {
344
+ if ( ans.runAI ) {
345
+ runAIData.push( {
346
+ clientId: inputBody.clientId,
347
+ checkListId: checkListId,
348
+ checkListName: inputBody.checklistName,
349
+ sectionNo: secIdx + 1,
350
+ sectionName: element.name,
351
+ answer: ans.answer,
352
+ answerType: question.answerType,
353
+ qname: question.qname,
354
+ runAI: true,
355
+ runAIFeatures: ans.runAIFeatures,
356
+ multiReferenceImage: ans.multiReferenceImage,
357
+ runAIDescription: ans.runAIDescription,
358
+ } );
359
+ }
360
+ } );
361
+ } );
362
+ }
363
+ } );
364
+ await runAIRequestServices.deleteMany( { checkListId: req.params.checklistId } );
365
+ if ( runAIData.length ) {
366
+ await runAIRequestServices.insertMany( runAIData );
367
+ }
368
+
337
369
  return res.sendSuccess( { checklistId: checkListId, msg: 'CheckList Created Successfully' } );
338
370
  }
339
371
  } ).catch( ( e ) => {
@@ -1096,6 +1128,35 @@ export const update = async ( req, res ) => {
1096
1128
  };
1097
1129
  insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, logObj );
1098
1130
  }
1131
+ let runAIData = [];
1132
+ inputBody.sections.forEach( ( element, secIdx ) => {
1133
+ if ( element.questions.length ) {
1134
+ element.questions.forEach( ( question ) => {
1135
+ question.answers.forEach( ( ans ) => {
1136
+ if ( ans.runAI ) {
1137
+ runAIData.push( {
1138
+ clientId: inputBody.clientId,
1139
+ checkListId: req.params.checklistId,
1140
+ checkListName: inputBody.checklistName,
1141
+ sectionNo: secIdx + 1,
1142
+ sectionName: element.name,
1143
+ answer: ans.answer,
1144
+ answerType: question.answerType,
1145
+ qname: question.qname,
1146
+ runAI: true,
1147
+ runAIFeatures: ans.runAIFeatures,
1148
+ multiReferenceImage: ans.multiReferenceImage,
1149
+ runAIDescription: ans.runAIDescription,
1150
+ } );
1151
+ }
1152
+ } );
1153
+ } );
1154
+ }
1155
+ } );
1156
+ await runAIRequestServices.deleteMany( { checkListId: req.params.checklistId } );
1157
+ if ( runAIData.length ) {
1158
+ await runAIRequestServices.insertMany( runAIData );
1159
+ }
1099
1160
  let actionType = 'Checklist Updated';
1100
1161
  let teamsMsg;
1101
1162
  let teamsAlertUrls = process.env.teamsAlertURL ? JSON.parse( process.env.teamsAlertURL ) : '';
@@ -4561,7 +4622,6 @@ export async function updateAiConfigure( req, res ) {
4561
4622
  }
4562
4623
  }
4563
4624
 
4564
-
4565
4625
  export async function getAiDetails( req, res ) {
4566
4626
  try {
4567
4627
  let storeList = [];
@@ -4619,3 +4679,186 @@ export async function getAiDetails( req, res ) {
4619
4679
  return res.sendError( e, 500 );
4620
4680
  }
4621
4681
  }
4682
+
4683
+ export async function getRunAIFeatures( req, res ) {
4684
+ try {
4685
+ console.log( 'req.body =>', req.body );
4686
+ let reqestData = req.body;
4687
+ let getRunAIFeaturesQuery = [
4688
+ {
4689
+ $match: {
4690
+ $or: [ { client_id: reqestData.client_id }, { client_id: { $exists: false } } ],
4691
+ isdeleted: false,
4692
+ },
4693
+ },
4694
+ { $addFields: { sortOrder: { $cond: [ { $eq: [ '$featureName', 'Others' ] }, 1, 0 ] } } },
4695
+ { $sort: { sortOrder: 1, _id: 1 } },
4696
+ { $project: { client_id: 1, featureName: 1, lableName: 1 } },
4697
+ ];
4698
+ let response = await runAIFeatureServices.aggregate( getRunAIFeaturesQuery );
4699
+ if ( response && response.length > 0 ) {
4700
+ return res.sendSuccess( response );
4701
+ } else {
4702
+ return res.sendError( 'No Features Available', 204 );
4703
+ }
4704
+ } catch ( e ) {
4705
+ logger.error( { functionName: 'getRunAIFeatures', error: e } );
4706
+ return res.sendError( e, 500 );
4707
+ }
4708
+ }
4709
+
4710
+ export async function updateRunAIRequest( req, res ) {
4711
+ try {
4712
+ let inputBody = req.body;
4713
+ inputBody.createdBy = req.user.email;
4714
+ let checkRunAIRequestQuery = {
4715
+ clientId: inputBody.clientId,
4716
+ checkListId: inputBody.checkListId,
4717
+ sectionNo: inputBody.sectionNo || '',
4718
+ qname: inputBody.qname,
4719
+ answer: inputBody.answer,
4720
+ };
4721
+ let checkRunAIRequest = await runAIRequestServices.findOne( checkRunAIRequestQuery );
4722
+
4723
+ // runAI Features Updated
4724
+ let incomeFeatures = inputBody.runAIFeatures;
4725
+ for ( let i = 0; i < incomeFeatures.length; i++ ) {
4726
+ // const element = array[i];
4727
+ if ( incomeFeatures[i].featureName == 'Others' ) {
4728
+ let insertData = {
4729
+ 'client_id': inputBody.clientId,
4730
+ 'featureName': incomeFeatures[i].lableName,
4731
+ 'lableName': incomeFeatures[i].lableName,
4732
+ };
4733
+ console.log( 'insertData =>', insertData );
4734
+ await runAIFeatureServices.create( insertData );
4735
+ }
4736
+ }
4737
+ if ( checkRunAIRequest ) {
4738
+ let updateRunAIRequest = await runAIRequestServices.updateOne( checkRunAIRequestQuery, inputBody );
4739
+ if ( updateRunAIRequest ) {
4740
+ return res.sendSuccess( updateRunAIRequest );
4741
+ } else {
4742
+ return res.sendError( 'something went wrong please Try again', 500 );
4743
+ }
4744
+ } else {
4745
+ let insertRunAIRequest = await runAIRequestServices.create( inputBody );
4746
+ if ( insertRunAIRequest ) {
4747
+ return res.sendSuccess( insertRunAIRequest );
4748
+ } else {
4749
+ return res.sendError( 'something went wrong please Try again', 500 );
4750
+ }
4751
+ }
4752
+ } catch ( e ) {
4753
+ logger.error( { functionName: 'updateRunAIRequest', error: e } );
4754
+ return res.sendError( e, 500 );
4755
+ }
4756
+ }
4757
+
4758
+ export async function createChecklistName( req, res ) {
4759
+ try {
4760
+ // console.log( 'req.body =>', req.body );
4761
+ let inputBody = req.body;
4762
+ let checklistNameQuery = {
4763
+ client_id: inputBody.clientId,
4764
+ checkListName: inputBody.checkListName,
4765
+ };
4766
+ let checklistExist = await checklistService.findOne( checklistNameQuery );
4767
+ if ( checklistExist ) {
4768
+ return res.sendError( { message: 'checklist name Alrady Exist' }, 400 );
4769
+ }
4770
+
4771
+ let getMaxChecklistNumber = [
4772
+ { $match: { client_id: inputBody.clientId } },
4773
+ { $group: { _id: null, maxCheckListNumber: { $max: '$checkListNumber' } } },
4774
+ ];
4775
+ let maxChecklistNumber = await checklistService.aggregate( getMaxChecklistNumber );
4776
+
4777
+ let checkListDetails = {
4778
+ type: 'checklist',
4779
+ checkListNumber: parseInt( maxChecklistNumber[0].maxCheckListNumber ) + 1,
4780
+ checkListName: inputBody.checkListName,
4781
+ checkListDescription: inputBody.checklistDescription,
4782
+ createdBy: req.user._id,
4783
+ createdByName: req.user.userName,
4784
+ questionCount: 0,
4785
+ client_id: req.body?.clientId,
4786
+ owner: req.user.userType == 'client' ? [ { name: req.user.userName, value: req.user.email } ] : [],
4787
+ runAIQuestionCount: 0,
4788
+ };
4789
+ let response = await checklistService.create( checkListDetails );
4790
+ if ( response ) {
4791
+ let insertSection = {
4792
+ 'question': [
4793
+ {
4794
+ 'qno': 1,
4795
+ 'qname': 'Q1',
4796
+ 'answerType': 'descriptive',
4797
+ 'runAI': false,
4798
+ 'runAIDescription': '',
4799
+ 'allowUploadfromGallery': false,
4800
+ 'linkType': false,
4801
+ 'multiQuestionReferenceImage': [],
4802
+ 'descriptivetype': 'text',
4803
+ 'questionReferenceImage': '',
4804
+ 'answers': [
4805
+ {
4806
+ 'answer': '',
4807
+ 'answeroptionNumber': 1,
4808
+ 'sopFlag': false,
4809
+ 'validation': false,
4810
+ 'validationAnswer': '',
4811
+ 'validationType': '',
4812
+ 'multiReferenceImage': [],
4813
+ 'showLinked': false,
4814
+ 'linkedQuestion': 0,
4815
+ 'referenceImage': '',
4816
+ 'nestedQuestion': [],
4817
+ },
4818
+ ],
4819
+ },
4820
+ ],
4821
+ 'section': 'Section 1',
4822
+ 'checkList': inputBody.checkListName,
4823
+ 'checkListId': new ObjectId( response._id ),
4824
+ 'client_id': inputBody.clientId,
4825
+ 'isdeleted': false,
4826
+ 'sectionNumber': 1,
4827
+ };
4828
+ await questionService.create( insertSection );
4829
+ let resultData = {
4830
+ _id: response._id,
4831
+ };
4832
+ return res.sendSuccess( resultData );
4833
+ } else {
4834
+ return res.sendError( 'Something Went Wrong Please Try Again', 500 );
4835
+ }
4836
+ } catch ( e ) {
4837
+ logger.error( { functionName: 'createChecklistName', error: e } );
4838
+ return res.sendError( e, 500 );
4839
+ }
4840
+ }
4841
+
4842
+ export async function updateRunAIFeatures( req, res ) {
4843
+ try {
4844
+ let inputBody = req.body;
4845
+ let incomeFeatures = inputBody.runAIFeatures;
4846
+ for ( let i = 0; i < incomeFeatures.length; i++ ) {
4847
+ // const element = array[i];
4848
+ if ( incomeFeatures[i].featureName == 'Others' ) {
4849
+ let insertData = {
4850
+ 'clientId': inputBody.clientId,
4851
+ 'featureName': incomeFeatures[i].lableName,
4852
+ 'lableName': incomeFeatures[i].lableName,
4853
+ };
4854
+ // console.log( 'insertData =>', insertData );
4855
+ await runAIFeatureServices.updateOne( { clientId: insertData.clientId, featureName: insertData.featureName }, insertData );
4856
+ }
4857
+ }
4858
+
4859
+ return res.sendSuccess( 'Feature created successfully' );
4860
+ } catch ( e ) {
4861
+ logger.error( { functionName: 'updateRunAIFeatures', error: e } );
4862
+ return res.sendError( error, 500 );
4863
+ }
4864
+ }
@@ -339,6 +339,7 @@ export const checklistPerformance = async ( req, res ) => {
339
339
  },
340
340
  timeFlag: { $sum: '$timeFlag' },
341
341
  questionFlagCount: { $sum: '$questionFlag' },
342
+ runAIFlagCount: { $sum: '$runAIFlag' },
342
343
  checkListType: { $last: '$checkListType' },
343
344
  redo: { $sum: { $cond: [ { $eq: [ '$redoStatus', true ] }, 1, 0 ] } },
344
345
  task: {
@@ -394,7 +395,7 @@ export const checklistPerformance = async ( req, res ) => {
394
395
  },
395
396
  storeCount: 1,
396
397
  submittedChecklist: 1,
397
- flaggedChecklist: { $add: [ '$timeFlag', '$questionFlagCount' ] },
398
+ flaggedChecklist: { $add: [ '$timeFlag', '$questionFlagCount', '$runAIFlagCount' ] },
398
399
  checkListType: 1,
399
400
  redo: 1,
400
401
  task: 1,
@@ -514,6 +515,7 @@ export const storePerformance = async ( req, res ) => {
514
515
  store_id: 1,
515
516
  storeName: 1,
516
517
  userEmail: 1,
518
+ runAIFlag: 1,
517
519
  },
518
520
  } );
519
521
 
@@ -535,6 +537,7 @@ export const storePerformance = async ( req, res ) => {
535
537
  questionFlag: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionFlag', 0 ] } },
536
538
  questionCount: { $sum: '$questionCount' },
537
539
  submitQuestionCount: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionCount', 0 ] } },
540
+ runAIFlag: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$runAIFlag', 0 ] } },
538
541
  },
539
542
  } );
540
543
 
@@ -544,7 +547,7 @@ export const storePerformance = async ( req, res ) => {
544
547
  storeName: 1,
545
548
  userEmail: 1,
546
549
  checkListCount: { $sum: '$totalChecklist' },
547
- flaggedCount: { $add: [ '$timeFlag', '$questionFlag' ] },
550
+ flaggedCount: { $add: [ '$timeFlag', '$questionFlag', '$runAIFlag' ] },
548
551
  submittedChecklist: 1,
549
552
  checkListType: 1,
550
553
  questionCount: 1,
@@ -729,6 +732,7 @@ export const userPerformance = async ( req, res ) => {
729
732
  userName: 1,
730
733
  questionCount: 1,
731
734
  redoStatus: 1,
735
+ runAIFlag: 1,
732
736
  },
733
737
  } );
734
738
 
@@ -747,6 +751,7 @@ export const userPerformance = async ( req, res ) => {
747
751
  $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionCount', 0 ] },
748
752
  },
749
753
  redo: { $sum: { $cond: [ { $eq: [ '$redoStatus', true ] }, 1, 0 ] } },
754
+ runAIFlag: { $sum: '$runAIFlag' },
750
755
  },
751
756
  } );
752
757
 
@@ -754,7 +759,7 @@ export const userPerformance = async ( req, res ) => {
754
759
  findQuery.push( {
755
760
  $addFields: {
756
761
  userName: '$_id',
757
- flaggedCount: { $add: [ '$timeFlag', '$questionFlag' ] },
762
+ flaggedCount: { $add: [ '$timeFlag', '$questionFlag', '$runAIFlag' ] },
758
763
  correctAnswers: { $subtract: [ '$submittedChecklistQuestionCount', '$questionFlag' ] },
759
764
  completion: {
760
765
  $round: [
@@ -1599,6 +1604,7 @@ export const checklistInfo = async ( req, res ) => {
1599
1604
  approvalByEmail: 1,
1600
1605
  approvalTime_string: 1,
1601
1606
  _id: 1,
1607
+ runAIFlag: 1,
1602
1608
  },
1603
1609
  } );
1604
1610
 
@@ -1635,7 +1641,7 @@ export const checklistInfo = async ( req, res ) => {
1635
1641
  storeName: 1,
1636
1642
  checkListType: 1,
1637
1643
  scheduleRepeatedType: 1,
1638
- flaggedChecklist: { $add: [ '$timeFlag', '$questionFlag' ] },
1644
+ flaggedChecklist: { $add: [ '$timeFlag', '$questionFlag', '$runAIFlag' ] },
1639
1645
  timeFlag: 1,
1640
1646
  questionFlag: 1,
1641
1647
  date_iso: 1,
@@ -1650,6 +1656,7 @@ export const checklistInfo = async ( req, res ) => {
1650
1656
  approvalByEmail: 1,
1651
1657
  approvalTime_string: 1,
1652
1658
  _id: 1,
1659
+ runAIFlag: 1,
1653
1660
  },
1654
1661
  } );
1655
1662
 
@@ -2606,6 +2613,7 @@ export const overallCardsV1 = async ( req, res ) => {
2606
2613
  totalQuestionCount: { $sum: '$questionCount' },
2607
2614
  totalQuestionFlagCount: { $sum: '$questionFlag' },
2608
2615
  totalTimeFlag: { $sum: '$timeFlag' },
2616
+ totalRunAIFlag: { $sum: '$runAIFlag' },
2609
2617
  },
2610
2618
  } );
2611
2619
  findQuery.push( {
@@ -2624,6 +2632,7 @@ export const overallCardsV1 = async ( req, res ) => {
2624
2632
  questionCountSum: { $sum: '$totalQuestionCount' },
2625
2633
  questionFlagCountSum: { $sum: '$totalQuestionFlagCount' },
2626
2634
  timeFlagSum: { $sum: '$totalTimeFlag' },
2635
+ runAIFlagSum: { $sum: '$totalRunAIFlag' },
2627
2636
  },
2628
2637
  } );
2629
2638
  findQuery.push( {
@@ -2642,6 +2651,7 @@ export const overallCardsV1 = async ( req, res ) => {
2642
2651
  statusCounts: 1,
2643
2652
  submittedChecklistQuestionCount: 1,
2644
2653
  submittedChecklistFlagQuestionCount: 1,
2654
+ runAIFlagSum: 1,
2645
2655
  },
2646
2656
  } );
2647
2657
  findQuery.push( {
@@ -2651,7 +2661,7 @@ export const overallCardsV1 = async ( req, res ) => {
2651
2661
  openChecklist: { $ifNull: [ '$statusCounts.open', 0 ] },
2652
2662
  inprogressChecklist: { $ifNull: [ '$statusCounts.inprogress', 0 ] },
2653
2663
  submittedChecklist: { $ifNull: [ '$statusCounts.submit', 0 ] },
2654
- flaggedChecklist: { $add: [ { $ifNull: [ '$timeFlagSum', 0 ] }, { $ifNull: [ '$questionFlagCountSum', 0 ] } ] },
2664
+ flaggedChecklist: { $add: [ { $ifNull: [ '$timeFlagSum', 0 ] }, { $ifNull: [ '$questionFlagCountSum', 0 ] }, { $ifNull: [ '$runAIFlagSum', 0 ] } ] },
2655
2665
  completionScore: { $round: [ { $multiply: [ { $divide: [ { $ifNull: [ '$statusCounts.submit', 0 ] }, { $ifNull: [ '$totalChecklist', 0 ] } ] }, 100 ] }, 0 ] },
2656
2666
  // completionScore: { $multiply: [ { $divide: [ '$statusCounts.submit', '$totalChecklist' ] }, 100 ] },
2657
2667
  questionFlagCount: { $ifNull: [ '$questionFlagCountSum', 0 ] },
@@ -2857,6 +2867,7 @@ export const overallComparisonCardsV1 = async ( req, res ) => {
2857
2867
  totalQuestionCount: { $sum: '$questionCount' },
2858
2868
  totalQuestionFlagCount: { $sum: '$questionFlag' },
2859
2869
  totalTimeFlag: { $sum: '$timeFlag' },
2870
+ totalRunAIFlag: { $sum: '$runAIFlag' },
2860
2871
  },
2861
2872
  },
2862
2873
  {
@@ -2875,6 +2886,7 @@ export const overallComparisonCardsV1 = async ( req, res ) => {
2875
2886
  questionCountSum: { $sum: '$totalQuestionCount' },
2876
2887
  questionFlagCountSum: { $sum: '$totalQuestionFlagCount' },
2877
2888
  timeFlagSum: { $sum: '$totalTimeFlag' },
2889
+ runAIFlagSum: { $sum: '$totalRunAIFlag' },
2878
2890
  },
2879
2891
  },
2880
2892
  {
@@ -2893,6 +2905,7 @@ export const overallComparisonCardsV1 = async ( req, res ) => {
2893
2905
  statusCounts: 1,
2894
2906
  submittedChecklistQuestionCount: 1,
2895
2907
  submittedChecklistFlagQuestionCount: 1,
2908
+ runAIFlagSum: 1,
2896
2909
  },
2897
2910
  },
2898
2911
  {
@@ -2902,7 +2915,7 @@ export const overallComparisonCardsV1 = async ( req, res ) => {
2902
2915
  openChecklist: { $ifNull: [ '$statusCounts.open', 0 ] },
2903
2916
  inprogressChecklist: { $ifNull: [ '$statusCounts.inprogress', 0 ] },
2904
2917
  submittedChecklist: { $ifNull: [ '$statusCounts.submit', 0 ] },
2905
- flaggedChecklist: { $add: [ { $ifNull: [ '$timeFlagSum', 0 ] }, { $ifNull: [ '$questionFlagCountSum', 0 ] } ] },
2918
+ flaggedChecklist: { $add: [ { $ifNull: [ '$timeFlagSum', 0 ] }, { $ifNull: [ '$questionFlagCountSum', 0 ] }, { $ifNull: [ '$runAIFlagSum', 0 ] } ] },
2906
2919
  completionScore: { $round: [ { $multiply: [ { $divide: [ { $ifNull: [ '$statusCounts.submit', 0 ] }, { $ifNull: [ '$totalChecklist', 0 ] } ] }, 100 ] }, 0 ] },
2907
2920
  // completionScore: { $multiply: [ { $divide: [ '$statusCounts.submit', '$totalChecklist' ] }, 100 ] },
2908
2921
  questionFlagCount: { $ifNull: [ '$questionFlagCountSum', 0 ] },
@@ -157,4 +157,32 @@ export const selectAssign = {
157
157
  body: selectAssignSchema,
158
158
  };
159
159
 
160
+ export const createChecklistNameSchema = joi.object( {
161
+ clientId: joi.string().required(),
162
+ checkListName: joi.string().required(),
163
+ checklistDescription: joi.string().optional(),
164
+ } );
165
+
166
+ export const createChecklistNameValidation = {
167
+ body: createChecklistNameSchema,
168
+ };
169
+
170
+ export const runAIRequestSchema = joi.object( {
171
+ clientId: joi.string().required(),
172
+ checkListId: joi.string().required(),
173
+ checkListName: joi.string().optional().allow( '' ),
174
+ sectionNo: joi.number().required(),
175
+ sectionName: joi.string().optional().allow( '' ),
176
+ qname: joi.string().required(),
177
+ answerType: joi.string().optional().allow( '' ),
178
+ answer: joi.string().optional().allow( '' ),
179
+ runAI: joi.boolean().required(),
180
+ runAIFeatures: joi.array().optional().allow( '' ),
181
+ referenceImages: joi.array().items( joi.any() ).min( 0 ),
182
+ } );
183
+
184
+ export const runAIRequestValidation = {
185
+ body: runAIRequestSchema,
186
+ };
187
+
160
188
 
@@ -26,6 +26,7 @@ internalTraxRouter
26
26
  .post( '/getLiveChecklistClients', isAllowedInternalAPIHandler, internalController.getLiveChecklistClients )
27
27
  .post( '/notificationCreate', isAllowedInternalAPIHandler, internalController.notificationCreate )
28
28
  .post( '/insertAINotification', isAllowedInternalAPIHandler, internalController.insertAINotification )
29
- .post( '/updateRunAI', isAllowedInternalAPIHandler, internalController.updateRunAI );
29
+ .post( '/updateRunAI', isAllowedInternalAPIHandler, internalController.updateRunAI )
30
+ .post( '/countUpdateRunAI', isAllowedInternalAPIHandler, internalController.countUpdateRunAI );
30
31
 
31
32
 
@@ -1,6 +1,6 @@
1
1
  import express from 'express';
2
2
  import { isAllowedSessionHandler, validate, accessVerification, isAllowedClient } from 'tango-app-api-middleware';
3
- import { checklistValidation, checklistDetailsValidation, runaiValidation, checklistPageSchema, duplicateValidation, updateChecklistValidation, uploadUserValidation, aichecklistValidation, publishValidation, selectAssign } from '../dtos/validation.dtos.js';
3
+ import { checklistValidation, checklistDetailsValidation, runaiValidation, checklistPageSchema, duplicateValidation, updateChecklistValidation, uploadUserValidation, aichecklistValidation, publishValidation, selectAssign, createChecklistNameValidation, runAIRequestValidation } from '../dtos/validation.dtos.js';
4
4
  import * as traxController from '../controllers/trax.controller.js';
5
5
 
6
6
  export const traxRouter = express.Router();
@@ -30,7 +30,10 @@ traxRouter
30
30
  // .post( '/assignUpload', isAllowedSessionHandler, traxController.assignChecklistUser )
31
31
  .post( '/updateAssign', isAllowedSessionHandler, traxController.updateAssign )
32
32
  .post( '/updateAiConfigure', isAllowedSessionHandler, traxController.updateAiConfigure )
33
- .get( '/getAiDetails', isAllowedSessionHandler, traxController.getAiDetails );
34
- ;
33
+ .get( '/getAiDetails', isAllowedSessionHandler, traxController.getAiDetails )
34
+ .post( '/getRunAIFeatures', isAllowedSessionHandler, traxController.getRunAIFeatures )
35
+ .post( '/updateRunAIFeatures', isAllowedSessionHandler, traxController.updateRunAIFeatures )
36
+ .post( '/updateRunAIRequest', isAllowedSessionHandler, validate( runAIRequestValidation ), traxController.updateRunAIRequest )
37
+ .post( '/createChecklistName', isAllowedSessionHandler, validate( createChecklistNameValidation ), traxController.createChecklistName );
35
38
 
36
39
  // isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ),
@@ -0,0 +1,31 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export const findOne = async ( query={}, field={} ) => {
4
+ return model.runAIFeaturesModel.findOne( query, field );
5
+ };
6
+
7
+ export const find = async ( query={}, field={} ) => {
8
+ return model.runAIFeaturesModel.find( query, field );
9
+ };
10
+
11
+ export const create = async ( document = {} ) => {
12
+ return model.runAIFeaturesModel.create( document );
13
+ };
14
+
15
+ export const deleteOne = async ( query = {} ) => {
16
+ return model.runAIFeaturesModel.deleteOne( query );
17
+ };
18
+
19
+ export const updateOne = async ( query = {}, record={} ) => {
20
+ return model.runAIFeaturesModel.updateOne( query, { $set: record }, { upsert: true } );
21
+ };
22
+
23
+ export const aggregate = async ( query = {} ) => {
24
+ return model.runAIFeaturesModel.aggregate( query );
25
+ };
26
+
27
+ export const count = async ( query = {} ) => {
28
+ return model.runAIFeaturesModel.countDocuments( query );
29
+ };
30
+
31
+
@@ -0,0 +1,39 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export const findOne = async ( query={}, field={} ) => {
4
+ return model.runAIRequestModel.findOne( query, field );
5
+ };
6
+
7
+ export const find = async ( query={}, field={} ) => {
8
+ return model.runAIRequestModel.find( query, field );
9
+ };
10
+
11
+ export const create = async ( document = {} ) => {
12
+ return model.runAIRequestModel.create( document );
13
+ };
14
+
15
+ export const insertMany = async ( document = {} ) => {
16
+ return model.runAIRequestModel.insertMany( document );
17
+ };
18
+
19
+ export const deleteMany = async ( query = {} ) => {
20
+ return model.runAIRequestModel.deleteMany( query );
21
+ };
22
+
23
+ export const deleteOne = async ( query = {} ) => {
24
+ return model.runAIRequestModel.deleteOne( query );
25
+ };
26
+
27
+ export const updateOne = async ( query = {}, record={} ) => {
28
+ return model.runAIRequestModel.updateOne( query, { $set: record } );
29
+ };
30
+
31
+ export const aggregate = async ( query = {} ) => {
32
+ return model.runAIRequestModel.aggregate( query );
33
+ };
34
+
35
+ export const count = async ( query = {} ) => {
36
+ return model.runAIRequestModel.countDocuments( query );
37
+ };
38
+
39
+