tango-app-api-trax 3.8.15 → 3.8.16-nike

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.8.15",
3
+ "version": "3.8.16-nike",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -29,7 +29,7 @@
29
29
  "nodemon": "^3.1.4",
30
30
  "path": "^0.12.7",
31
31
  "puppeteer": "^24.39.1",
32
- "tango-api-schema": "^2.5.72",
32
+ "tango-api-schema": "^2.5.96",
33
33
  "tango-app-api-middleware": "^3.5.2",
34
34
  "url": "^0.11.4",
35
35
  "winston": "^3.13.1",
@@ -53,31 +53,31 @@ async function getBrandInfo( clientId ) {
53
53
  return brandInfo;
54
54
  }
55
55
 
56
- async function streamChecklistZip( res, checklistList, brandInfo, zipBaseName ) {
57
- const zipName = `${sanitizeFilenamePart( zipBaseName, 'visit-checklists' )}_${dayjs().format( 'YYYY-MM-DD_HH-mm' )}.zip`;
56
+ // async function streamChecklistZip( res, checklistList, brandInfo, zipBaseName ) {
57
+ // const zipName = `${sanitizeFilenamePart( zipBaseName, 'visit-checklists' )}_${dayjs().format( 'YYYY-MM-DD_HH-mm' )}.zip`;
58
58
 
59
- res.status( 200 );
60
- res.setHeader( 'Content-Type', 'application/zip' );
61
- res.setHeader( 'Content-Disposition', `attachment; filename="${zipName.replace( /"/g, '\\"' )}"` );
62
- res.setHeader( 'Cache-Control', 'private, no-cache' );
59
+ // res.status( 200 );
60
+ // res.setHeader( 'Content-Type', 'application/zip' );
61
+ // res.setHeader( 'Content-Disposition', `attachment; filename="${zipName.replace( /"/g, '\\"' )}"` );
62
+ // res.setHeader( 'Cache-Control', 'private, no-cache' );
63
63
 
64
- const archive = archiver( 'zip', { zlib: { level: 9 } } );
64
+ // const archive = archiver( 'zip', { zlib: { level: 9 } } );
65
65
 
66
- archive.on( 'error', ( err ) => {
67
- throw err;
68
- } );
66
+ // archive.on( 'error', ( err ) => {
67
+ // throw err;
68
+ // } );
69
69
 
70
- archive.pipe( res );
70
+ // archive.pipe( res );
71
71
 
72
- for ( const checklistDetails of checklistList ) {
73
- const templateData = buildVisitChecklistTemplateData( checklistDetails, brandInfo );
74
- const pdfBuffer = await generateVisitChecklistPDF( templateData );
75
- const pdfName = `${sanitizeFilenamePart( checklistDetails.storeName || checklistDetails.store_id || checklistDetails._id, 'store' )}_${sanitizeFilenamePart( checklistDetails.checkListName || 'Visit Checklist' )}.pdf`;
76
- archive.append( Buffer.isBuffer( pdfBuffer ) ? pdfBuffer : Buffer.from( pdfBuffer ), { name: pdfName } );
77
- }
72
+ // for ( const checklistDetails of checklistList ) {
73
+ // const templateData = buildVisitChecklistTemplateData( checklistDetails, brandInfo );
74
+ // const pdfBuffer = await generateVisitChecklistPDF( templateData );
75
+ // const pdfName = `${sanitizeFilenamePart( checklistDetails.storeName || checklistDetails.store_id || checklistDetails._id, 'store' )}_${sanitizeFilenamePart( checklistDetails.checkListName || 'Visit Checklist' )}.pdf`;
76
+ // archive.append( Buffer.isBuffer( pdfBuffer ) ? pdfBuffer : Buffer.from( pdfBuffer ), { name: pdfName } );
77
+ // }
78
78
 
79
- await archive.finalize();
80
- }
79
+ // await archive.finalize();
80
+ // }
81
81
 
