tango-app-api-trax 3.8.16 → 3.8.17-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 +2 -2
- package/src/controllers/download.controller.js +19 -19
- package/src/controllers/gallery.controller.js +88 -25
- package/src/controllers/handlebar-helper.js +1 -0
- package/src/controllers/internalTrax.controller.js +1017 -14
- package/src/controllers/mobileTrax.controller.js +334 -201
- package/src/controllers/teaxFlag.controller.js +5 -5
- package/src/controllers/trax.controller.js +6 -2
- package/src/hbs/recurringFlag.hbs +250 -0
- package/src/hbs/template.hbs +47 -32
- package/src/hbs/visit-checklist.hbs +107 -62
- package/src/hbs/weeklyWrap.hbs +218 -0
- package/src/routes/internalTraxApi.router.js +4 -0
- package/src/services/recurringFlagTracker.service.js +33 -0
- package/src/utils/visitChecklistPdf.utils.js +6 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-trax",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.17-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.
|
|
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
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
64
|
+
// const archive = archiver( 'zip', { zlib: { level: 9 } } );
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
// archive.on( 'error', ( err ) => {
|
|
67
|
+
// throw err;
|
|
68
|
+
// } );
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
// archive.pipe( res );
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
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,98 @@ 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
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
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].answers.forEach( ( ans ) => {
|
|
469
|
+
ans.validationAnswer = '';
|
|
470
|
+
delete ans.redoComment;
|
|
471
|
+
delete ans.redo;
|
|
472
|
+
} );
|
|
473
|
+
question[sectionIndex].questions[eleIndex].userAnswer = [];
|
|
474
|
+
question[sectionIndex].questions[eleIndex].remarks = '';
|
|
475
|
+
} );
|
|
476
|
+
}
|
|
477
|
+
} );
|
|
478
|
+
// data.answers.forEach( ( item ) => {
|
|
479
|
+
// if ( item.showLinked ) {
|
|
480
|
+
// item.nestedQuestion = [];
|
|
481
|
+
// item.showLinked = false;
|
|
482
|
+
// item.linkedQuestion = 0;
|
|
483
|
+
// }
|
|
484
|
+
// } );
|
|
485
|
+
// }
|
|
486
|
+
}
|
|
487
|
+
let userAnswer = Array.isArray( data.userAnswer ) ? [ ...data.userAnswer ] : [];
|
|
488
|
+
|
|
489
|
+
question[sectionIndex].questions[findQuestion] = data;
|
|
490
|
+
if ( isSingleAnswerRedo ) {
|
|
491
|
+
let targetQuestion = question[sectionIndex].questions[findQuestion];
|
|
492
|
+
let targetUserAnswerIndex = targetQuestion.userAnswer?.findIndex( ( ele ) => ele.answer == req.body.payload.answerName );
|
|
493
|
+
let targetUserAnswer = targetQuestion.userAnswer[targetUserAnswerIndex];
|
|
494
|
+
if ( targetUserAnswer && Array.isArray( targetQuestion.answers ) ) {
|
|
495
|
+
let matchedAnsIdx = targetQuestion.answers.findIndex( ( ans ) => {
|
|
496
|
+
// if ( targetUserAnswer.no !== undefined && ans.index === targetUserAnswer.no ) return true;
|
|
497
|
+
// if ( targetUserAnswer.index !== undefined && ans.index === targetUserAnswer.index ) return true;
|
|
498
|
+
// if ( targetUserAnswer.answeroptionNumber !== undefined && ans.answeroptionNumber === targetUserAnswer.answeroptionNumber ) return true;
|
|
499
|
+
return ans.answer === targetUserAnswer.answer;
|
|
463
500
|
} );
|
|
501
|
+
if ( matchedAnsIdx !== -1 ) {
|
|
502
|
+
targetQuestion.answers[matchedAnsIdx].redo = true;
|
|
503
|
+
targetQuestion.answers[matchedAnsIdx].validationAnswer = '';
|
|
504
|
+
targetQuestion.answers[matchedAnsIdx].redoComment = req.body.payload?.checklistDescription || '';
|
|
505
|
+
targetQuestion.remarks = '';
|
|
506
|
+
}
|
|
507
|
+
targetQuestion.userAnswer.splice( targetUserAnswerIndex, 1 );
|
|
464
508
|
}
|
|
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
509
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
510
|
+
let currentQno = req.body.payload.qno;
|
|
511
|
+
let parentQIndex = -1;
|
|
512
|
+
// let parentAnsIndex = -1;
|
|
513
|
+
for ( let i = 0; i < question[sectionIndex].questions.length; i++ ) {
|
|
514
|
+
let parentAnswers = question[sectionIndex].questions[i].answers || [];
|
|
515
|
+
let foundAnsIdx = parentAnswers.findIndex( ( ans ) => Array.isArray( ans?.nestedQuestion ) && ans.nestedQuestion.some( ( ele ) => parseInt( ele ) == currentQno ) );
|
|
516
|
+
if ( foundAnsIdx !== -1 ) {
|
|
517
|
+
parentQIndex = i;
|
|
518
|
+
// parentAnsIndex = foundAnsIdx;
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
if ( parentQIndex !== -1 ) {
|
|
523
|
+
let parentQno = question[sectionIndex].questions[parentQIndex].qno;
|
|
524
|
+
question[sectionIndex].questions[findQuestion].parentQno = parentQno;
|
|
525
|
+
// question[sectionIndex].questions[findQuestion].remarks = '';
|
|
526
|
+
// question[sectionIndex].questions[parentQIndex].answers[parentAnsIndex].redo = true;
|
|
527
|
+
// question[sectionIndex].questions[parentQIndex].answers[parentAnsIndex].validationAnswer = '';
|
|
528
|
+
}
|
|
529
|
+
} else {
|
|
530
|
+
question[sectionIndex].questions[findQuestion].userAnswer = [];
|
|
531
|
+
if ( Array.isArray( question[sectionIndex].questions[findQuestion].answers ) ) {
|
|
532
|
+
question[sectionIndex].questions[findQuestion].answers.forEach( ( ans ) => {
|
|
533
|
+
ans.validationAnswer = '';
|
|
534
|
+
delete ans.redoComment;
|
|
535
|
+
delete ans.redo;
|
|
536
|
+
} );
|
|
537
|
+
}
|
|
538
|
+
question[sectionIndex].questions[findQuestion].remarks = '';
|
|
539
|
+
}
|
|
479
540
|
checklistDetails.questionAnswers = question;
|
|
480
541
|
let updateData = {
|
|
481
|
-
checklistStatus: 'open',
|
|
542
|
+
checklistStatus: checklistDetails.checklistStatus != 'submit' ? checklistDetails.checklistStatus : 'open',
|
|
482
543
|
redoStatus: true,
|
|
483
544
|
reinitiateStatus: true,
|
|
484
545
|
questionAnswers: question,
|
|
546
|
+
...( checklistDetails.checklistStatus != 'submit' && checklistDetails.redoStatus ) ? { redoEdit: true } : {},
|
|
547
|
+
...( ( checklistDetails.redoEdit === undefined && checklistConfigDetails.redoValidity ) && { scheduleEndTime_iso: dayjs( checklistDetails.scheduleEndTime_iso ).add( checklistConfigDetails.redoValidity, 'day' ).format() } ),
|
|
485
548
|
};
|
|
486
549
|
|
|
487
550
|
let response = await processedChecklist.updateOne( { _id: req.body.payload._id }, updateData );
|