tango-app-api-trax 3.3.1-beta-38 → 3.3.1-beta-40

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-38",
3
+ "version": "3.3.1-beta-40",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -231,25 +231,6 @@ export async function startChecklist( req, res ) {
231
231
  await checklistLogs.create( logInsertData );
232
232
  let getchecklist = getupdatedchecklist;
233
233
  let questions = [];
234
- // function processQuestion( question, section, questions, nested=false ) {
235
- // let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno );
236
- // if ( findExists && nested ) {
237
- // let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
238
- // questions.splice( findIndex, 1 );
239
- // questions.push( question );
240
- // }
241
- // if ( !findExists ) {
242
- // questions.push( question );
243
- // for ( let answer of question.answers ) {
244
- // if ( answer.showLinked && answer?.linkedQuestion != '' ) {
245
- // let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
246
- // if ( linkedQuestion ) {
247
- // processQuestion( linkedQuestion, section, questions, true );
248
- // }
249
- // }
250
- // }
251
- // }
252
- // }
253
234
  for ( let [ index, data ] of getchecklist.entries() ) {
254
235
  for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
255
236
  questions = [];
@@ -258,7 +239,7 @@ export async function startChecklist( req, res ) {
258
239
  question.parentQuestion = question.qno;
259
240
  questions.push( question );
260
241
  let linkedAnswer = new Set( question.answers.filter( ( ele ) => ele.showLinked ).flatMap( ( ele ) => ele.nestedQuestion ) );
261
- let linkedQuestion = section.questions.filter( ( qn ) => linkedAnswer.has( qn.qno ) );
242
+ let linkedQuestion = section.questions.filter( ( qn ) => qn?.parentQuestion ? qn?.parentQuestion == question.qno && linkedAnswer.has( qn.qno ) : linkedAnswer.has( qn.qno ) );
262
243
  linkedQuestion = JSON.parse( JSON.stringify( linkedQuestion ) );
263
244
  linkedQuestion.forEach( ( linkQn ) => {
264
245
  linkQn.parentQuestion = question.qno;
@@ -269,6 +250,42 @@ export async function startChecklist( req, res ) {
269
250
  getchecklist[index].questionAnswers[secIndex].questions = questions;
270
251
  }
271
252
  }
253
+ function processQuestion( question, section, questions, nested = false ) {
254
+ let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno && item.parentQuestion == question.parentQuestion );
255
+ if ( findExists && nested ) {
256
+ let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno && item.parentQuestion == question.parentQuestion );
257
+ questions.splice( findIndex, 1 );
258
+ questions.push( question );
259
+ for ( let answer of question.answers ) {
260
+ if ( answer.showLinked && answer?.linkedQuestion != '' ) {
261
+ let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion && item.parentQuestion == question.parentQuestion );
262
+ if ( linkedQuestion ) {
263
+ processQuestion( linkedQuestion, section, questions, true );
264
+ }
265
+ }
266
+ }
267
+ }
268
+ if ( !findExists ) {
269
+ questions.push( question );
270
+ for ( let answer of question.answers ) {
271
+ if ( answer.showLinked && answer?.linkedQuestion != '' ) {
272
+ let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion && item.parentQuestion == question.parentQuestion );
273
+ if ( linkedQuestion ) {
274
+ processQuestion( linkedQuestion, section, questions, true );
275
+ }
276
+ }
277
+ }
278
+ }
279
+ }
280
+ for ( let [ index, data ] of getchecklist.entries() ) {
281
+ for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
282
+ questions = [];
283
+ for ( let question of section.questions ) {
284
+ processQuestion( question, section, questions );
285
+ }
286
+ getchecklist[index].questionAnswers[secIndex].questions = questions;
287
+ }
288
+ }
272
289
  return res.sendSuccess( getchecklist );
273
290
  } else {
274
291
  return res.sendError( 'something went wrong please try again', 500 );
@@ -2634,33 +2651,6 @@ export async function questionList( req, res ) {
2634
2651
  }
2635
2652
 
2636
2653
  let questions = [];
2637
- // function processQuestion( question, section, questions, nested=false ) {
2638
- // let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno );
2639
- // if ( findExists && nested ) {
2640
- // // let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
2641
- // // questions.splice( findIndex, 1 );
2642
- // questions.push( question );
2643
- // for ( let answer of question.answers ) {
2644
- // if ( answer.showLinked && answer?.linkedQuestion != '' ) {
2645
- // let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
2646
- // if ( linkedQuestion ) {
2647
- // processQuestion( linkedQuestion, section, questions, true );
2648
- // }
2649
- // }
2650
- // }
2651
- // }
2652
- // if ( !findExists ) {
2653
- // questions.push( question );
2654
- // for ( let answer of question.answers ) {
2655
- // if ( answer.showLinked && answer?.linkedQuestion != '' ) {
2656
- // let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
2657
- // if ( linkedQuestion ) {
2658
- // processQuestion( linkedQuestion, section, questions, true );
2659
- // }
2660
- // }
2661
- // }
2662
- // }
2663
- // }
2664
2654
  for ( let [ index, data ] of getchecklist.entries() ) {
2665
2655
  for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
2666
2656
  questions = [];
@@ -2680,6 +2670,42 @@ export async function questionList( req, res ) {
2680
2670
  getchecklist[index].questionAnswers[secIndex].questions = questions;
2681
2671
  }
2682
2672
  }
2673
+ function processQuestion( question, section, questions, nested = false ) {
2674
+ let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno && item.parentQuestion == question.parentQuestion );
2675
+ if ( findExists && nested ) {
2676
+ let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno && item.parentQuestion == question.parentQuestion );
2677
+ questions.splice( findIndex, 1 );
2678
+ questions.push( question );
2679
+ for ( let answer of question.answers ) {
2680
+ if ( answer.showLinked && answer?.linkedQuestion != '' ) {
2681
+ let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion && item.parentQuestion == question.parentQuestion );
2682
+ if ( linkedQuestion ) {
2683
+ processQuestion( linkedQuestion, section, questions, true );
2684
+ }
2685
+ }
2686
+ }
2687
+ }
2688
+ if ( !findExists ) {
2689
+ questions.push( question );
2690
+ for ( let answer of question.answers ) {
2691
+ if ( answer.showLinked && answer?.linkedQuestion != '' ) {
2692
+ let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion && item.parentQuestion == question.parentQuestion );
2693
+ if ( linkedQuestion ) {
2694
+ processQuestion( linkedQuestion, section, questions, true );
2695
+ }
2696
+ }
2697
+ }
2698
+ }
2699
+ }
2700
+ for ( let [ index, data ] of getchecklist.entries() ) {
2701
+ for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
2702
+ questions = [];
2703
+ for ( let question of section.questions ) {
2704
+ processQuestion( question, section, questions );
2705
+ }
2706
+ getchecklist[index].questionAnswers[secIndex].questions = questions;
2707
+ }
2708
+ }
2683
2709
 
2684
2710
  return res.sendSuccess( getchecklist );
2685
2711
  }