tango-app-api-trax 3.8.29 → 3.8.31

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.29",
3
+ "version": "3.8.31",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -29,7 +29,7 @@
29
29
  "nodemon": "^3.1.4",
30
30
  "path": "^0.12.7",
31
31
  "puppeteer": "^24.39.1",
32
- "tango-api-schema": "^2.5.88",
32
+ "tango-api-schema": "^2.5.96",
33
33
  "tango-app-api-middleware": "^3.5.2",
34
34
  "url": "^0.11.4",
35
35
  "winston": "^3.13.1",
@@ -436,12 +436,14 @@ export async function redoChecklist( req, res ) {
436
436
  }
437
437
 
438
438
 
439
- let checklistDetails = await processedChecklist.findOne( { _id: req.body.payload._id }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1, submitTime: 1, userName: 1, answerType: 1, coverage: 1, userEmail: 1 } );
439
+ let checklistDetails = await processedChecklist.findOne( { _id: req.body.payload._id }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1, submitTime: 1, userName: 1, answerType: 1, coverage: 1, userEmail: 1, scheduleEndTime_iso: 1, redoEdit: 1 } );
440
+
440
441
  if ( !checklistDetails ) {
441
442
  return res.sendError( 'No data found', 204 );
442
443
  }
443
444
  let question = checklistDetails.questionAnswers;
444
445
 
446
+ let checklistConfigDetails = await checklistService.findOne( { _id: checklistDetails.sourceCheckList_id }, { redoValidity: 1 } );
445
447
 
446
448
  let sectionIndex = question.findIndex( ( sec ) => sec.sectionName == req.body.payload.sectionName );
