tango-app-api-trax 3.9.1 → 3.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-trax",
3
- "version": "3.9.1",
3
+ "version": "3.9.3",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -437,12 +437,14 @@ export async function redoChecklist( req, res ) {
437
437
  }
438
438
 
439
439
 
440
- 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 } );
440
+ 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 } );
441
+
441
442
  if ( !checklistDetails ) {
442
443
  return res.sendError( 'No data found', 204 );
443
444
  }
444
445
  let question = checklistDetails.questionAnswers;
445
446
 
447
+ let checklistConfigDetails = await checklistService.findOne( { _id: checklistDetails.sourceCheckList_id }, { redoValidity: 1 } );
446
448
 
447
449
  let sectionIndex = question.findIndex( ( sec ) => sec.sectionName == req.body.payload.sectionName );
448
450
  if ( sectionIndex == -1 ) {
@@ -451,37 +453,97 @@ export async function redoChecklist( req, res ) {
451
453
 
452
454
  let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.qno == req.body.payload.qno );
453
455
 
454
- let data = { ...question[sectionIndex].questions[findQuestion], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
455
- // if ( checklistDetails.client_id == '458' ) {
456
- data.answers.forEach( ( item ) => {
457
- if ( item.showLinked ) {
458
- item.nestedQuestion.forEach( ( ele ) => {
459
- let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn.qno == parseInt( ele ) );
460
- let element = { ...question[sectionIndex].questions[eleIndex], redo: true, redoComment: '', linkquestionenabled: false };
461
- question[sectionIndex].questions[eleIndex] = element;
462
- question[sectionIndex].questions[eleIndex].userAnswer = [];
463
- question[sectionIndex].questions[eleIndex].remarks = '';
456
+ let data = { ...question[sectionIndex].questions[findQuestion], redo: true, ...( !req.body.payload?.answerIndex && { redoComment: req.body.payload?.checklistDescription || '' } ) };
457
+ let answerIndex = req.body.payload?.answerIndex;
458
+ let isSingleAnswerRedo = answerIndex != null;
459
+
460
+ if ( !isSingleAnswerRedo ) {
461
+ // if ( checklistDetails.client_id == '458' ) {
462
+ data.answers.forEach( ( item ) => {
463
+ if ( item.showLinked ) {
464
+ item.nestedQuestion.forEach( ( ele ) => {
465
+ let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn.qno == parseInt( ele ) );
466
+ let element = { ...question[sectionIndex].questions[eleIndex], redo: true, redoComment: '', linkquestionenabled: false };
467
+ question[sectionIndex].questions[eleIndex] = element;
468
+ if ( Array.isArray( question?.[sectionIndex]?.questions?.[eleIndex]?.answers )?.length ) {
469
+ question[sectionIndex].questions[eleIndex].answers.forEach( ( ans ) => {
470
+ ans.validationAnswer = '';
471
+ delete ans.redoComment;
472
+ delete ans.redo;
473
+ } );
474
+ }
475
+ question[sectionIndex].questions[eleIndex].userAnswer = [];
476
+ question[sectionIndex].questions[eleIndex].remarks = '';
477
+ } );
478
+ }
479
+ } );
480
+ // data.answers.forEach( ( item ) => {
481
+ // if ( item.showLinked ) {
482
+ // item.nestedQuestion = [];
483
+ // item.showLinked = false;
484
+ // item.linkedQuestion = 0;
485
+ // }
486
+ // } );
487
+ // }
488
+ }
489
+ let userAnswer = Array.isArray( data.userAnswer ) ? [ ...data.userAnswer ] : [];
490
+
491
+ question[sectionIndex].questions[findQuestion] = data;
492
+ if ( isSingleAnswerRedo ) {
493
+ let targetQuestion = question[sectionIndex].questions[findQuestion];
494
+ let targetUserAnswerIndex = targetQuestion.userAnswer?.findIndex( ( ele ) => ele.answer == req.body.payload.answerName );
495
+ let targetUserAnswer = targetQuestion.userAnswer[targetUserAnswerIndex];
496
+ if ( targetUserAnswer && Array.isArray( targetQuestion.answers ) ) {
497
+ let matchedAnsIdx = targetQuestion.answers.findIndex( ( ans ) => {
498
+ // if ( targetUserAnswer.no !== undefined && ans.index === targetUserAnswer.no ) return true;
499
+ // if ( targetUserAnswer.index !== undefined && ans.index === targetUserAnswer.index ) return true;
500
+ // if ( targetUserAnswer.answeroptionNumber !== undefined && ans.answeroptionNumber === targetUserAnswer.answeroptionNumber ) return true;
501
+ return ans.answer === targetUserAnswer.answer;
464
502
  } );
503
+ if ( matchedAnsIdx !== -1 ) {
504
+ targetQuestion.answers[matchedAnsIdx].redo = true;
505
+ targetQuestion.answers[matchedAnsIdx].validationAnswer = '';
506
+ targetQuestion.answers[matchedAnsIdx].redoComment = req.body.payload?.checklistDescription || '';
507
+ targetQuestion.remarks = '';
508
+ }
509
+ targetQuestion.userAnswer.splice( targetUserAnswerIndex, 1 );
465
510
  }
466
- } );
467
- // data.answers.forEach( ( item ) => {
468
- // if ( item.showLinked ) {
469
- // item.nestedQuestion = [];
470
- // item.showLinked = false;
471
- // item.linkedQuestion = 0;
472
- // }
473
- // } );
474
- // }
475
- let userAnswer = data.userAnswer;
476
511
 
477
- question[sectionIndex].questions[findQuestion] = data;
478
- question[sectionIndex].questions[findQuestion].userAnswer = [];
479
- question[sectionIndex].questions[findQuestion].remarks = '';
512
+ let currentQno = req.body.payload.qno;
513
+ let parentQIndex = -1;
514
+ // let parentAnsIndex = -1;
515
+ for ( let i = 0; i < question[sectionIndex].questions.length; i++ ) {
516
+ let parentAnswers = question[sectionIndex].questions[i].answers || [];
517
+ let foundAnsIdx = parentAnswers.findIndex( ( ans ) => Array.isArray( ans?.nestedQuestion ) && ans.nestedQuestion.some( ( ele ) => parseInt( ele ) == currentQno ) );
518
+ if ( foundAnsIdx !== -1 ) {
519
+ parentQIndex = i;
520
+ // parentAnsIndex = foundAnsIdx;
521
+ break;
522
+ }
523
+ }
524
+ if ( parentQIndex !== -1 ) {
525
+ let parentQno = question[sectionIndex].questions[parentQIndex].qno;
526
+ question[sectionIndex].questions[findQuestion].parentQno = parentQno;
527
+ // question[sectionIndex].questions[findQuestion].remarks = '';
528
+ // question[sectionIndex].questions[parentQIndex].answers[parentAnsIndex].redo = true;
529
+ // question[sectionIndex].questions[parentQIndex].answers[parentAnsIndex].validationAnswer = '';
530
+ }
531
+ } else {
532
+ question[sectionIndex].questions[findQuestion].userAnswer = [];
533
+ if ( Array.isArray( question[sectionIndex].questions[findQuestion].answers ) ) {
534
+ question[sectionIndex].questions[findQuestion].answers.forEach( ( ans ) => {
535
+ ans.validationAnswer = '';
536
+ delete ans.redoComment;
537
+ delete ans.redo;
538
+ } );
539
+ }
540
+ question[sectionIndex].questions[findQuestion].remarks = '';
541
+ }
480
542
  checklistDetails.questionAnswers = question;
481
543
  let updateData = {
482
- checklistStatus: 'open',
544
+ checklistStatus: checklistDetails.checklistStatus != 'submit' ? checklistDetails.checklistStatus : 'open',
483
545
  redoStatus: true,
484
- reinitiateStatus: true,
546
+ ...( !checklistConfigDetails?.redoValidity && { reinitiateStatus: true } ),
485
547
  questionAnswers: question,
486
548
  ...( checklistDetails.checklistStatus != 'submit' && checklistDetails.redoStatus ) ? { redoEdit: true } : {},
487
549
  ...( ( checklistDetails.redoEdit === undefined && checklistConfigDetails.redoValidity ) ) ? { scheduleEndTime_iso: dayjs( checklistDetails.scheduleEndTime_iso ).add( checklistConfigDetails.redoValidity, 'day' ).format() } :{},
@@ -12,7 +12,7 @@ mobileRouter
12
12
  .post( '/startTask', isAllowedSessionHandler, validate( startValidation ), mobileController.startTask )
13
13
  .post( '/submitCheckList', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobilechecklistQuestionValidator, mobileController.sopMobilechecklistMultiSectionFormatter, mobileController.submitChecklist )
14
14
  .post( '/submitCheckListv5', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobilechecklistQuestionValidatorv1, mobileController.sopMobilechecklistMultiSectionFormatterv1, mobileController.submitChecklist )
15
- // .post( '/submitCheckListv6', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobilechecklistQuestionValidatorv1, mobileController.sopMobilechecklistMultiSectionFormatterv2, mobileController.submitChecklist )
15
+ .post( '/submitCheckListv6', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobilechecklistQuestionValidatorv1, mobileController.sopMobilechecklistMultiSectionFormatterv2, mobileController.submitChecklist )
16
16
  .post( '/submitTask', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobileTaskQuestionValidator, mobileController.sopMobileTaskMultiSectionFormatter, mobileController.submitTask )
17
17
  .post( '/submiteyeTestTask', isAllowedSessionHandler, mobileController.submiteyeTestTask )
18
18
  .get( '/dashboard', isAllowedSessionHandler, validate( dashboardValidation ), mobileController.dashboard )