82
82
  async function createChecklistZipBuffer( checklistList, brandInfo ) {
83
83
  const output = new PassThrough();
@@ -139,6 +139,7 @@ export async function getcustomerunattendedlist( req, res ) {
139
139
  }
140
140
  let url = JSON.parse( process.env.LAMBDAURL );
141
141
  let resultData = await LamdaServiceCall( url.customerUnattended, req.body );
142
+ console.log( '🚀 ~ getcustomerunattendedlist ~ url.customerUnattended:', url.customerUnattended );
142
143
  if ( resultData ) {
143
144
  if ( resultData.status_code == '200' ) {
144
145
  return res.sendSuccess( resultData );
@@ -436,12 +437,14 @@ export async function redoChecklist( req, res ) {
436
437
  }
437
438
 
438
439
 
439
- let checklistDetails = await processedChecklist.findOne( { _id: req.body.payload._id }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1, submitTime: 1, userName: 1, answerType: 1, coverage: 1, userEmail: 1 } );
440
+ let checklistDetails = await processedChecklist.findOne( { _id: req.body.payload._id }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1, submitTime: 1, userName: 1, answerType: 1, coverage: 1, userEmail: 1, scheduleEndTime_iso: 1, redoEdit: 1 } );
441
+
440
442
  if ( !checklistDetails ) {
441
443
  return res.sendError( 'No data found', 204 );
442
444
  }
443
445
  let question = checklistDetails.questionAnswers;
444
446
 
447
+ let checklistConfigDetails = await checklistService.findOne( { _id: checklistDetails.sourceCheckList_id }, { redoValidity: 1 } );
445
448
 
446
449
  let sectionIndex = question.findIndex( ( sec ) => sec.sectionName == req.body.payload.sectionName );
447
450
  if ( sectionIndex == -1 ) {
@@ -450,38 +453,86 @@ export async function redoChecklist( req, res ) {
450
453
 
451
454
  let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.qno == req.body.payload.qno );
452
455
 
453
- let data = { ...question[sectionIndex].questions[findQuestion], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
454
- // if ( checklistDetails.client_id == '458' ) {
455
- data.answers.forEach( ( item ) => {
456
- if ( item.showLinked ) {
457
- item.nestedQuestion.forEach( ( ele ) => {
458
- let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn.qno == parseInt( ele ) );
459
- let element = { ...question[sectionIndex].questions[eleIndex], redo: true, redoComment: '', linkquestionenabled: false };
460
- question[sectionIndex].questions[eleIndex] = element;
461
- question[sectionIndex].questions[eleIndex].userAnswer = [];
462
- question[sectionIndex].questions[eleIndex].remarks = '';
456
+ let data = { ...question[sectionIndex].questions[findQuestion], redo: true, ...( !req.body.payload?.answerIndex && { redoComment: req.body.payload?.checklistDescription || '' } ) };
457
+ let answerIndex = req.body.payload?.answerIndex;
458
+ let isSingleAnswerRedo = answerIndex != null;
459
+
460
+ if ( !isSingleAnswerRedo ) {
461
+ // if ( checklistDetails.client_id == '458' ) {
462
+ data.answers.forEach( ( item ) => {
463
+ if ( item.showLinked ) {
464
+ item.nestedQuestion.forEach( ( ele ) => {
465
+ let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn.qno == parseInt( ele ) );
466
+ let element = { ...question[sectionIndex].questions[eleIndex], redo: true, redoComment: '', linkquestionenabled: false };
467
+ question[sectionIndex].questions[eleIndex] = element;
468
+ question[sectionIndex].questions[eleIndex].userAnswer = [];
469
+ question[sectionIndex].questions[eleIndex].remarks = '';
470
+ } );
471
+ }
472
+ } );
473
+ // data.answers.forEach( ( item ) => {
474
+ // if ( item.showLinked ) {
475
+ // item.nestedQuestion = [];
476
+ // item.showLinked = false;
477
+ // item.linkedQuestion = 0;
478
+ // }
479
+ // } );
480
+ // }
481
+ }
482
+ let userAnswer = Array.isArray( data.userAnswer ) ? [ ...data.userAnswer ] : [];
483
+
484
+ question[sectionIndex].questions[findQuestion] = data;
485
+ if ( isSingleAnswerRedo ) {
486
+ let targetQuestion = question[sectionIndex].questions[findQuestion];
487
+ let targetUserAnswerIndex = targetQuestion.userAnswer?.findIndex( ( ele ) => ele.answer == req.body.payload.answerName );
488
+ let targetUserAnswer = targetQuestion.userAnswer[targetUserAnswerIndex];
489
+ if ( targetUserAnswer && Array.isArray( targetQuestion.answers ) ) {
490
+ let matchedAnsIdx = targetQuestion.answers.findIndex( ( ans ) => {
491
+ // if ( targetUserAnswer.no !== undefined && ans.index === targetUserAnswer.no ) return true;
492
+ // if ( targetUserAnswer.index !== undefined && ans.index === targetUserAnswer.index ) return true;
493
+ // if ( targetUserAnswer.answeroptionNumber !== undefined && ans.answeroptionNumber === targetUserAnswer.answeroptionNumber ) return true;
494
+ return ans.answer === targetUserAnswer.answer;
463
495
  } );
496
+ if ( matchedAnsIdx !== -1 ) {
497
+ targetQuestion.answers[matchedAnsIdx].redo = true;
498
+ targetQuestion.answers[matchedAnsIdx].validationAnswer = '';
499
+ targetQuestion.answers[matchedAnsIdx].redoComment = req.body.payload?.checklistDescription || '';
500
+ targetQuestion.remarks = '';
501
+ }
502
+ targetQuestion.userAnswer.splice( targetUserAnswerIndex, 1 );
464
503
  }
465
- } );
466
- // data.answers.forEach( ( item ) => {
467
- // if ( item.showLinked ) {
468
- // item.nestedQuestion = [];
469
- // item.showLinked = false;
470
- // item.linkedQuestion = 0;
471
- // }
472
- // } );
473
- // }
474
- let userAnswer = data.userAnswer;
475
504
 
476
- question[sectionIndex].questions[findQuestion] = data;
477
- question[sectionIndex].questions[findQuestion].userAnswer = [];
478
- question[sectionIndex].questions[findQuestion].remarks = '';
505
+ let currentQno = req.body.payload.qno;
506
+ let parentQIndex = -1;
507
+ // let parentAnsIndex = -1;
508
+ for ( let i = 0; i < question[sectionIndex].questions.length; i++ ) {
509
+ let parentAnswers = question[sectionIndex].questions[i].answers || [];
510
+ let foundAnsIdx = parentAnswers.findIndex( ( ans ) => Array.isArray( ans?.nestedQuestion ) && ans.nestedQuestion.some( ( ele ) => parseInt( ele ) == currentQno ) );
511
+ if ( foundAnsIdx !== -1 ) {
512
+ parentQIndex = i;
513
+ // parentAnsIndex = foundAnsIdx;
514
+ break;
515
+ }
516
+ }
517
+ if ( parentQIndex !== -1 ) {
518
+ let parentQno = question[sectionIndex].questions[parentQIndex].qno;
519
+ question[sectionIndex].questions[findQuestion].parentQno = parentQno;
520
+ // question[sectionIndex].questions[findQuestion].remarks = '';
521
+ // question[sectionIndex].questions[parentQIndex].answers[parentAnsIndex].redo = true;
522
+ // question[sectionIndex].questions[parentQIndex].answers[parentAnsIndex].validationAnswer = '';
523
+ }
524
+ } else {
525
+ question[sectionIndex].questions[findQuestion].userAnswer = [];
526
+ question[sectionIndex].questions[findQuestion].remarks = '';
527
+ }
479
528
  checklistDetails.questionAnswers = question;
480
529
  let updateData = {
481
- checklistStatus: 'open',
530
+ checklistStatus: checklistDetails.checklistStatus != 'submit' ? checklistDetails.checklistStatus : 'open',
482
531
  redoStatus: true,
483
532
  reinitiateStatus: true,
484
533
  questionAnswers: question,
534
+ ...( checklistDetails.checklistStatus != 'submit' && checklistDetails.redoStatus ) ? { redoEdit: true } : {},
535
+ ...( !Object.prototype.hasOwnProperty.call( checklistDetails, 'redoEdit' ) && { scheduleEndTime_iso: dayjs( checklistDetails.scheduleEndTime_iso ).add( checklistConfigDetails.redoValidity, 'day' ).format() } ),
485
536
  };
486
537
 
487
538
  let response = await processedChecklist.updateOne( { _id: req.body.payload._id }, updateData );
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-invalid-this */
1
2
  import Handlebars from 'handlebars';
2
3
  import fs from 'fs';
3
4