447
449
  if ( sectionIndex == -1 ) {
@@ -450,38 +452,98 @@ export async function redoChecklist( req, res ) {
450
452
 
451
453
  let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.qno == req.body.payload.qno );
452
454
 
453
- let data = { ...question[sectionIndex].questions[findQuestion], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
454
- // if ( checklistDetails.client_id == '458' ) {
455
- data.answers.forEach( ( item ) => {
456
- if ( item.showLinked ) {
457
- item.nestedQuestion.forEach( ( ele ) => {
458
- let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn.qno == parseInt( ele ) );
459
- let element = { ...question[sectionIndex].questions[eleIndex], redo: true, redoComment: '', linkquestionenabled: false };
460
- question[sectionIndex].questions[eleIndex] = element;
461
- question[sectionIndex].questions[eleIndex].userAnswer = [];
462
- question[sectionIndex].questions[eleIndex].remarks = '';
455
+ let data = { ...question[sectionIndex].questions[findQuestion], redo: true, ...( !req.body.payload?.answerIndex && { redoComment: req.body.payload?.checklistDescription || '' } ) };
456
+ let answerIndex = req.body.payload?.answerIndex;
457
+ let isSingleAnswerRedo = answerIndex != null;
458
+
459
+ if ( !isSingleAnswerRedo ) {
460
+ // if ( checklistDetails.client_id == '458' ) {
461
+ data.answers.forEach( ( item ) => {
462
+ if ( item.showLinked ) {
463
+ item.nestedQuestion.forEach( ( ele ) => {
464
+ let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn.qno == parseInt( ele ) );
465
+ let element = { ...question[sectionIndex].questions[eleIndex], redo: true, redoComment: '', linkquestionenabled: false };
466
+ question[sectionIndex].questions[eleIndex] = element;
467
+ question[sectionIndex].questions[eleIndex].answers.forEach( ( ans ) => {
468
+ ans.validationAnswer = '';
469
+ delete ans.redoComment;
470
+ delete ans.redo;
471
+ } );
472
+ question[sectionIndex].questions[eleIndex].userAnswer = [];
473
+ question[sectionIndex].questions[eleIndex].remarks = '';
474
+ } );
475
+ }
476
+ } );
477
+ // data.answers.forEach( ( item ) => {
478
+ // if ( item.showLinked ) {
479
+ // item.nestedQuestion = [];
480
+ // item.showLinked = false;
481
+ // item.linkedQuestion = 0;
482
+ // }
483
+ // } );
484
+ // }
485
+ }
486
+ let userAnswer = Array.isArray( data.userAnswer ) ? [ ...data.userAnswer ] : [];
487
+
488
+ question[sectionIndex].questions[findQuestion] = data;
489
+ if ( isSingleAnswerRedo ) {
490
+ let targetQuestion = question[sectionIndex].questions[findQuestion];
491
+ let targetUserAnswerIndex = targetQuestion.userAnswer?.findIndex( ( ele ) => ele.answer == req.body.payload.answerName );
492
+ let targetUserAnswer = targetQuestion.userAnswer[targetUserAnswerIndex];
493
+ if ( targetUserAnswer && Array.isArray( targetQuestion.answers ) ) {
494
+ let matchedAnsIdx = targetQuestion.answers.findIndex( ( ans ) => {
495
+ // if ( targetUserAnswer.no !== undefined && ans.index === targetUserAnswer.no ) return true;
496
+ // if ( targetUserAnswer.index !== undefined && ans.index === targetUserAnswer.index ) return true;
497
+ // if ( targetUserAnswer.answeroptionNumber !== undefined && ans.answeroptionNumber === targetUserAnswer.answeroptionNumber ) return true;
498
+ return ans.answer === targetUserAnswer.answer;
463
499
  } );
500
+ if ( matchedAnsIdx !== -1 ) {
501
+ targetQuestion.answers[matchedAnsIdx].redo = true;
502
+ targetQuestion.answers[matchedAnsIdx].validationAnswer = '';
503
+ targetQuestion.answers[matchedAnsIdx].redoComment = req.body.payload?.checklistDescription || '';
504
+ targetQuestion.remarks = '';
505
+ }
506
+ targetQuestion.userAnswer.splice( targetUserAnswerIndex, 1 );
464
507
  }
465
- } );
466
- // data.answers.forEach( ( item ) => {
467
- // if ( item.showLinked ) {
468
- // item.nestedQuestion = [];
469
- // item.showLinked = false;
470
- // item.linkedQuestion = 0;
471
- // }
472
- // } );
473
- // }
474
- let userAnswer = data.userAnswer;
475
508
 
476
- question[sectionIndex].questions[findQuestion] = data;
477
- question[sectionIndex].questions[findQuestion].userAnswer = [];
478
- question[sectionIndex].questions[findQuestion].remarks = '';
509
+ let currentQno = req.body.payload.qno;
510
+ let parentQIndex = -1;
511
+ // let parentAnsIndex = -1;
512
+ for ( let i = 0; i < question[sectionIndex].questions.length; i++ ) {
513
+ let parentAnswers = question[sectionIndex].questions[i].answers || [];
514
+ let foundAnsIdx = parentAnswers.findIndex( ( ans ) => Array.isArray( ans?.nestedQuestion ) && ans.nestedQuestion.some( ( ele ) => parseInt( ele ) == currentQno ) );
515
+ if ( foundAnsIdx !== -1 ) {
516
+ parentQIndex = i;
517
+ // parentAnsIndex = foundAnsIdx;
518
+ break;
519
+ }
520
+ }
521
+ if ( parentQIndex !== -1 ) {
522
+ let parentQno = question[sectionIndex].questions[parentQIndex].qno;
523
+ question[sectionIndex].questions[findQuestion].parentQno = parentQno;
524
+ // question[sectionIndex].questions[findQuestion].remarks = '';
525
+ // question[sectionIndex].questions[parentQIndex].answers[parentAnsIndex].redo = true;
526
+ // question[sectionIndex].questions[parentQIndex].answers[parentAnsIndex].validationAnswer = '';
527
+ }
528
+ } else {
529
+ question[sectionIndex].questions[findQuestion].userAnswer = [];
530
+ if ( Array.isArray( question[sectionIndex].questions[findQuestion].answers ) ) {
531
+ question[sectionIndex].questions[findQuestion].answers.forEach( ( ans ) => {
532
+ ans.validationAnswer = '';
533
+ delete ans.redoComment;
534
+ delete ans.redo;
535
+ } );
536
+ }
537
+ question[sectionIndex].questions[findQuestion].remarks = '';
538
+ }
479
539
  checklistDetails.questionAnswers = question;
480
540
  let updateData = {
481
- checklistStatus: 'open',
541
+ checklistStatus: checklistDetails.checklistStatus != 'submit' ? checklistDetails.checklistStatus : 'open',
482
542
  redoStatus: true,
483
543
  reinitiateStatus: true,
484
544
  questionAnswers: question,
545
+ ...( checklistDetails.checklistStatus != 'submit' && checklistDetails.redoStatus ) ? { redoEdit: true } : {},
546
+ ...( ( checklistDetails.redoEdit === undefined && checklistConfigDetails.redoValidity ) && { scheduleEndTime_iso: dayjs( checklistDetails.scheduleEndTime_iso ).add( checklistConfigDetails.redoValidity, 'day' ).format() } ),
485
547
  };
486
548
 
487
549
  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
  } );
@@ -1082,12 +1082,15 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1082
1082
  try {
1083
1083
  let requestData = req.body;
1084
1084
  requestData.questionAnswers = typeof requestData.questionAnswers == 'string' ? JSON.parse( requestData.questionAnswers ) : requestData.questionAnswers;
1085
- let getChecklistQA = await processedchecklist.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1 } );
1085
+ let getChecklistQA = await processedchecklist.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1, redoEdit: 1 } );
1086
1086
  let reqAnswers = requestData.questionAnswers;
