tango-app-api-trax 3.2.0-beta.5 → 3.2.0-beta.6

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.2.0-beta.5",
3
+ "version": "3.2.0-beta.6",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -466,27 +466,30 @@ export async function sopMobilechecklistQuestionValidator( req, res, next ) {
466
466
 
467
467
  if ( requestData.submittype == 'submit' ) {
468
468
  let reqAnswers = requestData.questionAnswers;
469
+ logger.error( { functionName: 'payload', message: reqAnswers } );
469
470
  let CLQAnswers = getChecklistQA.questionAnswers;
471
+ logger.error( { functionName: 'CLQAnswers', message: CLQAnswers } );
470
472
  let validationCount= 0;
471
473
  let errorCount = 0;
472
474
  CLQAnswers.forEach( ( section ) => {
473
- let requestSection = reqAnswers.filter( ( reqSection ) => reqSection.section_id == section.section_id );
475
+ let requestSection = reqAnswers.filter( ( reqSection ) => reqSection.sectionName == section?.sectionOldName || reqSection.sectionName == section?.sectionName );
474
476
  if ( requestSection.length ) {
477
+ requestSection.forEach( ( item ) => item.section_id = section.section_id );
475
478
  section.questions.forEach( ( question ) => {
476
- question.answers.forEach( ( answer ) => {
477
- let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qno == question.qno );
478
- if ( sectionQuestion.length ) {
479
- if ( question.answerType == 'multiplechoicemultiple' && ( sectionQuestion[0].Multianswer == null || sectionQuestion[0].Multianswer == '' || !sectionQuestion[0].Multianswer.length ) ) {
479
+ // question.answers.forEach( ( answer ) => {
480
+ let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qname == question.oldQname || secQuestion.qname == question.qname );
481
+ if ( sectionQuestion.length ) {
482
+ if ( question.answerType == 'multiplechoicemultiple' && ( sectionQuestion[0].Multianswer == null || sectionQuestion[0].Multianswer == '' || !sectionQuestion[0].Multianswer.length ) ) {
483
+ validationCount++;
484
+ } else {
485
+ if ( ![ 'multiplechoicemultiple', 'multipleImage' ].includes( question.answerType ) && ( ( !sectionQuestion[0].linkType && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) || ( sectionQuestion[0].linkType && sectionQuestion[0].linkquestionenabled && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) ) ) {
480
486
  validationCount++;
481
- } else {
482
- if ( ![ 'multiplechoicemultiple', 'multipleImage' ].includes( question.answerType ) && ( ( !sectionQuestion[0].linkType && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) || ( sectionQuestion[0].linkType && sectionQuestion[0].linkquestionenabled && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) ) ) {
483
- validationCount++;
484
- }
485
487
  }
486
- } else {
487
- errorCount++;
488
488
  }
489
- } );
489
+ } else {
490
+ errorCount++;
491
+ }
492
+ // } );
490
493
  } );
491
494
  } else {
492
495
  errorCount++;
@@ -521,7 +524,7 @@ export async function sopMobileTaskQuestionValidator( req, res, next ) {
521
524
  let CLQAnswers = getChecklistQA.questionAnswers;
522
525
  let validationCount= 0;
523
526
  CLQAnswers.forEach( ( section ) => {
524
- let requestSection = reqAnswers.filter( ( reqSection ) => reqSection.section_id == section.section_id );
527
+ let requestSection = reqAnswers.filter( ( reqSection ) => reqSection.sectionName == section?.sectionOldName || reqSection.sectionName == section.sectionName );
525
528
  section.questions.forEach( ( question ) => {
526
529
  question.answers.forEach( ( answer ) => {
527
530
  let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qno == question.qno );
@@ -555,6 +558,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
555
558
  requestData.questionAnswers = typeof requestData.questionAnswers == 'string' ? JSON.parse( requestData.questionAnswers ) : requestData.questionAnswers;
556
559
  let getChecklistQA = await processedchecklist.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1 } );
557
560
  let reqAnswers = requestData.questionAnswers;
561
+ logger.error( { functionName: 'updatedPayload', message: reqAnswers } );
558
562
  let CLQAnswers = getChecklistQA.questionAnswers;
559
563
 
560
564
  if ( requestData.submittype == 'submit' ) {
@@ -567,6 +571,58 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
567
571
  } );
568
572
  }
569
573
 
574
+ if ( requestData?.editSubmit && requestData?.editSubmit == 'true' ) {
575
+ let sampleData = reqAnswers[0];
576
+ CLQAnswers.forEach( ( section ) => {
577
+ console.log( section, 'section' );
578
+ let requestSection = reqAnswers.filter( ( reqSection ) => reqSection.sectionName == section?.sectionOldName || reqSection.sectionName == section?.sectionName );
579
+ if ( requestSection.length ) {
580
+ requestSection.forEach( ( item ) => item.section_id = section.section_id );
581
+ section.questions.forEach( ( question ) => {
582
+ let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qname == question.oldQname || secQuestion.qname == question.qname );
583
+ if ( !sectionQuestion.length ) {
584
+ console.log( question, 'question', question.answerType );
585
+ let data = { ...requestSection[0] };
586
+ data.answerType = question.answerType;
587
+ data.qno = question.qno;
588
+ data.qname = question.qname;
589
+ data.answer = 'null';
590
+ data.remarks = '';
591
+ data.validationAnswer = '';
592
+ data.Multianswer = [];
593
+ data.linkType = question.linkType;
594
+ data.linkquestionenabled = question.linkType;
595
+ data.linkedQuestion = null;
596
+ data.showLinked = null;
597
+ data.parentanswer = '';
598
+ data.dateRangeType = false;
599
+ reqAnswers.push( data );
600
+ }
601
+ } );
602
+ } else {
603
+ section.questions.forEach( ( ele ) => {
604
+ let data = { ...sampleData };
605
+ data.section_id = section.section_id;
606
+ data.sectionName = section.sectionName;
607
+ data.answerType = ele.answerType;
608
+ data.qno = ele.qno;
609
+ data.qname = ele.qname;
610
+ data.answer = 'null';
611
+ data.remarks = '';
612
+ data.validationAnswer = '';
613
+ data.Multianswer = [];
614
+ data.linkType = ele.linkType;
615
+ data.linkquestionenabled = ele.linkType;
616
+ data.linkedQuestion = null;
617
+ data.showLinked = null;
618
+ data.parentanswer = '';
619
+ data.dateRangeType = false;
620
+ reqAnswers.push( data );
621
+ } );
622
+ }
623
+ } );
624
+ }
625
+
570
626
  let sectionFormat = [];
571
627
  let uniqueSections = {};
572
628
  reqAnswers.forEach( ( item ) => {
@@ -577,14 +633,14 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
577
633
  } );
578
634
  const uniqueArray = Object.values( uniqueSections );
579
635
  for ( let section of uniqueArray ) {
580
- let CLQSection = CLQAnswers.find( ( item ) => item.section_id == section.id );
636
+ let CLQSection = CLQAnswers.find( ( item ) => item.section_id.toString() == section.id.toString() );
581
637
  if ( CLQSection ) {
582
638
  let newArray = [];
583
639
  let qaAnswers = CLQSection.questions;
584
640
  let requestSection = reqAnswers.filter( ( item ) => item.section_id == section.id );
585
641
  for ( let i = 0; i < requestSection.length; i++ ) {
586
642
  for ( let j = 0; j < qaAnswers.length; j++ ) {
587
- if ( requestSection[i].qno == qaAnswers[j].qno ) {
643
+ if ( requestSection[i].qname == qaAnswers[j].oldQname || requestSection[i].qname == qaAnswers[j].qname ) {
588
644
  if ( qaAnswers[j].answerType == 'yes/no' ) {
589
645
  let qaans = qaAnswers[j].answers;
590
646
  let yn = [];
@@ -855,6 +911,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
855
911
 
856
912
 
857
913
  requestData.questionAnswers = sectionFormat;
914
+ logger.error( { message: requestData.questionAnswers, error: 'QuestionanswersPayload' } );
858
915
  next();
859
916
  } catch ( error ) {
860
917
  logger.error( { function: 'sopMobilechecklistMultiSectionFormatter', error: error, body: req.body } );
@@ -2047,8 +2047,9 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
2047
2047
  }
2048
2048
  let sectionList = [];
2049
2049
  for ( let [ index, section ] of questionList.entries() ) {
2050
- let checkExists = getsubmitDetails[0].questionAnswers.findIndex( ( sec ) => sec.sectionName == section.sectionOldName );
2050
+ let checkExists = getsubmitDetails[0].questionAnswers.findIndex( ( sec ) => sec.sectionName == section?.sectionOldName || sec.sectionName == section.sectionName );
2051
2051
  if ( checkExists != -1 ) {
2052
+ getsubmitDetails[0].questionAnswers[index].section_id = section.section_id;
2052
2053
  getsubmitDetails[0].questionAnswers[index].sectionName = section.sectionName;
2053
2054
  let question = [];
2054
2055
  section.questions.forEach( ( qns ) => {