tango-app-api-trax 3.4.1-alpha-11 → 3.4.1-alpha-13

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.4.1-alpha-11",
3
+ "version": "3.4.1-alpha-13",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -245,10 +245,10 @@ export async function startChecklist( req, res ) {
245
245
  for ( let [ index, data ] of getchecklist.entries() ) {
246
246
  for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
247
247
  questions = [];
248
- for ( let question of section.questions ) {
248
+ for ( let [ questionIdx, question ] of section.questions.entries() ) {
249
249
  let linkedQuestions;
250
250
  if ( !question.linkType ) {
251
- question.uniqueNo = parseInt( getOtp() );
251
+ question.uniqueNo = parseInt( getOtp() )+ Date.now() + questionIdx;
252
252
  questions.push( question );
253
253
  linkedQuestions = [];
254
254
  let questionList = new Map( section.questions.map( ( ele ) => [ ele.qno, ele ] ) );
@@ -259,7 +259,7 @@ export async function startChecklist( req, res ) {
259
259
  answer.nestedQuestion.forEach( ( qn, qidx ) => {
260
260
  let getQn = questionList.get( qn );
261
261
  if ( getQn ) {
262
- let randomNo = parseInt( getOtp() );
262
+ let randomNo = parseInt( getOtp() ) + Date.now() + qidx;
263
263
  getQn = JSON.parse( JSON.stringify( getQn ) );
264
264
  getQn = { ...getQn, uniqueNo: randomNo };
265
265
  nesedQuestion.push( getQn );
@@ -2759,13 +2759,13 @@ export async function questionList( req, res ) {
2759
2759
  for ( let [ index, data ] of getchecklist.entries() ) {
2760
2760
  for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
2761
2761
  questions = [];
2762
- for ( let question of section.questions ) {
2762
+ for ( let [ questionIndex, question ] of section.questions.entries() ) {
2763
2763
  let linkedQuestions;
2764
2764
  let uniqueShow = false;
2765
2765
  if ( !question.linkType ) {
2766
2766
  if ( !question?.uniqueNo ) {
2767
2767
  uniqueShow = true;
2768
- question.uniqueNo = parseInt( getOtp() );
2768
+ question.uniqueNo = parseInt( getOtp() ) + Date.now() + questionIndex;
2769
2769
  }
2770
2770
  questions.push( question );
2771
2771
  linkedQuestions = [];
@@ -2780,12 +2780,13 @@ export async function questionList( req, res ) {
2780
2780
  question.answers.forEach( ( answer ) => {
2781
2781
  if ( answer.linkedQuestion ) {
2782
2782
  let nesedQuestion = [];
2783
+ answer.oldNestedQuestion = !uniqueShow ? JSON.parse( JSON.stringify( answer.oldNestedQuestion ) ) : JSON.parse( JSON.stringify( answer.nestedQuestion ) );
2783
2784
  answer.nestedQuestion.forEach( ( qn, qidx ) => {
2784
2785
  let getQn = questionList.get( qn );
2785
2786
  if ( getQn ) {
2786
2787
  let randomNo;
2787
2788
  if ( !getQn?.uniqueNo ) {
2788
- randomNo = parseInt( getOtp() );
2789
+ randomNo = parseInt( getOtp() ) + Date.now() + qidx;
2789
2790
  } else {
2790
2791
  randomNo = getQn?.uniqueNo;
2791
2792
  }
@@ -2793,6 +2794,7 @@ export async function questionList( req, res ) {
2793
2794
  getQn = { ...getQn, uniqueNo: randomNo };
2794
2795
  nesedQuestion.push( getQn );
2795
2796
  if ( answer.linkedQuestion == getQn.qno ) {
2797
+ answer.oldLinkedQuestion = answer.linkedQuestion;
2796
2798
  answer.linkedQuestion = randomNo;
2797
2799
  }
2798
2800
  answer.nestedQuestion[qidx] = randomNo;
@@ -2802,10 +2804,12 @@ export async function questionList( req, res ) {
2802
2804
  let nestedLinkqn = [];
2803
2805
  ele.answers.forEach( ( ans ) => {
2804
2806
  if ( ans.linkedQuestion ) {
2807
+ ans.oldNestedQuestion = !uniqueShow ? JSON.parse( JSON.stringify( ans.oldNestedQuestion ) ) : JSON.parse( JSON.stringify( ans.nestedQuestion ) );
2805
2808
  ans.nestedQuestion.forEach( ( nested, idx ) => {
2806
2809
  let findRandom = nesedQuestion.find( ( qn ) => ( uniqueShow ? qn.qno == nested : qn.uniqueNo == nested ) && !nestedLinkqn.includes( qn.uniqueNo ) && !qn.updated );
2807
2810
  if ( findRandom ) {
2808
2811
  if ( ans.linkedQuestion == findRandom.qno ) {
2812
+ ans.oldLinkedQuestion = ans.linkedQuestion;
2809
2813
  ans.linkedQuestion = findRandom.uniqueNo;
2810
2814
  }
2811
2815
  ans.nestedQuestion[idx] = findRandom.uniqueNo;
@@ -3184,7 +3184,6 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
3184
3184
  delete data.parentanswer;
3185
3185
  delete data.remarks;
3186
3186
  delete data.linkquestionenabled;
3187
- let uniqueNo = data.uniqueNo;
3188
3187
  delete data.uniqueNo;
3189
3188
  if ( data.descriptivetype == null ) {
3190
3189
  delete data.descriptivetype;
@@ -3207,25 +3206,58 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
3207
3206
  logger.info( 'compare =>', compare );
3208
3207
  logger.info( 'qno =>', data.qno );
3209
3208
  modifiedCount++;
3210
- question.push( qns );
3209
+ question.push( { question: qns, type: 'qnEdit' } );
3211
3210
  } else {
3212
- getsubmitDetails[0].questionAnswers[index].questions[findQuestion].qname = qns.qname;
3213
- getsubmitDetails[0].questionAnswers[index].questions[findQuestion].uniqueNo = uniqueNo;
3214
- question.push( getsubmitDetails[0].questionAnswers[index].questions[findQuestion] );
3211
+ if ( getsubmitDetails[0].questionAnswers[index].questions[findQuestion].qname != qns.qname ) {
3212
+ question.push( { type: 'nameChange', question: qns } );
3213
+ }
3214
+ // getsubmitDetails[0].questionAnswers[index].questions[findQuestion].qname = qns.qname;
3215
3215
  }
3216
3216
  } else {
3217
3217
  modifiedCount++;
3218
- question.push( qns );
3218
+ question.push( { question: qns, type: 'add' } );
3219
3219
  }
3220
3220
  } );
3221
- getsubmitDetails[0].questionAnswers[index].questions = question;
3222
- sectionList.push( getsubmitDetails[0].questionAnswers[index] );
3221
+ // getsubmitDetails[0].questionAnswers[index].questions = question;
3222
+ sectionList.push( { sectionName: section.sectionName, oldName: section.sectionOldName, question: question, type: 'edit' } );
3223
3223
  } else {
3224
3224
  modifiedCount++;
3225
- sectionList.push( section );
3225
+ sectionList.push( { sectionName: section?.sectionName, oldName: section?.sectionOldName, question: section.questions, type: 'add' } );
3226
3226
  }
3227
3227
  }
3228
- getsubmitDetails[0].questionAnswers = sectionList;
3228
+ console.log( JSON.stringify( sectionList ) );
3229
+ // getsubmitDetails[0].questionAnswers = sectionList;
3230
+ sectionList.forEach( ( sec ) => {
3231
+ if ( sec.type == 'add' ) {
3232
+ getsubmitDetails[0].questionAnswers.push( sec );
3233
+ } else {
3234
+ sec.question.forEach( ( qn ) => {
3235
+ console.log( qn, 'qn' );
3236
+ let sectionDetails = getsubmitDetails[0].questionAnswers.findIndex( ( section ) => section.sectionName == sec?.oldName || section.sectionName == sec.sectionName );
3237
+ console.log( sectionDetails, 'detauls' );
3238
+ if ( qn.type == 'add' ) {
3239
+ getsubmitDetails[0].questionAnswers[sectionDetails].questions.push( qn.question );
3240
+ } else {
3241
+ const questions = getsubmitDetails[0].questionAnswers[sectionDetails].questions.reduce( ( acc, ele, idx ) => {
3242
+ if ( ele.qname.trim() == qn?.question?.oldQname?.trim() || ele.qname.trim() == qn.question.qname.trim() ) {
3243
+ acc.push( idx );
3244
+ }
3245
+ return acc;
3246
+ }, [] );
3247
+ console.log( questions, 'question' );
3248
+ if ( questions.length && [ 'qnEdit', 'nameChange' ].includes( qn.type ) ) {
3249
+ questions.forEach( ( qnIdx ) => {
3250
+ if ( qn.type == 'qnEdit' ) {
3251
+ getsubmitDetails[0].questionAnswers[sectionDetails].questions[qnIdx] = qn.question;
3252
+ } else {
3253
+ getsubmitDetails[0].questionAnswers[sectionDetails].questions[qnIdx].qname = qn.question.qname;
3254
+ }
3255
+ } );
3256
+ }
3257
+ }
3258
+ } );
3259
+ }
3260
+ } );
3229
3261
  if ( modifiedCount ) {
3230
3262
  getsubmitDetails[0].checklistStatus = 'inprogress';
3231
3263
  getsubmitDetails[0].date_string = dayjs( currentdate ).format( 'YYYY-MM-DD' );