1087
1087
  logger.error( { functionName: 'updatedPayload', message: reqAnswers } );
1088
1088
  let CLQAnswers = getChecklistQA.questionAnswers;
1089
1089
 
1090
1090
  if ( requestData.submittype == 'submit' ) {
1091
+ if ( getChecklistQA?.redoEdit ) {
1092
+ requestData.submittype = 'draft';
1093
+ }
1091
1094
  reqAnswers.forEach( ( reqA ) => {
1092
1095
  if ( ![ 'multiplechoicemultiple', 'multipleImage', 'image/video' ].includes( reqA?.answerType ) && ( reqA.answerType == 'dropDown' && !reqA.allowMultiple ) ) {
1093
1096
  if ( ( !reqA.linkType && ( reqA.answer == null || reqA.answer == '' ) ) || ( reqA.linkType && reqA.linkquestionenabled && ( reqA.answer == null || reqA.answer == '' ) ) ) {
@@ -1174,24 +1177,29 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1174
1177
  if ( qaAnswers[j].answerType == 'yes/no' ) {
1175
1178
  let qaans = qaAnswers[j].answers;
1176
1179
  let yn = [];
1177
- for ( let k = 0; k < qaans.length; k++ ) {
1178
- if ( requestSection[i].answer == qaans[k].answer ) {
1179
- if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
1180
- if ( requestSection[i].validationAnswer ) {
1181
- let validateAns = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
1182
- if ( validateAns.length ) {
1183
- let splitImgUrl = validateAns.split( '/' );
1184
- if ( splitImgUrl.length > 1 ) {
1185
- splitImgUrl.splice( 0, 3 );
1186
- 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
+ }
1187
1192
  }
1188
1193
  }
1194
+ } else {
1195
+ // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1196
+ qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
1189
1197
  }
1190
- } else {
1191
- // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1192
- 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] );
1193
1202
  }
1194
- yn.push( qaans[k] );
1195
1203
  }
1196
1204
  }
1197
1205
  let structure = {};
@@ -1231,39 +1239,44 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1231
1239
  } else if ( qaAnswers[j].answerType == 'multiplechoicesingle' || ( qaAnswers[j].answerType == 'dropdown' && !qaAnswers[j].allowMultiple ) ) {
1232
1240
  let qaans = qaAnswers[j].answers;
1233
1241
  let ms = [];
1234
- for ( let k = 0; k < qaans.length; k++ ) {
1235
- if ( requestSection[i].answer == qaans[k].answer ) {
1236
- if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
1237
- if ( requestSection[i].validationAnswer ) {
1238
- let validationAnswer = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
1239
- if ( validationAnswer.length ) {
1240
- let splitImgUrl = validationAnswer.split( '/' );
1241
- if ( splitImgUrl.length > 1 ) {
1242
- splitImgUrl.splice( 0, 3 );
1243
- 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
+ }
1244
1254
  }
1245
1255
  }
1246
- }
1247
- } else {
1248
- if ( qaans[k].validationType == 'Capture Multiple Image with description' ) {
1249
- qaans[k]['validationImage']=[];
1250
- if ( requestSection[i].validationImage.length ) {
1251
- for ( let image of requestSection[i].validationImage ) {
1252
- let validationAnswer = decodeURIComponent( image.split( '?' )[0] );
1253
- if ( validationAnswer.length ) {
1254
- let splitImgUrl = validationAnswer.split( '/' );
1255
- if ( splitImgUrl.length > 1 ) {
1256
- splitImgUrl.splice( 0, 3 );
1257
- qaans[k].validationImage.push( splitImgUrl.join( '/' ) || '' );
1258
- }
1259
- };
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
+ }
1260
1270
  }
1261
1271
  }
1272
+ // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1273
+ qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
1262
1274
  }
1263
- // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1264
- 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] );
1265
1279
  }
