tango-app-api-trax 3.8.16-nike → 3.8.17-nike

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.8.16-nike",
3
+ "version": "3.8.17-nike",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -465,6 +465,11 @@ export async function redoChecklist( req, res ) {
465
465
  let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn.qno == parseInt( ele ) );
466
466
  let element = { ...question[sectionIndex].questions[eleIndex], redo: true, redoComment: '', linkquestionenabled: false };
467
467
  question[sectionIndex].questions[eleIndex] = element;
468
+ question[sectionIndex].questions[eleIndex].answers.forEach( ( ans ) => {
469
+ ans.validationAnswer = '';
470
+ delete ans.redoComment;
471
+ delete ans.redo;
472
+ } );
468
473
  question[sectionIndex].questions[eleIndex].userAnswer = [];
469
474
  question[sectionIndex].questions[eleIndex].remarks = '';
470
475
  } );
@@ -523,6 +528,13 @@ export async function redoChecklist( req, res ) {
523
528
  }
524
529
  } else {
525
530
  question[sectionIndex].questions[findQuestion].userAnswer = [];
531
+ if ( Array.isArray( question[sectionIndex].questions[findQuestion].answers ) ) {
532
+ question[sectionIndex].questions[findQuestion].answers.forEach( ( ans ) => {
533
+ ans.validationAnswer = '';
534
+ delete ans.redoComment;
535
+ delete ans.redo;
536
+ } );
537
+ }
526
538
  question[sectionIndex].questions[findQuestion].remarks = '';
527
539
  }
528
540
  checklistDetails.questionAnswers = question;
@@ -532,7 +544,7 @@ export async function redoChecklist( req, res ) {
532
544
  reinitiateStatus: true,
533
545
  questionAnswers: question,
534
546
  ...( checklistDetails.checklistStatus != 'submit' && checklistDetails.redoStatus ) ? { redoEdit: true } : {},
535
- ...( !Object.prototype.hasOwnProperty.call( checklistDetails, 'redoEdit' ) && { scheduleEndTime_iso: dayjs( checklistDetails.scheduleEndTime_iso ).add( checklistConfigDetails.redoValidity, 'day' ).format() } ),
547
+ ...( ( checklistDetails.redoEdit === undefined && checklistConfigDetails.redoValidity ) && { scheduleEndTime_iso: dayjs( checklistDetails.scheduleEndTime_iso ).add( checklistConfigDetails.redoValidity, 'day' ).format() } ),
536
548
  };
537
549
 
538
550
  let response = await processedChecklist.updateOne( { _id: req.body.payload._id }, updateData );
@@ -2643,6 +2643,9 @@ export async function updateRunAI( req, res ) {
2643
2643
  if ( !req.body.qName ) {
2644
2644
  return res.sendError( 'Question name is required', 400 );
2645
2645
  }
2646
+ if ( !req.body.userAnswer ) {
2647
+ return res.sendError( 'answer is required', 400 );
2648
+ }
2646
2649
  let getDetails = await processedchecklist.findOne( { _id: req.body.id } );
2647
2650
  if ( !getDetails ) {
2648
2651
  return res.sendError( 'No data found', 204 );
@@ -2651,7 +2654,7 @@ export async function updateRunAI( req, res ) {
2651
2654
  let updateData = {};
2652
2655
 
2653
2656
  for ( let k of Object.keys( req.body.data ) ) {
2654
- let keyPath = `questionAnswers.$[section].questions.$[question].userAnswer.0.${k}`;
2657
+ let keyPath = `questionAnswers.$[section].questions.$[question].userAnswer.$[userAnswer].${k}`;
2655
2658
  updateData[keyPath] = req.body.data[k];
2656
2659
  }
2657
2660
 
@@ -2662,7 +2665,9 @@ export async function updateRunAI( req, res ) {
2662
2665
  arrayFilters: [
2663
2666
  { 'section.section_id': new ObjectId( req.body.sectionId ) },
2664
2667
  { 'question.qname': req.body.qName },
2668
+ { 'userAnswer.answer': req.body.userAnswer },
2665
2669
  ],
2670
+ strict: false,
2666
2671
  },
2667
2672
  );
2668
2673
  return res.sendSuccess( 'RunAI details updated successfully' );
@@ -118,7 +118,7 @@ export async function startChecklist( req, res ) {
118
118
  $and: [
119
119
  { _id: new ObjectId( requestData.processedcheckListId ) },
120
120
  { userId: req.user._id },
121
- { date_string: requestData.date },
121
+ { $or: [ { date_string: requestData.date }, { redoStatus: true } ] },
122
122
  ],
123
123
  },
124
124
  } );
