tango-app-api-trax 3.9.2 → 3.9.4
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
|
@@ -437,12 +437,14 @@ export async function redoChecklist( req, res ) {
|
|
|
437
437
|
}
|
|
438
438
|
|
|
439
439
|
|
|
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 } );
|
|
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
|
+
|
|
441
442
|
if ( !checklistDetails ) {
|
|
442
443
|
return res.sendError( 'No data found', 204 );
|
|
443
444
|
}
|
|
444
445
|
let question = checklistDetails.questionAnswers;
|
|
445
446
|
|
|
447
|
+
let checklistConfigDetails = await checklistService.findOne( { _id: checklistDetails.sourceCheckList_id }, { redoValidity: 1 } );
|
|
446
448
|
|
|
447
449
|
let sectionIndex = question.findIndex( ( sec ) => sec.sectionName == req.body.payload.sectionName );
|
|
448
450
|
if ( sectionIndex == -1 ) {
|
|
@@ -451,37 +453,97 @@ export async function redoChecklist( req, res ) {
|
|
|
451
453
|
|
|
452
454
|
let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.qno == req.body.payload.qno );
|
|
453
455
|
|
|
454
|
-
let data = { ...question[sectionIndex].questions[findQuestion], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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
|
+
if ( Array.isArray( question?.[sectionIndex]?.questions?.[eleIndex]?.answers )?.length ) {
|
|
469
|
+
question[sectionIndex].questions[eleIndex].answers.forEach( ( ans ) => {
|
|
470
|
+
ans.validationAnswer = '';
|
|
471
|
+
delete ans.redoComment;
|
|
472
|
+
delete ans.redo;
|
|
473
|
+
} );
|
|
474
|
+
}
|
|
475
|
+
question[sectionIndex].questions[eleIndex].userAnswer = [];
|
|
476
|
+
question[sectionIndex].questions[eleIndex].remarks = '';
|
|
477
|
+
} );
|
|
478
|
+
}
|
|
479
|
+
} );
|
|
480
|
+
// data.answers.forEach( ( item ) => {
|
|
481
|
+
// if ( item.showLinked ) {
|
|
482
|
+
// item.nestedQuestion = [];
|
|
483
|
+
// item.showLinked = false;
|
|
484
|
+
// item.linkedQuestion = 0;
|
|
485
|
+
// }
|
|
486
|
+
// } );
|
|
487
|
+
// }
|
|
488
|
+
}
|
|
489
|
+
let userAnswer = Array.isArray( data.userAnswer ) ? [ ...data.userAnswer ] : [];
|
|
490
|
+
|
|
491
|
+
question[sectionIndex].questions[findQuestion] = data;
|
|
492
|
+
if ( isSingleAnswerRedo ) {
|
|
493
|
+
let targetQuestion = question[sectionIndex].questions[findQuestion];
|
|
494
|
+
let targetUserAnswerIndex = targetQuestion.userAnswer?.findIndex( ( ele ) => ele.answer == req.body.payload.answerName );
|
|
495
|
+
let targetUserAnswer = targetQuestion.userAnswer[targetUserAnswerIndex];
|
|
496
|
+
if ( targetUserAnswer && Array.isArray( targetQuestion.answers ) ) {
|
|
497
|
+
let matchedAnsIdx = targetQuestion.answers.findIndex( ( ans ) => {
|
|
498
|
+
// if ( targetUserAnswer.no !== undefined && ans.index === targetUserAnswer.no ) return true;
|
|
499
|
+
// if ( targetUserAnswer.index !== undefined && ans.index === targetUserAnswer.index ) return true;
|
|
500
|
+
// if ( targetUserAnswer.answeroptionNumber !== undefined && ans.answeroptionNumber === targetUserAnswer.answeroptionNumber ) return true;
|
|
501
|
+
return ans.answer === targetUserAnswer.answer;
|
|
464
502
|
} );
|
|
503
|
+
if ( matchedAnsIdx !== -1 ) {
|
|
504
|
+
targetQuestion.answers[matchedAnsIdx].redo = true;
|
|
505
|
+
targetQuestion.answers[matchedAnsIdx].validationAnswer = '';
|
|
506
|
+
targetQuestion.answers[matchedAnsIdx].redoComment = req.body.payload?.checklistDescription || '';
|
|
507
|
+
targetQuestion.remarks = '';
|
|
508
|
+
}
|
|
509
|
+
targetQuestion.userAnswer.splice( targetUserAnswerIndex, 1 );
|
|
465
510
|
}
|
|
466
|
-
} );
|
|
467
|
-
// data.answers.forEach( ( item ) => {
|
|
468
|
-
// if ( item.showLinked ) {
|
|
469
|
-
// item.nestedQuestion = [];
|
|
470
|
-
// item.showLinked = false;
|
|
471
|
-
// item.linkedQuestion = 0;
|
|
472
|
-
// }
|
|
473
|
-
// } );
|
|
474
|
-
// }
|
|
475
|
-
let userAnswer = data.userAnswer;
|
|
476
511
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
512
|
+
let currentQno = req.body.payload.qno;
|
|
513
|
+
let parentQIndex = -1;
|
|
514
|
+
// let parentAnsIndex = -1;
|
|
515
|
+
for ( let i = 0; i < question[sectionIndex].questions.length; i++ ) {
|
|
516
|
+
let parentAnswers = question[sectionIndex].questions[i].answers || [];
|
|
517
|
+
let foundAnsIdx = parentAnswers.findIndex( ( ans ) => Array.isArray( ans?.nestedQuestion ) && ans.nestedQuestion.some( ( ele ) => parseInt( ele ) == currentQno ) );
|
|
518
|
+
if ( foundAnsIdx !== -1 ) {
|
|
519
|
+
parentQIndex = i;
|
|
520
|
+
// parentAnsIndex = foundAnsIdx;
|
|
521
|
+
break;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if ( parentQIndex !== -1 ) {
|
|
525
|
+
let parentQno = question[sectionIndex].questions[parentQIndex].qno;
|
|
526
|
+
question[sectionIndex].questions[findQuestion].parentQno = parentQno;
|
|
527
|
+
// question[sectionIndex].questions[findQuestion].remarks = '';
|
|
528
|
+
// question[sectionIndex].questions[parentQIndex].answers[parentAnsIndex].redo = true;
|
|
529
|
+
// question[sectionIndex].questions[parentQIndex].answers[parentAnsIndex].validationAnswer = '';
|
|
530
|
+
}
|
|
531
|
+
} else {
|
|
532
|
+
question[sectionIndex].questions[findQuestion].userAnswer = [];
|
|
533
|
+
if ( Array.isArray( question[sectionIndex].questions[findQuestion].answers ) ) {
|
|
534
|
+
question[sectionIndex].questions[findQuestion].answers.forEach( ( ans ) => {
|
|
535
|
+
ans.validationAnswer = '';
|
|
536
|
+
delete ans.redoComment;
|
|
537
|
+
delete ans.redo;
|
|
538
|
+
} );
|
|
539
|
+
}
|
|
540
|
+
question[sectionIndex].questions[findQuestion].remarks = '';
|
|
541
|
+
}
|
|
480
542
|
checklistDetails.questionAnswers = question;
|
|
481
543
|
let updateData = {
|
|
482
|
-
checklistStatus: 'open',
|
|
544
|
+
checklistStatus: checklistDetails.checklistStatus != 'submit' ? checklistDetails.checklistStatus : 'open',
|
|
483
545
|
redoStatus: true,
|
|
484
|
-
reinitiateStatus: true,
|
|
546
|
+
...( !checklistConfigDetails?.redoValidity && { reinitiateStatus: true } ),
|
|
485
547
|
questionAnswers: question,
|
|
486
548
|
...( checklistDetails.checklistStatus != 'submit' && checklistDetails.redoStatus ) ? { redoEdit: true } : {},
|
|
487
549
|
...( ( checklistDetails.redoEdit === undefined && checklistConfigDetails.redoValidity ) ) ? { scheduleEndTime_iso: dayjs( checklistDetails.scheduleEndTime_iso ).add( checklistConfigDetails.redoValidity, 'day' ).format() } :{},
|
|
@@ -118,7 +118,7 @@ export async function startChecklist( req, res ) {
|
|
|
118
118
|
$and: [
|
|
119
119
|
{ _id: new ObjectId( requestData.processedcheckListId ) },
|
|
120
120
|
{ userId: req.user._id },
|
|
121
|
-
{ date_string: requestData.date },
|
|
121
|
+
{ $or: [ { date_string: requestData.date }, { redoStatus: true } ] },
|
|
122
122
|
],
|
|
123
123
|
},
|
|
124
124
|
} );
|
|
@@ -137,7 +137,9 @@ export async function startChecklist( req, res ) {
|
|
|
137
137
|
let updateQuery = {};
|
|
138
138
|
updateQuery._id = new ObjectId( requestData.processedcheckListId );
|
|
139
139
|
updateQuery.userId = req.user._id;
|
|
140
|
-
|
|
140
|
+
if ( getBeforeChecklist?.[0]?.date_string == dayjs().format( 'YYYY-MM-DD' ) ) {
|
|
141
|
+
updateQuery.date_string = requestData.date;
|
|
142
|
+
}
|
|
141
143
|
|
|
142
144
|
if ( PCLQusestion && PCLQusestion?.questionAnswers && PCLQusestion?.questionAnswers.length > 0 ) {
|
|
143
145
|
await PCLQusestion.questionAnswers.forEach( ( section ) => {
|
|
@@ -317,7 +319,7 @@ export async function startChecklist( req, res ) {
|
|
|
317
319
|
return res.sendError( 'something went wrong please try again', 500 );
|
|
318
320
|
}
|
|
319
321
|
} catch ( e ) {
|
|
320
|
-
|
|
322
|
+
console.log( 'e =>', e );
|
|
321
323
|
logger.error( { function: 'startChecklist', error: e, body: req.body } );
|
|
322
324
|
return res.sendError( e, 500 );
|
|
323
325
|
}
|
|
@@ -661,12 +663,12 @@ export async function sopMobilechecklistQuestionValidatorv1( req, res, next ) {
|
|
|
661
663
|
let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qname == question.oldQname || secQuestion.qname == question.qname );
|
|
662
664
|
if ( sectionQuestion.length ) {
|
|
663
665
|
if ( requestData.submittype == 'submit' ) {
|
|
664
|
-
if ( ( [ 'multipleImage', 'multiplechoicemultiple' ].includes( question.answerType ) || ( question.answerType =='dropdown' && question.allowMultiple ) ) ) {
|
|
666
|
+
if ( ( [ 'multipleImage', 'multiplechoicemultiple', 'image/video' ].includes( question.answerType ) || ( question.answerType =='dropdown' && question.allowMultiple ) ) ) {
|
|
665
667
|
if ( ( !sectionQuestion[0].linkType || ( sectionQuestion[0].linkType && sectionQuestion[0].linkquestionenabled ) ) && ( sectionQuestion[0].Multianswer == null || sectionQuestion[0].Multianswer == '' || !sectionQuestion[0].Multianswer.length ) ) {
|
|
666
668
|
validationCount++;
|
|
667
669
|
}
|
|
668
670
|
} else {
|
|
669
|
-
if ( ( !
|
|
671
|
+
if ( ( !sectionQuestion[0].linkType && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) || ( sectionQuestion[0].linkType && sectionQuestion[0].linkquestionenabled && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) ) {
|
|
670
672
|
validationCount++;
|
|
671
673
|
}
|
|
672
674
|
}
|
|
@@ -1819,7 +1821,6 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1819
1821
|
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1820
1822
|
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1821
1823
|
if ( ( separatedArray[s].answer == qaans[k].answer ) ) {
|
|
1822
|
-
console.log( qaans[k].redo, separatedArray[s].redo, qaans[k].redo == separatedArray[s].redo, qaans[k].answer );
|
|
1823
1824
|
if ( ( getChecklistQA?.redoEdit && qaans[k].redo == separatedArray[s].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1824
1825
|
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1825
1826
|
if ( separatedArray[s].validationAnswer ) {
|
|
@@ -2723,6 +2724,9 @@ export async function submitChecklist( req, res ) {
|
|
|
2723
2724
|
let flagCount = QuestionFlag( req, res );
|
|
2724
2725
|
updateData.questionFlag = flagCount;
|
|
2725
2726
|
updateData.submitTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
|
|
2727
|
+
if ( getchecklist?.[0]?.redoEdit != undefined ) {
|
|
2728
|
+
updateData.redoEdit = false;
|
|
2729
|
+
}
|
|
2726
2730
|
if ( requestData.deviceDetails && requestData.deviceDetails != '' ) {
|
|
2727
2731
|
updateData.deviceDetails =JSON.parse( requestData.deviceDetails );
|
|
2728
2732
|
}
|
|
@@ -3503,6 +3507,9 @@ export async function dashboardv1( req, res ) {
|
|
|
3503
3507
|
// const { store_id, date } = req.query;
|
|
3504
3508
|
const { date } = req.query;
|
|
3505
3509
|
const userId = req.user._id;
|
|
3510
|
+
let fromDate = new Date( req.query.date );
|
|
3511
|
+
let toDate = new Date( req.query.date );
|
|
3512
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
3506
3513
|
|
|
3507
3514
|
// //Get User Based Checklist //
|
|
3508
3515
|
const clientId = { client_id: req.user.clientId };
|
|
@@ -3519,7 +3526,7 @@ export async function dashboardv1( req, res ) {
|
|
|
3519
3526
|
...storeMatch,
|
|
3520
3527
|
};
|
|
3521
3528
|
const buildPipeline = ( matchExtraConditions = {} ) => [
|
|
3522
|
-
{ $match: { ...baseMatch, ...matchExtraConditions } },
|
|
3529
|
+
{ $match: { $or: [ { ...baseMatch, ...matchExtraConditions }, { $and: [ { redoStatus: true }, { scheduleStartTime_iso: { $lt: toDate } }, { scheduleEndTime_iso: { $gte: fromDate } }, { userId }, { ...storeMatch } ] } ] } },
|
|
3523
3530
|
{
|
|
3524
3531
|
$facet: {
|
|
3525
3532
|
total: [ { $count: 'total' } ],
|
|
@@ -3539,9 +3546,7 @@ export async function dashboardv1( req, res ) {
|
|
|
3539
3546
|
},
|
|
3540
3547
|
];
|
|
3541
3548
|
|
|
3542
|
-
|
|
3543
|
-
let toDate = new Date( req.query.date );
|
|
3544
|
-
toDate.setDate( toDate.getDate() + 1 );
|
|
3549
|
+
|
|
3545
3550
|
const taskBaseMatch = {
|
|
3546
3551
|
// eslint-disable-next-line camelcase
|
|
3547
3552
|
// store_id,
|
|
@@ -3719,6 +3724,9 @@ export async function checklistv1( req, res ) {
|
|
|
3719
3724
|
// const { store_id, date, checklistStatus, searchValue } = req.query;
|
|
3720
3725
|
const { date, checklistStatus, searchValue } = req.query;
|
|
3721
3726
|
const userId = req.user._id;
|
|
3727
|
+
let fromDate = new Date( req.query.date );
|
|
3728
|
+
let toDate = new Date( req.query.date );
|
|
3729
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
3722
3730
|
|
|
3723
3731
|
// Get User Based Checklist //
|
|
3724
3732
|
const clientId = { client_id: req.user.clientId };
|
|
@@ -3730,7 +3738,7 @@ export async function checklistv1( req, res ) {
|
|
|
3730
3738
|
// eslint-disable-next-line camelcase
|
|
3731
3739
|
// { store_id },
|
|
3732
3740
|
{ userId },
|
|
3733
|
-
{ date_string: date },
|
|
3741
|
+
{ $or: [ { date_string: date }, { $and: [ { redoStatus: true }, { scheduleStartTime_iso: { $lt: toDate } }, { scheduleEndTime_iso: { $gte: fromDate } } ] } ] },
|
|
3734
3742
|
{ timeFlagStatus: true },
|
|
3735
3743
|
...matchExtraConditions,
|
|
3736
3744
|
clientId,
|
|
@@ -3792,9 +3800,7 @@ export async function checklistv1( req, res ) {
|
|
|
3792
3800
|
return pipeline;
|
|
3793
3801
|
};
|
|
3794
3802
|
|
|
3795
|
-
|
|
3796
|
-
let toDate = new Date( req.query.date );
|
|
3797
|
-
toDate.setDate( toDate.getDate() + 1 );
|
|
3803
|
+
|
|
3798
3804
|
const taskBuildPipeline = ( matchExtraConditions = [], projectExtraConditions = {} ) => {
|
|
3799
3805
|
const matchConditions = [
|
|
3800
3806
|
// eslint-disable-next-line camelcase
|
|
@@ -4174,7 +4180,7 @@ export async function questionList( req, res ) {
|
|
|
4174
4180
|
checkvalidation = answer.validationAnswer;
|
|
4175
4181
|
}
|
|
4176
4182
|
}
|
|
4177
|
-
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation } );
|
|
4183
|
+
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation, ...( answer.redo && { redo: answer.redo } ) } );
|
|
4178
4184
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
|
|
4179
4185
|
}
|
|
4180
4186
|
|