1266
- ms.push( qaans[k] );
1267
1280
  }
1268
1281
  }
1269
1282
  let structure = {};
@@ -1304,30 +1317,42 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1304
1317
  } else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' || ( qaAnswers[j].answerType == 'dropdown' && qaAnswers[j].allowMultiple ) ) {
1305
1318
  let qaans = qaAnswers[j].answers;
1306
1319
  let mcmo = [];
1307
- for ( let k = 0; k < qaans.length; k++ ) {
1308
- let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
1309
- for ( let s = 0; s < separatedArray.length; s++ ) {
1310
- if ( separatedArray[s].answer == qaans[k].answer ) {
1311
- if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
1312
- if ( separatedArray[s].validationAnswer ) {
1313
- let validationAnswer = decodeURIComponent( separatedArray[s].validationAnswer.split( '?' )[0] );
1314
- if ( validationAnswer.length ) {
1315
- let splitImgUrl = validationAnswer.split( '/' );
1316
- if ( splitImgUrl.length > 1 ) {
1317
- splitImgUrl.splice( 0, 3 );
1318
- 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
+ }
1335
+ }
1319
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;
1320
1343
  }
1321
1344
  }
1322
- } else {
1323
- // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1324
- qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
1345
+ mcmo.push( qaans[k] );
1325
1346
  }
1326
-
1327
- mcmo.push( qaans[k] );
1328
1347
  }
1329
1348
  }
1330
1349
  }
1350
+ qaAnswers[j].answers.forEach( ( ele ) => {
1351
+ if ( typeof ele?.redo === 'boolean' && requestData.submittype === 'submit' ) {
1352
+ ele.redo = false;
1353
+ }
1354
+ } );
1355
+
1331
1356
  let structure = {};
1332
1357
  structure.qno = qaAnswers[j].qno;
1333
1358
  structure.uniqueqno = qaAnswers[j].uniqueqno;