@@ -1177,24 +1177,29 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1177
1177
  if ( qaAnswers[j].answerType == 'yes/no' ) {
1178
1178
  let qaans = qaAnswers[j].answers;
1179
1179
  let yn = [];
1180
- for ( let k = 0; k < qaans.length; k++ ) {
1181
- if ( requestSection[i].answer == qaans[k].answer ) {
1182
- if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
1183
- if ( requestSection[i].validationAnswer ) {
1184
- let validateAns = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
1185
- if ( validateAns.length ) {
1186
- let splitImgUrl = validateAns.split( '/' );
1187
- if ( splitImgUrl.length > 1 ) {
1188
- splitImgUrl.splice( 0, 3 );
1189
- qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
1180
+ if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
1181
+ for ( let k = 0; k < qaans.length; k++ ) {
1182
+ if ( requestSection[i].answer == qaans[k].answer ) {
1183
+ if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
1184
+ if ( requestSection[i].validationAnswer ) {
1185
+ let validateAns = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
1186
+ if ( validateAns.length ) {
1187
+ let splitImgUrl = validateAns.split( '/' );
1188
+ if ( splitImgUrl.length > 1 ) {
1189
+ splitImgUrl.splice( 0, 3 );
1190
+ qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
1191
+ }
1190
1192
  }
1191
1193
  }
1194
+ } else {
1195
+ // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1196
+ qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
1192
1197
  }
1193
- } else {
1194
- // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1195
- qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
1198
+ if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
1199
+ qaans[k].runAIData = requestSection[i].runAIData;
1200
+ }
1201
+ yn.push( qaans[k] );
1196
1202
  }
1197
- yn.push( qaans[k] );
1198
1203
  }
1199
1204
  }
1200
1205
  let structure = {};
@@ -1234,39 +1239,44 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1234
1239
  } else if ( qaAnswers[j].answerType == 'multiplechoicesingle' || ( qaAnswers[j].answerType == 'dropdown' && !qaAnswers[j].allowMultiple ) ) {
1235
1240
  let qaans = qaAnswers[j].answers;
1236
1241
  let ms = [];
1237
- for ( let k = 0; k < qaans.length; k++ ) {
1238
- if ( requestSection[i].answer == qaans[k].answer ) {
1239
- if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
1240
- if ( requestSection[i].validationAnswer ) {
1241
- let validationAnswer = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
1242
- if ( validationAnswer.length ) {
1243
- let splitImgUrl = validationAnswer.split( '/' );
1244
- if ( splitImgUrl.length > 1 ) {
1245
- splitImgUrl.splice( 0, 3 );
1246
- qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
1242
+ if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
1243
+ for ( let k = 0; k < qaans.length; k++ ) {
1244
+ if ( requestSection[i].answer == qaans[k].answer ) {
1245
+ if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
1246
+ if ( requestSection[i].validationAnswer ) {
1247
+ let validationAnswer = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
1248
+ if ( validationAnswer.length ) {
1249
+ let splitImgUrl = validationAnswer.split( '/' );
1250
+ if ( splitImgUrl.length > 1 ) {
1251
+ splitImgUrl.splice( 0, 3 );
1252
+ qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
1253
+ }
1247
1254
  }
1248
1255
  }
1249
- }
1250
- } else {
1251
- if ( qaans[k].validationType == 'Capture Multiple Image with description' ) {
1252
- qaans[k]['validationImage']=[];
1253
- if ( requestSection[i].validationImage.length ) {
1254
- for ( let image of requestSection[i].validationImage ) {
1255
- let validationAnswer = decodeURIComponent( image.split( '?' )[0] );
1256
- if ( validationAnswer.length ) {
1257
- let splitImgUrl = validationAnswer.split( '/' );
1258
- if ( splitImgUrl.length > 1 ) {
1259
- splitImgUrl.splice( 0, 3 );
1260
- qaans[k].validationImage.push( splitImgUrl.join( '/' ) || '' );
1261
- }
1262
- };
1256
+ } else {
1257
+ if ( qaans[k].validationType == 'Capture Multiple Image with description' ) {
1258
+ qaans[k]['validationImage']=[];
1259
+ if ( requestSection[i].validationImage.length ) {
1260
+ for ( let image of requestSection[i].validationImage ) {
1261
+ let validationAnswer = decodeURIComponent( image.split( '?' )[0] );
1262
+ if ( validationAnswer.length ) {
1263
+ let splitImgUrl = validationAnswer.split( '/' );
1264
+ if ( splitImgUrl.length > 1 ) {
1265
+ splitImgUrl.splice( 0, 3 );
1266
+ qaans[k].validationImage.push( splitImgUrl.join( '/' ) || '' );
1267
+ }
1268
+ };
1269
+ }
1263
1270
  }
1264
1271
  }
1272
+ // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1273
+ qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
1265
1274
  }
1266
- // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1267
- qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
1275
+ if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
1276
+ qaans[k].runAIData = requestSection[i].runAIData;
1277
+ }
1278
+ ms.push( qaans[k] );
1268
1279
  }
1269
- ms.push( qaans[k] );
1270
1280
  }
1271
1281
  }
1272
1282
  let structure = {};
@@ -1307,29 +1317,33 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1307
1317
  } else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' || ( qaAnswers[j].answerType == 'dropdown' && qaAnswers[j].allowMultiple ) ) {
1308
1318
  let qaans = qaAnswers[j].answers;
1309
1319
  let mcmo = [];
1310
- for ( let k = 0; k < qaans.length; k++ ) {
1311
- let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
1312
- for ( let s = 0; s < separatedArray.length; s++ ) {
1313
- if ( ( separatedArray[s].answer == qaans[k].answer ) ) {
1314
- if ( ( getChecklistQA?.redoEdit && qaans[k].redo == separatedArray[s].redo ) || !getChecklistQA?.redoEdit ) {
1315
- if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
1316
- if ( separatedArray[s].validationAnswer ) {
1317
- let validationAnswer = decodeURIComponent( separatedArray[s].validationAnswer.split( '?' )[0] );
1318
- if ( validationAnswer.length ) {
1319
- let splitImgUrl = validationAnswer.split( '/' );
1320
- if ( splitImgUrl.length > 1 ) {
1321
- splitImgUrl.splice( 0, 3 );
1322
- qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
1320
+ if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
1321
+ for ( let k = 0; k < qaans.length; k++ ) {
1322
+ let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
1323
+ for ( let s = 0; s < separatedArray.length; s++ ) {
1324
+ if ( ( separatedArray[s].answer == qaans[k].answer ) ) {
1325
+ if ( ( getChecklistQA?.redoEdit && qaans[k].redo == separatedArray[s].redo ) || !getChecklistQA?.redoEdit ) {
1326
+ if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
1327
+ if ( separatedArray[s].validationAnswer ) {
1328
+ let validationAnswer = decodeURIComponent( separatedArray[s].validationAnswer.split( '?' )[0] );
1329
+ if ( validationAnswer.length ) {
1330
+ let splitImgUrl = validationAnswer.split( '/' );
1331
+ if ( splitImgUrl.length > 1 ) {
1332
+ splitImgUrl.splice( 0, 3 );
1333
+ qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
1334
+ }
1323
1335
  }
1324
1336
  }
1337
+ } else {
1338
+ // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1339
+ qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
1340
+ }
1341
+ if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
1342
+ qaans[k].runAIData = separatedArray[s].runAIData;
1325
1343
  }
1326
- } else {
1327
- // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1328
- qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
1329
1344
  }
1345
+ mcmo.push( qaans[k] );
1330
1346
  }
1331
-
1332
- mcmo.push( qaans[k] );
1333
1347
  }
1334
1348
  }
1335
1349
  }
@@ -1377,37 +1391,42 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1377
1391
  } else if ( [ 'image/video', 'multipleImage' ].includes( qaAnswers[j].answerType ) ) {
1378
1392
  let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
1379
1393
  let mcmi = [];
1394
+ if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
1380
1395
  // for (let k = 0; k < qaans.length; k++) {
1381
- for ( let s = 0; s < separatedArray.length; s++ ) {
1382
- if ( separatedArray[s].answer && separatedArray[s].answer !='' ) {
1383
- let newAnswer = {};
1384
- let validationAnswer = decodeURIComponent( separatedArray[s].answer.split( '?' )[0] );
1385
- if ( validationAnswer.length ) {
1386
- let splitImgUrl = validationAnswer.split( '/' );
1387
- if ( splitImgUrl.length > 1 ) {
1388
- splitImgUrl.splice( 0, 3 );
1389
- newAnswer.answer = splitImgUrl.join( '/' ) || '';
1396
+ for ( let s = 0; s < separatedArray.length; s++ ) {
1397
+ if ( separatedArray[s].answer && separatedArray[s].answer !='' ) {
1398
+ let newAnswer = {};
1399
+ let validationAnswer = decodeURIComponent( separatedArray[s].answer.split( '?' )[0] );
1400
+ if ( validationAnswer.length ) {
1401
+ let splitImgUrl = validationAnswer.split( '/' );
1402
+ if ( splitImgUrl.length > 1 ) {
1403
+ splitImgUrl.splice( 0, 3 );
1404
+ newAnswer.answer = splitImgUrl.join( '/' ) || '';
1405
+ }
1390
1406
  }
1391
- }
1392
1407
 
1393
- newAnswer.answeroptionNumber = 0;
1394
- newAnswer.sopFlag = false;
1395
- newAnswer.validation = false;
1396
- newAnswer.validationType = '';
1397
- newAnswer.referenceImage = '';
1398
- newAnswer.allowUploadfromGallery = false;
1399
- newAnswer.descriptivetype = '';
1400
- newAnswer.showLinked = false;
1401
- newAnswer.linkedQuestion = 0;
1402
- newAnswer.nestedQuestion = [];
1403
- newAnswer.index = s;
1404
- newAnswer.runAI = qaAnswers[j].answers[0]?.runAI || false;
1405
- newAnswer.runAIFeatures = qaAnswers[j].answers[0]?.runAIFeatures || [];
1406
- newAnswer.runAIDescription = qaAnswers[j].answers[0]?.runAIDescription || '';
1407
- if ( qaAnswers[j].answerType == 'image/video' ) {
1408
- newAnswer.answerType = separatedArray[s].answerType;
1408
+ newAnswer.answeroptionNumber = 0;
1409
+ newAnswer.sopFlag = false;
1410
+ newAnswer.validation = false;
1411
+ newAnswer.validationType = '';
1412
+ newAnswer.referenceImage = '';
1413
+ newAnswer.allowUploadfromGallery = false;
1414
+ newAnswer.descriptivetype = '';
1415
+ newAnswer.showLinked = false;
1416
+ newAnswer.linkedQuestion = 0;
1417
+ newAnswer.nestedQuestion = [];
1418
+ newAnswer.index = s;
1419
+ newAnswer.runAI = qaAnswers[j].answers[0]?.runAI || false;
1420
+ newAnswer.runAIFeatures = qaAnswers[j].answers[0]?.runAIFeatures || [];
1421
+ newAnswer.runAIDescription = qaAnswers[j].answers[0]?.runAIDescription || '';
1422
+ if ( qaAnswers[j].answerType == 'image/video' ) {
1423
+ newAnswer.answerType = separatedArray[s].answerType;
1424
+ }
1425
+ if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
1426
+ newAnswer.runAIData = separatedArray[s].runAIData;
1427
+ }
1428
+ mcmi.push( newAnswer );
1409
1429
  }
1410
- mcmi.push( newAnswer );
1411
1430
  }
1412
1431
  }
1413
1432
  // }
@@ -1447,71 +1466,76 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1447
1466
  newArray.push( structure );
1448
1467
  } else {
1449
1468
  let des = [];
1450
- if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
1451
- let validationAnswer = '';
1452
- if ( requestSection[i].answer.split( '?' ).length > 1 || requestSection[i].answer.includes( 'https://' ) ) {
1453
- validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
1454
- }
1455
- if ( validationAnswer.length ) {
1456
- let splitImgUrl = validationAnswer.split( '/' );
1457
- if ( splitImgUrl.length > 1 ) {
1458
- splitImgUrl.splice( 0, 3 );
1459
- requestSection[i].answer = splitImgUrl.join( '/' );
1469
+ if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
1470
+ if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
1471
+ let validationAnswer = '';
1472
+ if ( requestSection[i].answer.split( '?' ).length > 1 || requestSection[i].answer.includes( 'https://' ) ) {
1473
+ validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
1460
1474
  }
1461
- }
1462
- let ansstructure = {
1463
- answer: requestSection[i].answer,
1464
- answeroptionNumber: 1,
1465
- sopFlag: false,
1466
- validation: false,
1467
- validationType: '',
1468
- validationAnswer: '',
1469
- referenceImage: qaAnswers[j].answers[0].referenceImage || '',
1470
- multiReferenceImage: qaAnswers[j].answers[0].multiReferenceImage || [],
1471
- showLinked: qaAnswers[j].answers[0].showLinked,
1472
- linkedQuestion: qaAnswers[j].answers[0].linkedQuestion,
1473
- runAI: qaAnswers[j].answers[0]?.runAI || false,
1474
- runAIFeatures: qaAnswers[j]?.answers[0]?.runAIFeatures || [],
1475
- runAIDescription: qaAnswers[j].answers[0]?.runAIDescription || '',
1476
- };
1477
- if ( qaAnswers[j].answerType == 'date' ) {
1478
- ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
1479
- if ( qaAnswers[j].compliance ) {
1475
+ if ( validationAnswer.length ) {
1476
+ let splitImgUrl = validationAnswer.split( '/' );
1477
+ if ( splitImgUrl.length > 1 ) {
1478
+ splitImgUrl.splice( 0, 3 );
1479
+ requestSection[i].answer = splitImgUrl.join( '/' );
1480
+ }
1481
+ }
1482
+ let ansstructure = {
1483
+ answer: requestSection[i].answer,
1484
+ answeroptionNumber: 1,
1485
+ sopFlag: false,
1486
+ validation: false,
1487
+ validationType: '',
1488
+ validationAnswer: '',
1489
+ referenceImage: qaAnswers[j].answers[0].referenceImage || '',
1490
+ multiReferenceImage: qaAnswers[j].answers[0].multiReferenceImage || [],
1491
+ showLinked: qaAnswers[j].answers[0].showLinked,
1492
+ linkedQuestion: qaAnswers[j].answers[0].linkedQuestion,
1493
+ runAI: qaAnswers[j].answers[0]?.runAI || false,
1494
+ runAIFeatures: qaAnswers[j]?.answers[0]?.runAIFeatures || [],
1495
+ runAIDescription: qaAnswers[j].answers[0]?.runAIDescription || '',
1496
+ };
1497
+ if ( qaAnswers[j].answerType == 'date' ) {
1498
+ ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
1480
1499
  if ( qaAnswers[j].compliance ) {
1481
- let ansArray = requestSection[i].answer.split( ',' );
1482
- if ( ansArray.includes( '-' ) ) {
1483
- ansArray = requestSection[i].answer.split( '-' );
1500
+ if ( qaAnswers[j].compliance ) {
1501
+ let ansArray = requestSection[i].answer.split( ',' );
1502
+ if ( ansArray.includes( '-' ) ) {
1503
+ ansArray = requestSection[i].answer.split( '-' );
1504
+ }
1505
+ if ( ansArray.length > 1 && ansArray.some( ( date ) => dayjs( date, 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate && dayjs( date, 'DD MMM YYYY' ) <= qaAnswers[j]?.answers[0]?.endDate ) ) {
1506
+ ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1507
+ } else if ( ansArray.length > 1 && ( dayjs( ansArray?.[0], 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate && dayjs( ansArray?.[1], 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) <= qaAnswers[j]?.answers[0]?.endDate ) ) {
1508
+ ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1509
+ } else if ( dayjs( requestSection[i].answer, 'DD MMM YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate && dayjs( requestSection[i].answer, 'DD MMM YYYY' ) <= qaAnswers[j]?.answers[0]?.endDate ) {
1510
+ ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1511
+ } else {
1512
+ ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
1513
+ }
1484
1514
  }
1485
- if ( ansArray.length > 1 && ansArray.some( ( date ) => dayjs( date, 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate && dayjs( date, 'DD MMM YYYY' ) <= qaAnswers[j]?.answers[0]?.endDate ) ) {
1486
- ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1487
- } else if ( ansArray.length > 1 && ( dayjs( ansArray?.[0], 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate && dayjs( ansArray?.[1], 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) <= qaAnswers[j]?.answers[0]?.endDate ) ) {
1488
- ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1489
- } else if ( dayjs( requestSection[i].answer, 'DD MMM YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate && dayjs( requestSection[i].answer, 'DD MMM YYYY' ) <= qaAnswers[j]?.answers[0]?.endDate ) {
1515
+ }
1516
+ }
1517
+ if ( qaAnswers[j].answerType == 'linearscale' ) {
1518
+ if ( qaAnswers[j].compliance ) {
1519
+ let linearAnswer = requestSection[i].answer.split( 'to' );
1520
+ if ( parseInt( linearAnswer?.[0] ) >= qaAnswers[j]?.answers[0]?.minValue && parseInt( linearAnswer?.[1] ) <= qaAnswers[j]?.answers[0]?.maxValue ) {
1490
1521
  ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1491
1522
  } else {
1492
1523
  ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
1493
1524
  }
1494
1525
  }
1526
+ ansstructure.linearType = qaAnswers[j]?.answers[0]?.linearType;
1527
+ ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
1528
+ ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
1495
1529
  }
1496
- }
1497
- if ( qaAnswers[j].answerType == 'linearscale' ) {
1498
- if ( qaAnswers[j].compliance ) {
1499
- let linearAnswer = requestSection[i].answer.split( 'to' );
1500
- if ( parseInt( linearAnswer?.[0] ) >= qaAnswers[j]?.answers[0]?.minValue && parseInt( linearAnswer?.[1] ) <= qaAnswers[j]?.answers[0]?.maxValue ) {
1501
- ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1502
- } else {
1503
- ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
1504
- }
1530
+ if ( qaAnswers[j].answerType == 'image' ) {
1531
+ ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
1532
+ ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
1505
1533
  }
1506
- ansstructure.linearType = qaAnswers[j]?.answers[0]?.linearType;
1507
- ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
1508
- ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
1509
- }
1510
- if ( qaAnswers[j].answerType == 'image' ) {
1511
- ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
1512
- ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
1534
+ if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
1535
+ ansstructure.runAIData = requestSection[i].runAIData;
1536
+ }
1537
+ des.push( ansstructure );
1513
1538
  }
1514
- des.push( ansstructure );
1515
1539
  }
1516
1540
  let structure = {};
1517
1541
  structure.qno = qaAnswers[j].qno;
@@ -2962,6 +2986,9 @@ export async function dashboardv1( req, res ) {
2962
2986
  // const { store_id, date } = req.query;
2963
2987
  const { date } = req.query;
2964
2988
  const userId = req.user._id;
2989
+ let fromDate = new Date( req.query.date );
2990
+ let toDate = new Date( req.query.date );
2991
+ toDate.setDate( toDate.getDate() + 1 );
2965
2992
 
2966
2993
  // //Get User Based Checklist //
2967
2994
  const clientId = { client_id: req.user.clientId };
@@ -2972,7 +2999,7 @@ export async function dashboardv1( req, res ) {
2972
2999
  // eslint-disable-next-line camelcase
2973
3000
  // store_id,
2974
3001
  userId,
2975
- date_string: date,
3002
+ $or: [ { date_string: date }, { $and: [ { redoStatus: true }, { scheduleEndTime_iso: { $gte: fromDate } } ] } ],
2976
3003
  timeFlagStatus: true,
2977
3004
  ...clientId,
2978
3005
  ...storeMatch,
@@ -2998,9 +3025,7 @@ export async function dashboardv1( req, res ) {
2998
3025
  },
2999
3026
  ];
3000
3027
 
3001
- let fromDate = new Date( req.query.date );
3002
- let toDate = new Date( req.query.date );
3003
- toDate.setDate( toDate.getDate() + 1 );
3028
+
3004
3029
  const taskBaseMatch = {
3005
3030
  // eslint-disable-next-line camelcase
3006
3031
  // store_id,
@@ -3049,6 +3074,8 @@ export async function dashboardv1( req, res ) {
3049
3074
  processedTask.aggregate( taskQuery ),
3050
3075
  ] );
3051
3076
 
3077
+ console.log( checklistResult );
3078
+
3052
3079
  const checklistResultData =
3053
3080
  checklistResult.status === 'fulfilled' ?
3054
3081
  processResult( checklistResult.value ) :
@@ -3178,6 +3205,9 @@ export async function checklistv1( req, res ) {
3178
3205
  // const { store_id, date, checklistStatus, searchValue } = req.query;
3179
3206
  const { date, checklistStatus, searchValue } = req.query;
3180
3207
  const userId = req.user._id;
3208
+ let fromDate = new Date( req.query.date );
3209
+ let toDate = new Date( req.query.date );
3210
+ toDate.setDate( toDate.getDate() + 1 );
3181
3211
 
3182
3212
  // Get User Based Checklist //
3183
3213
  const clientId = { client_id: req.user.clientId };
@@ -3189,16 +3219,23 @@ export async function checklistv1( req, res ) {
3189
3219
  // eslint-disable-next-line camelcase
3190
3220
  // { store_id },
3191
3221
  { userId },
3192
- { date_string: date },
3222
+ // { $or: [ { date_string: date }, { $and: [ { redoStatus: true }, { scheduleEndTime_iso: { $gte: fromDate } } ] } ] },
3193
3223
  { timeFlagStatus: true },
3194
3224
  ...matchExtraConditions,
3195
3225
  clientId,
3196
3226
  storeMatch,
3197
3227
  ];
3228
+ if ( checklistStatus != 'submit' ) {
3229
+ matchConditions.push( { $or: [ { date_string: date }, { $and: [ { redoStatus: true }, { scheduleEndTime_iso: { $gte: fromDate } } ] } ] } );
3230
+ }
3231
+ if ( checklistStatus == 'submit' ) {
3232
+ matchConditions.push( { date_string: date } );
3233
+ }
3198
3234
  if ( checklistStatus ) {
3199
3235
  matchConditions.push( { checklistStatus } );
3200
3236
  }
3201
3237
 
3238
+
3202
3239
  const pipeline = [
3203
3240
  { $match: { $and: matchConditions } },
3204
3241
  ...( searchValue ?
@@ -3251,9 +3288,7 @@ export async function checklistv1( req, res ) {
3251
3288
  return pipeline;
3252
3289
  };
3253
3290
 
3254
- let fromDate = new Date( req.query.date );
3255
- let toDate = new Date( req.query.date );
3256
- toDate.setDate( toDate.getDate() + 1 );
3291
+
3257
3292
  const taskBuildPipeline = ( matchExtraConditions = [], projectExtraConditions = {} ) => {
3258
3293
  const matchConditions = [
3259
3294
  // eslint-disable-next-line camelcase