tango-app-api-trax 3.3.1-beta-39 → 3.3.1-beta-41

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-39",
3
+ "version": "3.3.1-beta-41",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,7 +26,7 @@
26
26
  "mongodb": "^6.8.0",
27
27
  "nodemon": "^3.1.4",
28
28
  "path": "^0.12.7",
29
- "tango-api-schema": "^2.2.56",
29
+ "tango-api-schema": "^2.2.58",
30
30
  "tango-app-api-middleware": "^3.1.55",
31
31
  "url": "^0.11.4",
32
32
  "winston": "^3.13.1",
@@ -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,21 +250,26 @@ export async function startChecklist( req, res ) {
269
250
  getchecklist[index].questionAnswers[secIndex].questions = questions;
270
251
  }
271
252
  }
272
-
273
- let orderedQuestions = [];
274
-
275
- function processQuestion( question, section, questions, nested=false ) {
276
- let findExists = orderedQuestions.find( ( item ) => item?.qno && item.qno == question.qno );
277
- if ( findExists && nested && question.parentQuestion == findExists.parentQuestion ) {
278
- let findIndex = orderedQuestions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
279
- orderedQuestions.splice( findIndex, 1 );
280
- orderedQuestions.push( question );
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
+ }
281
267
  }
282
268
  if ( !findExists ) {
283
- orderedQuestions.push( question );
269
+ questions.push( question );
284
270
  for ( let answer of question.answers ) {
285
271
  if ( answer.showLinked && answer?.linkedQuestion != '' ) {
286
- let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
272
+ let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion && item.parentQuestion == question.parentQuestion );
287
273
  if ( linkedQuestion ) {
288
274
  processQuestion( linkedQuestion, section, questions, true );
289
275
  }
@@ -293,11 +279,11 @@ export async function startChecklist( req, res ) {
293
279
  }
294
280
  for ( let [ index, data ] of getchecklist.entries() ) {
295
281
  for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
296
- orderedQuestions = [];
282
+ questions = [];
297
283
  for ( let question of section.questions ) {
298
284
  processQuestion( question, section, questions );
299
285
  }
300
- getchecklist[index].questionAnswers[secIndex].questions = orderedQuestions;
286
+ getchecklist[index].questionAnswers[secIndex].questions = questions;
301
287
  }
302
288
  }
303
289
  return res.sendSuccess( getchecklist );
@@ -2494,8 +2480,8 @@ export async function checklistv1( req, res ) {
2494
2480
  };
2495
2481
 
2496
2482
  const [ checklistResult, taskResult ] = await Promise.allSettled( [
2497
- processedchecklist.aggregate( buildPipeline( [ { checkListType: 'custom' } ], { isPlano: 1, planoId: 1 } ) ),
2498
- processedTask.aggregate( buildPipeline( [], { isPlano: 1, planoId: 1 } ) ),
2483
+ processedchecklist.aggregate( buildPipeline( [ { checkListType: 'custom' } ], { isPlano: 1, planoId: 1, planoType: 1 } ) ),
2484
+ processedTask.aggregate( buildPipeline( [], { isPlano: 1, planoId: 1, planoType: 1 } ) ),
2499
2485
  ] );
2500
2486
 
2501
2487
  const checklistData = checklistResult.status === 'fulfilled' ? checklistResult.value : [];
@@ -2665,33 +2651,6 @@ export async function questionList( req, res ) {
2665
2651
  }
2666
2652
 
2667
2653
  let questions = [];
2668
- // function processQuestion( question, section, questions, nested=false ) {
2669
- // let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno );
2670
- // if ( findExists && nested ) {
2671
- // // let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
2672
- // // questions.splice( findIndex, 1 );
2673
- // questions.push( question );
2674
- // for ( let answer of question.answers ) {
2675
- // if ( answer.showLinked && answer?.linkedQuestion != '' ) {
2676
- // let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
2677
- // if ( linkedQuestion ) {
2678
- // processQuestion( linkedQuestion, section, questions, true );
2679
- // }
2680
- // }
2681
- // }
2682
- // }
2683
- // if ( !findExists ) {
2684
- // questions.push( question );
2685
- // for ( let answer of question.answers ) {
2686
- // if ( answer.showLinked && answer?.linkedQuestion != '' ) {
2687
- // let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
2688
- // if ( linkedQuestion ) {
2689
- // processQuestion( linkedQuestion, section, questions, true );
2690
- // }
2691
- // }
2692
- // }
2693
- // }
2694
- // }
2695
2654
  for ( let [ index, data ] of getchecklist.entries() ) {
2696
2655
  for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
2697
2656
  questions = [];
@@ -2711,21 +2670,26 @@ export async function questionList( req, res ) {
2711
2670
  getchecklist[index].questionAnswers[secIndex].questions = questions;
2712
2671
  }
2713
2672
  }
2714
-
2715
- let orderedQuestions = [];
2716
-
2717
- function processQuestion( question, section, questions, nested=false ) {
2718
- let findExists = orderedQuestions.find( ( item ) => item?.qno && item.qno == question.qno );
2719
- if ( findExists && nested && question.parentQuestion == findExists.parentQuestion ) {
2720
- let findIndex = orderedQuestions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
2721
- orderedQuestions.splice( findIndex, 1 );
2722
- orderedQuestions.push( question );
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
+ }
2723
2687
  }
2724
2688
  if ( !findExists ) {
2725
- orderedQuestions.push( question );
2689
+ questions.push( question );
2726
2690
  for ( let answer of question.answers ) {
2727
2691
  if ( answer.showLinked && answer?.linkedQuestion != '' ) {
2728
- let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
2692
+ let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion && item.parentQuestion == question.parentQuestion );
2729
2693
  if ( linkedQuestion ) {
2730
2694
  processQuestion( linkedQuestion, section, questions, true );
2731
2695
  }
@@ -2735,11 +2699,11 @@ export async function questionList( req, res ) {
2735
2699
  }
2736
2700
  for ( let [ index, data ] of getchecklist.entries() ) {
2737
2701
  for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
2738
- orderedQuestions = [];
2702
+ questions = [];
2739
2703
  for ( let question of section.questions ) {
2740
2704
  processQuestion( question, section, questions );
2741
2705
  }
2742
- getchecklist[index].questionAnswers[secIndex].questions = orderedQuestions;
2706
+ getchecklist[index].questionAnswers[secIndex].questions = questions;
2743
2707
  }
2744
2708
  }
2745
2709