@@ -1366,37 +1391,42 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1366
1391
  } else if ( [ 'image/video', 'multipleImage' ].includes( qaAnswers[j].answerType ) ) {
1367
1392
  let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
1368
1393
  let mcmi = [];
1394
+ if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
1369
1395
  // for (let k = 0; k < qaans.length; k++) {
1370
- for ( let s = 0; s < separatedArray.length; s++ ) {
1371
- if ( separatedArray[s].answer && separatedArray[s].answer !='' ) {
1372
- let newAnswer = {};
1373
- let validationAnswer = decodeURIComponent( separatedArray[s].answer.split( '?' )[0] );
1374
- if ( validationAnswer.length ) {
1375
- let splitImgUrl = validationAnswer.split( '/' );
1376
- if ( splitImgUrl.length > 1 ) {
1377
- splitImgUrl.splice( 0, 3 );
1378
- 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
+ }
1379
1406
  }
1380
- }
1381
1407
 
1382
- newAnswer.answeroptionNumber = 0;
1383
- newAnswer.sopFlag = false;
1384
- newAnswer.validation = false;
1385
- newAnswer.validationType = '';
1386
- newAnswer.referenceImage = '';
1387
- newAnswer.allowUploadfromGallery = false;
1388
- newAnswer.descriptivetype = '';
1389
- newAnswer.showLinked = false;
1390
- newAnswer.linkedQuestion = 0;
1391
- newAnswer.nestedQuestion = [];
1392
- newAnswer.index = s;
1393
- newAnswer.runAI = qaAnswers[j].answers[0]?.runAI || false;
1394
- newAnswer.runAIFeatures = qaAnswers[j].answers[0]?.runAIFeatures || [];
1395
- newAnswer.runAIDescription = qaAnswers[j].answers[0]?.runAIDescription || '';
1396
- if ( qaAnswers[j].answerType == 'image/video' ) {
1397
- 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 );
1398
1429
  }
1399
- mcmi.push( newAnswer );
1400
1430
  }
1401
1431
  }
1402
1432
  // }
@@ -1436,71 +1466,76 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1436
1466
  newArray.push( structure );
1437
1467
  } else {
1438
1468
  let des = [];
1439
- if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
1440
- let validationAnswer = '';
1441
- if ( requestSection[i].answer.split( '?' ).length > 1 || requestSection[i].answer.includes( 'https://' ) ) {
1442
- validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
1443
- }
1444
- if ( validationAnswer.length ) {
1445
- let splitImgUrl = validationAnswer.split( '/' );
1446
- if ( splitImgUrl.length > 1 ) {
1447
- splitImgUrl.splice( 0, 3 );
1448
- 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] );
1449
1474
  }
1450
- }
1451
- let ansstructure = {
1452
- answer: requestSection[i].answer,
1453
- answeroptionNumber: 1,
1454
- sopFlag: false,
1455
- validation: false,
1456
- validationType: '',
1457
- validationAnswer: '',
1458
- referenceImage: qaAnswers[j].answers[0].referenceImage || '',
1459
- multiReferenceImage: qaAnswers[j].answers[0].multiReferenceImage || [],
1460
- showLinked: qaAnswers[j].answers[0].showLinked,
1461
- linkedQuestion: qaAnswers[j].answers[0].linkedQuestion,
1462
- runAI: qaAnswers[j].answers[0]?.runAI || false,
1463
- runAIFeatures: qaAnswers[j]?.answers[0]?.runAIFeatures || [],
1464
- runAIDescription: qaAnswers[j].answers[0]?.runAIDescription || '',
1465
- };
1466
- if ( qaAnswers[j].answerType == 'date' ) {
1467
- ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
1468
- 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;
1469
1499
  if ( qaAnswers[j].compliance ) {
1470
- let ansArray = requestSection[i].answer.split( ',' );
1471
- if ( ansArray.includes( '-' ) ) {
1472
- 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
+ }
1473
1514
  }
1474
- 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 ) ) {
1475
- ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1476
- } 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 ) ) {
1477
- ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1478
- } 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 ) {
1479
1521
  ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1480
1522
  } else {
1481
1523
  ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
1482
1524
  }
1483
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;
1484
1529
  }
