tango-app-api-trax 3.2.0-beta.2 → 3.2.0-beta.4

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.2",
3
+ "version": "3.2.0-beta.4",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -453,10 +453,10 @@ export async function sopMobilechecklistQuestionValidator( req, res, next ) {
453
453
  return res.sendError( 'Check List Got Edited Please Fill Again', 422 );
454
454
  }
455
455
 
456
- if ( getChecklistQA ) {
456
+ if ( getChecklistQA && requestData.submittype == 'submit' ) {
457
457
  let checkChecklistStatus = await checklistService.findOne( { _id: getChecklistQA.sourceCheckList_id }, { publish: 1 } );
458
458
  if ( !checkChecklistStatus.publish ) {
459
- return res.sendError( 'Check List Got Edited Please Fill Again', 422 );
459
+ return res.sendError( 'Checklist got edited.please contact admin', 400 );
460
460
  }
461
461
  }
462
462
 
@@ -468,23 +468,34 @@ export async function sopMobilechecklistQuestionValidator( req, res, next ) {
468
468
  let reqAnswers = requestData.questionAnswers;
469
469
  let CLQAnswers = getChecklistQA.questionAnswers;
470
470
  let validationCount= 0;
471
+ let errorCount = 0;
471
472
  CLQAnswers.forEach( ( section ) => {
472
473
  let requestSection = reqAnswers.filter( ( reqSection ) => reqSection.section_id == section.section_id );
473
- section.questions.forEach( ( question ) => {
474
- question.answers.forEach( ( answer ) => {
475
- let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qno == question.qno );
476
- if ( question.answerType == 'multiplechoicemultiple' && ( sectionQuestion[0].Multianswer == null || sectionQuestion[0].Multianswer == '' || !sectionQuestion[0].Multianswer.length ) ) {
477
- validationCount++;
478
- } else {
479
- 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
- validationCount++;
474
+ if ( requestSection.length ) {
475
+ 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 ) ) {
480
+ 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
+ }
486
+ } else {
487
+ errorCount++;
481
488
  }
482
- }
489
+ } );
483
490
  } );
484
- } );
491
+ } else {
492
+ errorCount++;
493
+ }
485
494
  } );
486
495
  if ( validationCount ) {
487
496
  return res.sendError( 'Please Fill all Required Fields', 400 );
497
+ } else if ( errorCount ) {
498
+ return res.sendError( 'Checklist got edited.please contact admin', 400 );
488
499
  } else {
489
500
  next();
490
501
  }
@@ -2434,6 +2445,15 @@ export async function uploadAnswerImage( req, res ) {
2434
2445
  return res.sensError( 'Invalid Request: Please include questionNo!', 400 );
2435
2446
  }
2436
2447
 
2448
+ let getChecklistQA = await processedchecklist.findOne( { _id: input.checklistId }, { sourceCheckList_id: 1 } );
2449
+
2450
+ if ( getChecklistQA ) {
2451
+ let checkChecklistStatus = await checklistService.findOne( { _id: getChecklistQA.sourceCheckList_id }, { publish: 1 } );
2452
+ if ( !checkChecklistStatus.publish ) {
2453
+ return res.sendError( 'Checklist got edited.please contact admin', 400 );
2454
+ }
2455
+ }
2456
+
2437
2457
  let date = dayjs().format( 'YYYY-MM-DD' );
2438
2458
  let folder;
2439
2459
 
@@ -2045,6 +2045,7 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
2045
2045
  if ( getsubmitDetails[0].checkListDescription != getCLconfig.checkListDescription ) {
2046
2046
  getsubmitDetails[0].checkListDescription = getCLconfig.checkListDescription;
2047
2047
  }
2048
+ let sectionList = [];
2048
2049
  for ( let [ index, section ] of questionList.entries() ) {
2049
2050
  let checkExists = getsubmitDetails[0].questionAnswers.findIndex( ( sec ) => sec.sectionName == section.sectionOldName );
2050
2051
  if ( checkExists != -1 ) {
@@ -2085,11 +2086,13 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
2085
2086
  }
2086
2087
  } );
2087
2088
  getsubmitDetails[0].questionAnswers[index].questions = question;
2089
+ sectionList.push( getsubmitDetails[0].questionAnswers[index].questions );
2088
2090
  } else {
2089
2091
  modifiedCount++;
2090
- getsubmitDetails[0].questionAnswers.push( section );
2092
+ sectionList.push( section );
2091
2093
  }
2092
2094
  }
2095
+ getsubmitDetails[0].questionAnswers = sectionList;
2093
2096
  if ( modifiedCount ) {
2094
2097
  getsubmitDetails[0].checklistStatus = 'inprogress';
2095
2098
  }