tango-app-api-trax 3.3.1-beta-1 → 3.3.1-beta-2

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.3.1-beta-1",
3
+ "version": "3.3.1-beta-2",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -220,30 +220,35 @@ export async function startChecklist( req, res ) {
220
220
 
221
221
  let getchecklist = getupdatedchecklist;
222
222
  let questions = [];
223
- function processQuestion( question, section, questions, nested=false ) {
224
- let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno );
225
- if ( findExists && nested ) {
226
- let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
227
- questions.splice( findIndex, 1 );
228
- questions.push( question );
229
- }
230
- if ( !findExists ) {
231
- questions.push( question );
232
- for ( let answer of question.answers ) {
233
- if ( answer.showLinked && answer?.linkedQuestion != '' ) {
234
- let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
235
- if ( linkedQuestion ) {
236
- processQuestion( linkedQuestion, section, questions, true );
237
- }
238
- }
239
- }
240
- }
241
- }
223
+ // function processQuestion( question, section, questions, nested=false ) {
224
+ // let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno );
225
+ // if ( findExists && nested ) {
226
+ // let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
227
+ // questions.splice( findIndex, 1 );
228
+ // questions.push( question );
229
+ // }
230
+ // if ( !findExists ) {
231
+ // questions.push( question );
232
+ // for ( let answer of question.answers ) {
233
+ // if ( answer.showLinked && answer?.linkedQuestion != '' ) {
234
+ // let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
235
+ // if ( linkedQuestion ) {
236
+ // processQuestion( linkedQuestion, section, questions, true );
237
+ // }
238
+ // }
239
+ // }
240
+ // }
241
+ // }
242
242
  for ( let [ index, data ] of getchecklist.entries() ) {
243
243
  for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
244
244
  questions = [];
245
245
  for ( let question of section.questions ) {
246
- processQuestion( question, section, questions );
246
+ if ( !question.linkType ) {
247
+ questions.push( question );
248
+ let linkedAnswer = new Set( question.answers.filter( ( ele ) => ele.showLinked ).flatMap( ( ele ) => ele.nestedQuestion ) );
249
+ let linkedQuestion = section.questions.filter( ( qn ) => linkedAnswer.has( qn.qno ) );
250
+ questions.push( ...linkedQuestion );
251
+ }
247
252
  }
248
253
  getchecklist[index].questionAnswers[secIndex].questions = questions;
249
254
  }
@@ -2480,7 +2485,11 @@ export async function questionList( req, res ) {
2480
2485
  if ( question.answerType == 'multiplechoicemultiple' ) {
2481
2486
  let checkvalidation = null;
2482
2487
  if ( answer.validationAnswer && answer.validationAnswer !='' ) {
2483
- checkvalidation = await signedUrl( { file_path: decodeURIComponent( answer.validationAnswer ), Bucket: bucket.sop } );
2488
+ if ( answer.validationType != 'Descriptive Answer' ) {
2489
+ checkvalidation = await signedUrl( { file_path: decodeURIComponent( answer.validationAnswer ), Bucket: bucket.sop } );
2490
+ } else {
2491
+ checkvalidation = answer.validationAnswer;
2492
+ }
2484
2493
  }
2485
2494
  Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation } );
2486
2495
  getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
@@ -2543,38 +2552,43 @@ export async function questionList( req, res ) {
2543
2552
  }
2544
2553
 
2545
2554
  let questions = [];