1485
- }
1486
- if ( qaAnswers[j].answerType == 'linearscale' ) {
1487
- if ( qaAnswers[j].compliance ) {
1488
- let linearAnswer = requestSection[i].answer.split( 'to' );
1489
- if ( parseInt( linearAnswer?.[0] ) >= qaAnswers[j]?.answers[0]?.minValue && parseInt( linearAnswer?.[1] ) <= qaAnswers[j]?.answers[0]?.maxValue ) {
1490
- ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1491
- } else {
1492
- ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
1493
- }
1530
+ if ( qaAnswers[j].answerType == 'image' ) {
1531
+ ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
1532
+ ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
1494
1533
  }
1495
- ansstructure.linearType = qaAnswers[j]?.answers[0]?.linearType;
1496
- ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
1497
- ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
1498
- }
1499
- if ( qaAnswers[j].answerType == 'image' ) {
1500
- ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
1501
- 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 );
1502
1538
  }
1503
- des.push( ansstructure );
1504
1539
  }
1505
1540
  let structure = {};
1506
1541
  structure.qno = qaAnswers[j].qno;
@@ -2172,6 +2207,7 @@ export async function submitChecklist( req, res ) {
2172
2207
  let flagCount = QuestionFlag( req, res );
2173
2208
  updateData.questionFlag = flagCount;
2174
2209
  updateData.submitTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
2210
+ updateData.redoEdit = false;
2175
2211
  if ( requestData.deviceDetails && requestData.deviceDetails != '' ) {
2176
2212
  updateData.deviceDetails =JSON.parse( requestData.deviceDetails );
2177
2213
  }
@@ -2444,7 +2480,8 @@ export async function submitTask( req, res ) {
2444
2480
  'storeResponseTime': currentDateTime.format( 'HH:mm:ss - MMM DD, YYYY' ),
2445
2481
  'message_mode': 'retriggered',
2446
2482
  };
2447
- sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).storeHygiene}`, JSON.stringify( sqsData ) );
2483
+ let sqsResponse = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).storeHygiene}`, JSON.stringify( sqsData ) );
2484
+ console.log( sqsResponse );
2448
2485
  }
2449
2486
  if ( !excludedChecklists.includes( checklist.checkListName ) ) {
2450
2487
  const query1 = [
@@ -2949,6 +2986,9 @@ export async function dashboardv1( req, res ) {
2949
2986
  // const { store_id, date } = req.query;
2950
2987
  const { date } = req.query;
2951
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 );
2952
2992
 
2953
2993
  // //Get User Based Checklist //
2954
2994
  const clientId = { client_id: req.user.clientId };
@@ -2959,7 +2999,7 @@ export async function dashboardv1( req, res ) {
2959
2999
  // eslint-disable-next-line camelcase
2960
3000
  // store_id,
2961
3001
  userId,
2962
- date_string: date,
3002
+ $or: [ { date_string: date }, { $and: [ { redoStatus: true }, { scheduleEndTime_iso: { $gte: fromDate } } ] } ],
2963
3003
  timeFlagStatus: true,
2964
3004
  ...clientId,
2965
3005
  ...storeMatch,
@@ -2985,9 +3025,7 @@ export async function dashboardv1( req, res ) {
2985
3025
  },
2986
3026
  ];
2987
3027
 
2988
- let fromDate = new Date( req.query.date );
2989
- let toDate = new Date( req.query.date );
2990
- toDate.setDate( toDate.getDate() + 1 );
3028
+
2991
3029
  const taskBaseMatch = {
2992
3030
  // eslint-disable-next-line camelcase
2993
3031
  // store_id,
@@ -3036,6 +3074,8 @@ export async function dashboardv1( req, res ) {
3036
3074
  processedTask.aggregate( taskQuery ),
3037
3075
  ] );
3038
3076
 
3077
+ console.log( checklistResult );
3078
+
3039
3079
  const checklistResultData =
3040
3080
  checklistResult.status === 'fulfilled' ?
3041
3081
  processResult( checklistResult.value ) :
@@ -3165,6 +3205,9 @@ export async function checklistv1( req, res ) {
3165
3205
  // const { store_id, date, checklistStatus, searchValue } = req.query;
3166
3206
  const { date, checklistStatus, searchValue } = req.query;
3167
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 );
3168
3211
 
3169
3212
  // Get User Based Checklist //
3170
3213
  const clientId = { client_id: req.user.clientId };
@@ -3176,16 +3219,23 @@ export async function checklistv1( req, res ) {
3176
3219
  // eslint-disable-next-line camelcase
3177
3220
  // { store_id },
3178
3221
  { userId },
3179
- { date_string: date },
3222
+ // { $or: [ { date_string: date }, { $and: [ { redoStatus: true }, { scheduleEndTime_iso: { $gte: fromDate } } ] } ] },
3180
3223
  { timeFlagStatus: true },
3181
3224
  ...matchExtraConditions,
3182
3225
  clientId,
3183
3226
  storeMatch,
3184
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
+ }
3185
3234
  if ( checklistStatus ) {
3186
3235
  matchConditions.push( { checklistStatus } );
3187
3236
  }
3188
3237
 
3238
+
3189
3239
  const pipeline = [
3190
3240
  { $match: { $and: matchConditions } },
3191
3241
  ...( searchValue ?
@@ -3238,9 +3288,7 @@ export async function checklistv1( req, res ) {
3238
3288
  return pipeline;
3239
3289
  };
3240
3290
 
3241
- let fromDate = new Date( req.query.date );
3242
- let toDate = new Date( req.query.date );
3243
- toDate.setDate( toDate.getDate() + 1 );
3291
+
3244
3292
  const taskBuildPipeline = ( matchExtraConditions = [], projectExtraConditions = {} ) => {
3245
3293
  const matchConditions = [
3246
3294
  // eslint-disable-next-line camelcase
@@ -3620,7 +3668,7 @@ export async function questionList( req, res ) {
3620
3668
  checkvalidation = answer.validationAnswer;
3621
3669
  }
3622
3670
  }
3623
- Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation } );
3671
+ Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation, ...( answer.redo && { redo: answer.redo } ) } );
3624
3672
  getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
3625
3673
  }
