tango-app-api-trax 3.4.1-alpha-20 → 3.4.1-approvecheck-0
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/index.js +2 -1
- package/package.json +3 -3
- package/src/controllers/activityLog.controller.js +292 -0
- package/src/controllers/download.controller.js +119 -3
- package/src/controllers/gallery.controller.js +195 -6
- package/src/controllers/internalTrax.controller.js +675 -10
- package/src/controllers/mobileTrax.controller.js +356 -983
- package/src/controllers/teaxFlag.controller.js +467 -2
- package/src/controllers/trax.controller.js +859 -266
- package/src/controllers/traxDashboard.controllers.js +1 -2
- package/src/dtos/downloadValidation.dtos.js +2 -1
- package/src/hbs/login-otp.hbs +943 -943
- package/src/routes/activityLog.router.js +18 -0
- package/src/routes/download.router.js +4 -0
- package/src/routes/gallery.routes.js +2 -1
- package/src/routes/internalTraxApi.router.js +3 -1
- package/src/routes/mobileTrax.routes.js +1 -3
- package/src/routes/trax.routes.js +5 -3
- package/src/routes/traxFlag.router.js +13 -1
- package/src/services/camera.service.js +14 -0
- package/src/services/processedchecklistconfig.services.js +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { logger } from 'tango-app-api-middleware';
|
|
3
|
+
import { logger, insertOpenSearchData } from 'tango-app-api-middleware';
|
|
4
4
|
import * as storeService from '../services/store.service.js';
|
|
5
5
|
import * as groupService from '../services/group.service.js';
|
|
6
6
|
import * as clusterService from '../services/cluster.service.js';
|
|
@@ -282,15 +282,16 @@ export async function approveChecklist( req, res ) {
|
|
|
282
282
|
if ( req.body?.storeId?.length ) {
|
|
283
283
|
query['store_id'] = { $in: req.body.storeId };
|
|
284
284
|
}
|
|
285
|
-
let checklistDetails = await processedChecklist.find( query, { _id: 1, checklistStatus: 1, storeName: 1, store_id: 1, userEmail: 1 } );
|
|
285
|
+
let checklistDetails = await processedChecklist.find( query, { _id: 1, checklistStatus: 1, storeName: 1, store_id: 1, userEmail: 1, client_id: 1, coverage: 1, checkListName: 1 } );
|
|
286
286
|
if ( !checklistDetails.length ) {
|
|
287
287
|
return res.sendError( 'No data found', 204 );
|
|
288
288
|
}
|
|
289
289
|
let idList = checklistDetails.filter( ( ele ) => ele.checklistStatus == 'submit' ).map( ( item ) => item._id );
|
|
290
290
|
if ( idList.length ) {
|
|
291
|
-
let updateResponse = await processedChecklist.updateMany( { _id: { $in: idList } }, { approvalStatus: true } );
|
|
291
|
+
let updateResponse = await processedChecklist.updateMany( { _id: { $in: idList } }, { approvalStatus: true , approvalTime:new Date(), approvalTime_string:dayjs.format("hh:mm A, DD MMM YYYY"), approvalByName:req.user.name, approvalByEmail:req.user.email} );
|
|
292
292
|
if ( updateResponse.modifiedCount || updateResponse.matchedCount ) {
|
|
293
293
|
let inputstores = checklistDetails.filter( ( data ) => data.checklistStatus == 'submit' );
|
|
294
|
+
let storeNames = inputstores.map( ( data ) => data.storeName );
|
|
294
295
|
|
|
295
296
|
|
|
296
297
|
let params = {
|
|
@@ -303,6 +304,10 @@ export async function approveChecklist( req, res ) {
|
|
|
303
304
|
},
|
|
304
305
|
'upsert': {
|
|
305
306
|
approvalStatus: true,
|
|
307
|
+
approvalTime:new Date(),
|
|
308
|
+
approvalTime_string:dayjs.format("hh:mm A, DD MMM YYYY"),
|
|
309
|
+
approvalByName:req.user.name,
|
|
310
|
+
approvalByEmail:req.user.email
|
|
306
311
|
},
|
|
307
312
|
};
|
|
308
313
|
|
|
@@ -315,7 +320,27 @@ export async function approveChecklist( req, res ) {
|
|
|
315
320
|
};
|
|
316
321
|
let url = JSON.parse( process.env.LAMBDAURL );
|
|
317
322
|
let searchResponse = await fetch( url.approveChecklist, requestOptions );
|
|
318
|
-
|
|
323
|
+
let logData= {
|
|
324
|
+
'client_id': checklistDetails[0].client_id,
|
|
325
|
+
'createAt': new Date(),
|
|
326
|
+
'sourceCheckList_id': req.body.sourceCheckList_id,
|
|
327
|
+
'checkListName': checklistDetails[0].checkListName,
|
|
328
|
+
'fromCheckListName': '',
|
|
329
|
+
'type': 'checklist',
|
|
330
|
+
'action': 'approved',
|
|
331
|
+
'storeName': '',
|
|
332
|
+
'store_id': '',
|
|
333
|
+
'createdByEmail': req.user.email,
|
|
334
|
+
'createdBy': req.user._id,
|
|
335
|
+
'coverage': checklistDetails[0].coverage,
|
|
336
|
+
'logDetails': {
|
|
337
|
+
'approved': storeNames,
|
|
338
|
+
},
|
|
339
|
+
'userType': req.user.userType,
|
|
340
|
+
};
|
|
341
|
+
console.log( 'logData', logData );
|
|
342
|
+
let urlopensearch = JSON.parse( process.env.OPENSEARCH );
|
|
343
|
+
insertOpenSearchData( urlopensearch.traxActivityLog, logData );
|
|
319
344
|
console.log( searchResponse.ok );
|
|
320
345
|
if ( searchResponse.ok ) {
|
|
321
346
|
let pendingstores = checklistDetails.filter( ( data ) => data.checklistStatus != 'submit' );
|
|
@@ -350,7 +375,7 @@ export async function redoChecklist( req, res ) {
|
|
|
350
375
|
}
|
|
351
376
|
|
|
352
377
|
|
|
353
|
-
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 } );
|
|
378
|
+
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 } );
|
|
354
379
|
if ( !checklistDetails ) {
|
|
355
380
|
return res.sendError( 'No data found', 204 );
|
|
356
381
|
}
|
|
@@ -440,7 +465,27 @@ export async function redoChecklist( req, res ) {
|
|
|
440
465
|
let url = JSON.parse( process.env.LAMBDAURL );
|
|
441
466
|
let searchResponse = await fetch( url.redoChecklist, requestOptions );
|
|
442
467
|
console.log( searchResponse.ok );
|
|
443
|
-
|
|
468
|
+
let logData= {
|
|
469
|
+
'client_id': checklistDetails.client_id,
|
|
470
|
+
'createAt': new Date(),
|
|
471
|
+
'sourceCheckList_id': checklistDetails.sourceCheckList_id,
|
|
472
|
+
'checkListName': checklistDetails.checkListName,
|
|
473
|
+
'fromCheckListName': checklistDetails.checkListName,
|
|
474
|
+
'type': 'checklist',
|
|
475
|
+
'action': checklistDetails.redoStatus?'multiredo': 'redo',
|
|
476
|
+
'storeName': checklistDetails?.storeName?checklistDetails?.storeName:'',
|
|
477
|
+
'store_id': checklistDetails?.store_id?checklistDetails?.store_id:'',
|
|
478
|
+
'userName': checklistDetails.userName,
|
|
479
|
+
'userEmail': checklistDetails.userEmail,
|
|
480
|
+
'createdByEmail': req.user.email,
|
|
481
|
+
'createdBy': req.user.userName,
|
|
482
|
+
'coverage': checklistDetails.coverage,
|
|
483
|
+
'logDetails': {},
|
|
484
|
+
'userType': req.user.userType,
|
|
485
|
+
};
|
|
486
|
+
let urlopensearch = JSON.parse( process.env.OPENSEARCH );
|
|
487
|
+
console.log( 'logData', logData );
|
|
488
|
+
insertOpenSearchData( urlopensearch.traxActivityLog, logData );
|
|
444
489
|
if ( searchResponse.ok ) {
|
|
445
490
|
return res.sendSuccess( 'Question redo successfully' );
|
|
446
491
|
} else {
|
|
@@ -455,6 +500,150 @@ export async function redoChecklist( req, res ) {
|
|
|
455
500
|
}
|
|
456
501
|
}
|
|
457
502
|
|
|
503
|
+
export async function redomultiChecklist( req, res ) {
|
|
504
|
+
try {
|
|
505
|
+
let inputData = req.body.payload.coverage==='user'?req.body.payload.userEmail:req.body.payload.storeName;
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
for ( let originalData of inputData ) {
|
|
509
|
+
if ( !originalData.checklistId ) {
|
|
510
|
+
return res.sendError( 'Id is Required', 400 );
|
|
511
|
+
}
|
|
512
|
+
if ( !originalData.section_id ) {
|
|
513
|
+
return res.sendError( 'Section id is Required', 400 );
|
|
514
|
+
}
|
|
515
|
+
if ( !req.body.payload.qno ) {
|
|
516
|
+
return res.sendError( 'Question number is Required', 400 );
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
let checklistDetails = await processedChecklist.findOne( { _id: originalData.checklistId }, { 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 } );
|
|
521
|
+
if ( !checklistDetails ) {
|
|
522
|
+
return res.sendError( 'No data found', 204 );
|
|
523
|
+
}
|
|
524
|
+
let question = checklistDetails.questionAnswers;
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
let sectionIndex = question.findIndex( ( sec ) => sec.sectionName == req.body.payload.sectionName );
|
|
528
|
+
if ( sectionIndex == -1 ) {
|
|
529
|
+
return res.sendError( 'section is not found', 400 );
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.qno == req.body.payload.qno );
|
|
533
|
+
|
|
534
|
+
let data = { ...question[sectionIndex].questions[findQuestion], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
|
|
535
|
+
// if ( checklistDetails.client_id == '458' ) {
|
|
536
|
+
data.answers.forEach( ( item ) => {
|
|
537
|
+
if ( item.showLinked ) {
|
|
538
|
+
item.nestedQuestion.forEach( ( ele ) => {
|
|
539
|
+
let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn.qno == parseInt( ele ) );
|
|
540
|
+
let element = { ...question[sectionIndex].questions[eleIndex], redo: true, redoComment: '', linkquestionenabled: false };
|
|
541
|
+
question[sectionIndex].questions[eleIndex] = element;
|
|
542
|
+
question[sectionIndex].questions[eleIndex].userAnswer = [];
|
|
543
|
+
question[sectionIndex].questions[eleIndex].remarks = '';
|
|
544
|
+
} );
|
|
545
|
+
}
|
|
546
|
+
} );
|
|
547
|
+
// data.answers.forEach( ( item ) => {
|
|
548
|
+
// if ( item.showLinked ) {
|
|
549
|
+
// item.nestedQuestion = [];
|
|
550
|
+
// item.showLinked = false;
|
|
551
|
+
// item.linkedQuestion = 0;
|
|
552
|
+
// }
|
|
553
|
+
// } );
|
|
554
|
+
// }
|
|
555
|
+
let userAnswer = data.userAnswer;
|
|
556
|
+
|
|
557
|
+
question[sectionIndex].questions[findQuestion] = data;
|
|
558
|
+
question[sectionIndex].questions[findQuestion].userAnswer = [];
|
|
559
|
+
question[sectionIndex].questions[findQuestion].remarks = '';
|
|
560
|
+
checklistDetails.questionAnswers = question;
|
|
561
|
+
let updateData = {
|
|
562
|
+
checklistStatus: 'open',
|
|
563
|
+
redoStatus: true,
|
|
564
|
+
reinitiateStatus: true,
|
|
565
|
+
questionAnswers: question,
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
let response = await processedChecklist.updateOne( { _id: originalData.checklistId }, updateData );
|
|
569
|
+
console.log( response );
|
|
570
|
+
if ( response.modifiedCount || response.matchedCount ) {
|
|
571
|
+
let storeTimeZone = await storeService.findOne( { storeName: checklistDetails.storeName }, { 'storeProfile.timeZone': 1 } );
|
|
572
|
+
let currentDateTime;
|
|
573
|
+
if ( storeTimeZone?.storeProfile?.timeZone ) {
|
|
574
|
+
currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
|
|
575
|
+
} else {
|
|
576
|
+
currentDateTime = dayjs();
|
|
577
|
+
}
|
|
578
|
+
data = {
|
|
579
|
+
checklistId: checklistDetails.sourceCheckList_id,
|
|
580
|
+
checkListName: checklistDetails.checkListName,
|
|
581
|
+
checklistDescription: req.body.payload.checklistDescription,
|
|
582
|
+
sectionId: originalData.section_id,
|
|
583
|
+
sectionName: question[sectionIndex].sectionName,
|
|
584
|
+
questionName: question[sectionIndex].questions[findQuestion].qname,
|
|
585
|
+
action: 'redo',
|
|
586
|
+
store_id: checklistDetails?.store_id?checklistDetails?.store_id:'',
|
|
587
|
+
storeName: checklistDetails?.storeName?checklistDetails?.storeName:'',
|
|
588
|
+
client_id: checklistDetails.client_id,
|
|
589
|
+
processedChecklistId: checklistDetails._id,
|
|
590
|
+
type: checklistDetails.checkListType,
|
|
591
|
+
userAnswer: userAnswer,
|
|
592
|
+
initiatedBy: req.user.userName,
|
|
593
|
+
initiatedTime: dayjs.utc( currentDateTime.format( 'hh:mm:ss A, DD MMM YYYY' ), 'hh:mm:ss A, DD MMM YYYY' ).format(),
|
|
594
|
+
answerType: question[sectionIndex].questions[findQuestion].answerType,
|
|
595
|
+
submitedBy: checklistDetails.userName,
|
|
596
|
+
submitTime: checklistDetails.submitTime,
|
|
597
|
+
};
|
|
598
|
+
await checklistLogs.create( data );
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
req.body.payload._id=originalData.checklistId;
|
|
602
|
+
req.body.payload.section_id=originalData.section_id;
|
|
603
|
+
req.body.payload.uniqueNo=originalData.uniqueNo;
|
|
604
|
+
console.log( req.body );
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
const requestOptions = {
|
|
608
|
+
method: 'POST',
|
|
609
|
+
headers: {
|
|
610
|
+
'Content-Type': 'application/json',
|
|
611
|
+
},
|
|
612
|
+
body: JSON.stringify( req.body ),
|
|
613
|
+
};
|
|
614
|
+
let url = JSON.parse( process.env.LAMBDAURL );
|
|
615
|
+
let searchResponse = await fetch( url.redoChecklist, requestOptions );
|
|
616
|
+
console.log( searchResponse.ok );
|
|
617
|
+
let logData= {
|
|
618
|
+
'client_id': checklistDetails.client_id,
|
|
619
|
+
'createAt': new Date(),
|
|
620
|
+
'sourceCheckList_id': checklistDetails.sourceCheckList_id,
|
|
621
|
+
'checkListName': checklistDetails.checkListName,
|
|
622
|
+
'fromCheckListName': checklistDetails.checkListName,
|
|
623
|
+
'type': 'checklist',
|
|
624
|
+
'action': checklistDetails.redoStatus?'multiredo': 'redo',
|
|
625
|
+
'storeName': checklistDetails?.storeName?checklistDetails?.storeName:'',
|
|
626
|
+
'store_id': checklistDetails?.store_id?checklistDetails?.store_id:'',
|
|
627
|
+
'userName': checklistDetails.userName,
|
|
628
|
+
'userEmail': checklistDetails.userEmail,
|
|
629
|
+
'createdByEmail': req.user.email,
|
|
630
|
+
'createdBy': req.user.userName,
|
|
631
|
+
'coverage': checklistDetails.coverage,
|
|
632
|
+
'logDetails': {},
|
|
633
|
+
'userType': req.user.userType,
|
|
634
|
+
};
|
|
635
|
+
let urlopensearch = JSON.parse( process.env.OPENSEARCH );
|
|
636
|
+
console.log( 'logData', logData );
|
|
637
|
+
insertOpenSearchData( urlopensearch.traxActivityLog, logData );
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
return res.sendSuccess( 'Question redo successfully' );
|
|
641
|
+
} catch ( e ) {
|
|
642
|
+
logger.error( { function: 'redomultiChecklist', error: e } );
|
|
643
|
+
return res.sendError( e, 500 );
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
458
647
|
|
|
459
648
|
export async function getLogs( req, res ) {
|
|
460
649
|
try {
|