2546
- function processQuestion( question, section, questions, nested=false ) {
2547
- let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno );
2548
- if ( findExists && nested ) {
2549
- let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
2550
- questions.splice( findIndex, 1 );
2551
- questions.push( question );
2552
- for ( let answer of question.answers ) {
2553
- if ( answer.showLinked && answer?.linkedQuestion != '' ) {
2554
- let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
2555
- if ( linkedQuestion ) {
2556
- processQuestion( linkedQuestion, section, questions, true );
2557
- }
2558
- }
2559
- }
2560
- }
2561
- if ( !findExists ) {
2562
- questions.push( question );
2563
- for ( let answer of question.answers ) {
2564
- if ( answer.showLinked && answer?.linkedQuestion != '' ) {
2565
- let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
2566
- if ( linkedQuestion ) {
2567
- processQuestion( linkedQuestion, section, questions, true );
2568
- }
2569
- }
2570
- }
2571
- }
2572
- }
2555
+ // function processQuestion( question, section, questions, nested=false ) {
2556
+ // let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno );
2557
+ // if ( findExists && nested ) {
2558
+ // // let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
2559
+ // // questions.splice( findIndex, 1 );
2560
+ // questions.push( question );
2561
+ // for ( let answer of question.answers ) {
2562
+ // if ( answer.showLinked && answer?.linkedQuestion != '' ) {
2563
+ // let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
2564
+ // if ( linkedQuestion ) {
2565
+ // processQuestion( linkedQuestion, section, questions, true );
2566
+ // }
2567
+ // }
2568
+ // }
2569
+ // }
2570
+ // if ( !findExists ) {
2571
+ // questions.push( question );
2572
+ // for ( let answer of question.answers ) {
2573
+ // if ( answer.showLinked && answer?.linkedQuestion != '' ) {
2574
+ // let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
2575
+ // if ( linkedQuestion ) {
2576
+ // processQuestion( linkedQuestion, section, questions, true );
2577
+ // }
2578
+ // }
2579
+ // }
2580
+ // }
2581
+ // }
2573
2582
  for ( let [ index, data ] of getchecklist.entries() ) {
2574
2583
  for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
2575
2584
  questions = [];
2576
2585
  for ( let question of section.questions ) {
2577
- processQuestion( question, section, questions );
2586
+ if ( !question.linkType ) {
2587
+ questions.push( question );
2588
+ let linkedAnswer = new Set( question.answers.filter( ( ele ) => ele.showLinked ).flatMap( ( ele ) => ele.nestedQuestion ) );
2589
+ let linkedQuestion = section.questions.filter( ( qn ) => linkedAnswer.has( qn.qno ) );
2590
+ questions.push( ...linkedQuestion );
2591
+ }
2578
2592
  }
2579
2593
  getchecklist[index].questionAnswers[secIndex].questions = questions;
2580
2594
  }
@@ -248,9 +248,13 @@ export const create = async ( req, res ) => {
248
248
  }
249
249
  if ( answer.showLinked ) {
250
250
  if ( nestedIndex != -1 ) {
251
- section.questions[qIdx].answers[nestedIndex].nestedQuestion.push( answer.linkedQuestion );
251
+ if ( !section.questions[qIdx].answers[nestedIndex].nestedQuestion.includes( answer.linkedQuestion ) ) {
252
+ section.questions[qIdx].answers[nestedIndex].nestedQuestion.push( answer.linkedQuestion );
253
+ }
252
254
  } else {
253
- section.questions[qIdx].answers[index].nestedQuestion.push( answer.linkedQuestion );
255
+ if ( !section.questions[qIdx].answers[index].nestedQuestion.includes( answer.linkedQuestion ) ) {
256
+ section.questions[qIdx].answers[index].nestedQuestion.push( answer.linkedQuestion );
257
+ }
254
258
  }
255
259
  let nestedLinkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
256
260
  if ( nestedLinkedQuestion ) {
@@ -753,9 +757,13 @@ export const update = async ( req, res ) => {
753
757
  }
754
758
  if ( answer.showLinked ) {
755
759
  if ( nestedIndex != -1 ) {
756
- section.questions[qIdx].answers[nestedIndex].nestedQuestion.push( answer.linkedQuestion );
760
+ if ( !section.questions[qIdx].answers[nestedIndex].nestedQuestion.includes( answer.linkedQuestion ) ) {
761
+ section.questions[qIdx].answers[nestedIndex].nestedQuestion.push( answer.linkedQuestion );
762
+ }
757
763
  } else {
758
- section.questions[qIdx].answers[index].nestedQuestion.push( answer.linkedQuestion );
764
+ if ( !section.questions[qIdx].answers[index].nestedQuestion.includes( answer.linkedQuestion ) ) {
765
+ section.questions[qIdx].answers[index].nestedQuestion.push( answer.linkedQuestion );
766
+ }
759
767
  }
760
768
  let nestedLinkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
761
769
  if ( nestedLinkedQuestion ) {