3626
3674
 
@@ -1729,6 +1729,7 @@ export const updateConfigure = async ( req, res ) => {
1729
1729
  owner: inputBody?.checkListDetails?.owner || [],
1730
1730
  restrictAttendance: inputBody?.checkListDetails?.restrictAttendance || false,
1731
1731
  enableNewDeployedStore: inputBody?.checkListDetails?.enableNewDeployedStore || false,
1732
+ redoValidity: inputBody?.checkListDetails?.redoValidity || 7,
1732
1733
  };
1733
1734
 
1734
1735
  if ( inputBody?.checkListDetails?.approver.length ) {
@@ -3907,6 +3908,8 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
3907
3908
  }
3908
3909
  }
3909
3910
  getsubmitDetails[0].questionAnswers = sectionList;
3911
+ getsubmitDetails[0].scheduleEndTime = getCLconfig.scheduleEndTime;
3912
+ getsubmitDetails[0].scheduleEndTime_iso = endTimeIso.format();
3910
3913
  if ( modifiedCount ) {
3911
3914
  getsubmitDetails[0].checklistStatus = 'inprogress';
3912
3915
  getsubmitDetails[0].date_string = dayjs( currentdate ).format( 'YYYY-MM-DD' );
@@ -4030,6 +4033,7 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
4030
4033
  }, { userId: 1, store_id: 1 } );
4031
4034
 
4032
4035
  if ( inprogressData.length ) {
4036
+ await processedchecklist.updateMany( { _id: { $in: inprogressData.map( ( ele ) => new ObjectId( ele._id ) ) } }, { scheduleEndTime: getCLconfig.scheduleEndTime, scheduleEndTime_iso: endTimeIso.format() } );
4033
4037
  inprogressData.forEach( ( item ) => {
4034
4038
  let checkData = assignUserList.find( ( ele ) => ele.userId.toString() == item.userId.toString() && ele.store_id == item.store_id );
4035
4039
  if ( !checkData ) {