tango-app-api-trax 3.4.0-flag-8 → 3.4.0-flag-10

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.0-flag-8",
3
+ "version": "3.4.0-flag-10",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -282,7 +282,7 @@ 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 } );
286
286
  if ( !checklistDetails.length ) {
287
287
  return res.sendError( 'No data found', 204 );
288
288
  }
@@ -317,6 +317,27 @@ export async function approveChecklist( req, res ) {
317
317
  let searchResponse = await fetch( url.approveChecklist, requestOptions );
318
318
 
319
319
  console.log( searchResponse.ok );
320
+
321
+ let logData= {
322
+ 'client_id': checklistDetails[0].client_id,
323
+ 'createAt': new Date(),
324
+ 'sourceCheckList_id': req.body.sourceCheckList_id,
325
+ 'checkListName': checklistDetails[0].checkListName,
326
+ 'fromCheckListName': checklistDetails[0].checkListName,
327
+ 'type': 'checklist',
328
+ 'action': 'approved',
329
+ 'storeName': '',
330
+ 'store_id': '',
331
+ 'createdByEmail': req.user.email,
332
+ 'createdBy': req.user._id,
333
+ 'coverage': checklistDetails[0].coverage,
334
+ 'logDetails': {
335
+ 'approved': [ 'LKST011', 'LKST022', 'LKST3444', 'LKST455', 'LKST566', 'LKST666', 'LKST766', 'LKST866', 'LkST966' ],
336
+ },
337
+ };
338
+ let urlopensearch = JSON.parse( process.env.OPENSEARCH );
339
+ console.log( 'logData', logData );
340
+ await insertOpenSearchData( urlopensearch.traxActivityLog, logData );
320
341
  if ( searchResponse.ok ) {
321
342
  let pendingstores = checklistDetails.filter( ( data ) => data.checklistStatus != 'submit' );
322
343
  if ( pendingstores && pendingstores.length > 0 ) {
@@ -350,7 +371,7 @@ export async function redoChecklist( req, res ) {
350
371
  }
351
372
 
352
373
 
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 } );
374
+ 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
375
  if ( !checklistDetails ) {
355
376
  return res.sendError( 'No data found', 204 );
356
377
  }
@@ -429,7 +450,7 @@ export async function redoChecklist( req, res ) {
429
450
  submitTime: checklistDetails.submitTime,
430
451
  };
431
452
  await checklistLogs.create( data );
432
-
453
+ console.log( req.body );
433
454
  const requestOptions = {
434
455
  method: 'POST',
435
456
  headers: {
@@ -440,7 +461,26 @@ export async function redoChecklist( req, res ) {
440
461
  let url = JSON.parse( process.env.LAMBDAURL );
441
462
  let searchResponse = await fetch( url.redoChecklist, requestOptions );
442
463
  console.log( searchResponse.ok );
443
-
464
+ let logData= {
465
+ 'client_id': checklistDetails.client_id,
466
+ 'createAt': new Date(),
467
+ 'sourceCheckList_id': checklistDetails.sourceCheckList_id,
468
+ 'checkListName': checklistDetails.checkListName,
469
+ 'fromCheckListName': checklistDetails.checkListName,
470
+ 'type': 'checklist',
471
+ 'action': 'redo',
472
+ 'storeName': checklistDetails?.storeName?checklistDetails?.storeName:'',
473
+ 'store_id': checklistDetails?.store_id?checklistDetails?.store_id:'',
474
+ 'userName': checklistDetails.userName,
475
+ 'userEmail': checklistDetails.userEmail,
476
+ 'createdByEmail': req.user.email,
477
+ 'createdBy': req.user.userName,
478
+ 'coverage': checklistDetails.coverage,
479
+ 'logDetails': {},
480
+ };
481
+ let urlopensearch = JSON.parse( process.env.OPENSEARCH );
482
+ console.log( 'logData', logData );
483
+ await insertOpenSearchData( urlopensearch.traxActivityLog, logData );
444
484
  if ( searchResponse.ok ) {
445
485
  return res.sendSuccess( 'Question redo successfully' );
446
486
  } else {
@@ -454,6 +494,148 @@ export async function redoChecklist( req, res ) {
454
494
  return res.sendError( e, 500 );
455
495
  }
456
496
  }
497
+ export async function redomultiChecklist( req, res ) {
498
+ try {
499
+ let inputData = req.body.payload.coverage==='user'?req.body.payload.userEmail:req.body.payload.storeName;
500
+
501
+
502
+ for ( let originalData of inputData ) {
503
+ if ( !originalData.checklistId ) {
504
+ return res.sendError( 'Id is Required', 400 );
505
+ }
506
+ if ( !originalData.section_id ) {
507
+ return res.sendError( 'Section id is Required', 400 );
508
+ }
509
+ if ( !req.body.payload.qno ) {
510
+ return res.sendError( 'Question number is Required', 400 );
511
+ }
512
+
513
+
514
+ 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 } );
515
+ if ( !checklistDetails ) {
516
+ return res.sendError( 'No data found', 204 );
517
+ }
518
+ let question = checklistDetails.questionAnswers;
519
+
520
+
521
+ let sectionIndex = question.findIndex( ( sec ) => sec.sectionName == req.body.payload.sectionName );
522
+ if ( sectionIndex == -1 ) {
523
+ return res.sendError( 'section is not found', 400 );
524
+ }
525
+
526
+ let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.qno == req.body.payload.qno );
527
+
528
+ let data = { ...question[sectionIndex].questions[findQuestion], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
529
+ // if ( checklistDetails.client_id == '458' ) {
530
+ data.answers.forEach( ( item ) => {
531
+ if ( item.showLinked ) {
532
+ item.nestedQuestion.forEach( ( ele ) => {
533
+ let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn.qno == parseInt( ele ) );
534
+ let element = { ...question[sectionIndex].questions[eleIndex], redo: true, redoComment: '', linkquestionenabled: false };
535
+ question[sectionIndex].questions[eleIndex] = element;
536
+ question[sectionIndex].questions[eleIndex].userAnswer = [];
537
+ question[sectionIndex].questions[eleIndex].remarks = '';
538
+ } );
539
+ }
540
+ } );
541
+ // data.answers.forEach( ( item ) => {
542
+ // if ( item.showLinked ) {
543
+ // item.nestedQuestion = [];
544
+ // item.showLinked = false;
545
+ // item.linkedQuestion = 0;
546
+ // }
547
+ // } );
548
+ // }
549
+ let userAnswer = data.userAnswer;
550
+
551
+ question[sectionIndex].questions[findQuestion] = data;
552
+ question[sectionIndex].questions[findQuestion].userAnswer = [];
553
+ question[sectionIndex].questions[findQuestion].remarks = '';
554
+ checklistDetails.questionAnswers = question;
555
+ let updateData = {
556
+ checklistStatus: 'open',
557
+ redoStatus: true,
558
+ reinitiateStatus: true,
559
+ questionAnswers: question,
560
+ };
561
+
562
+ let response = await processedChecklist.updateOne( { _id: originalData.checklistId }, updateData );
563
+ console.log( response );
564
+ if ( response.modifiedCount || response.matchedCount ) {
565
+ let storeTimeZone = await storeService.findOne( { storeName: checklistDetails.storeName }, { 'storeProfile.timeZone': 1 } );
566
+ let currentDateTime;
567
+ if ( storeTimeZone?.storeProfile?.timeZone ) {
568
+ currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
569
+ } else {
570
+ currentDateTime = dayjs();
571
+ }
572
+ data = {
573
+ checklistId: checklistDetails.sourceCheckList_id,
574
+ checkListName: checklistDetails.checkListName,
575
+ checklistDescription: req.body.payload.checklistDescription,
576
+ sectionId: originalData.section_id,
577
+ sectionName: question[sectionIndex].sectionName,
578
+ questionName: question[sectionIndex].questions[findQuestion].qname,
579
+ action: 'redo',
580
+ store_id: checklistDetails?.store_id?checklistDetails?.store_id:'',
581
+ storeName: checklistDetails?.storeName?checklistDetails?.storeName:'',
582
+ client_id: checklistDetails.client_id,
583
+ processedChecklistId: checklistDetails._id,
584
+ type: checklistDetails.checkListType,
585
+ userAnswer: userAnswer,
586
+ initiatedBy: req.user.userName,
587
+ initiatedTime: dayjs.utc( currentDateTime.format( 'hh:mm:ss A, DD MMM YYYY' ), 'hh:mm:ss A, DD MMM YYYY' ).format(),
588
+ answerType: question[sectionIndex].questions[findQuestion].answerType,
589
+ submitedBy: checklistDetails.userName,
590
+ submitTime: checklistDetails.submitTime,
591
+ };
592
+ await checklistLogs.create( data );
593
+
594
+
595
+ req.body.payload._id=originalData.checklistId;
596
+ req.body.payload.section_id=originalData.section_id;
597
+ req.body.payload.uniqueNo=originalData.uniqueNo;
598
+ console.log( req.body );
599
+
600
+
601
+ const requestOptions = {
602
+ method: 'POST',
603
+ headers: {
604
+ 'Content-Type': 'application/json',
605
+ },
606
+ body: JSON.stringify( req.body ),
607
+ };
608
+ let url = JSON.parse( process.env.LAMBDAURL );
609
+ let searchResponse = await fetch( url.redoChecklist, requestOptions );
610
+ console.log( searchResponse.ok );
611
+ let logData= {
612
+ 'client_id': checklistDetails.client_id,
613
+ 'createAt': new Date(),
614
+ 'sourceCheckList_id': checklistDetails.sourceCheckList_id,
615
+ 'checkListName': checklistDetails.checkListName,
616
+ 'fromCheckListName': checklistDetails.checkListName,
617
+ 'type': 'checklist',
618
+ 'action': 'redo',
619
+ 'storeName': checklistDetails?.storeName?checklistDetails?.storeName:'',
620
+ 'store_id': checklistDetails?.store_id?checklistDetails?.store_id:'',
621
+ 'userName': checklistDetails.userName,
622
+ 'userEmail': checklistDetails.userEmail,
623
+ 'createdByEmail': req.user.email,
624
+ 'createdBy': req.user.userName,
625
+ 'coverage': checklistDetails.coverage,
626
+ 'logDetails': {},
627
+ };
628
+ let urlopensearch = JSON.parse( process.env.OPENSEARCH );
629
+ console.log( 'logData', logData );
630
+ await insertOpenSearchData( urlopensearch.traxActivityLog, logData );
631
+ }
632
+ }
633
+ return res.sendSuccess( 'Question redo successfully' );
634
+ } catch ( e ) {
635
+ logger.error( { function: 'redomultiChecklist', error: e } );
636
+ return res.sendError( e, 500 );
637
+ }
638
+ }
457
639
 
458
640
 
459
641
  export async function getLogs( req, res ) {
@@ -875,7 +875,7 @@ export const update = async ( req, res ) => {
875
875
  } );
876
876
  let compare = findDifferences( qn, question );
877
877
  if ( Object.keys( compare ).length && ( compare?.answerType || compare?.answers || compare?.linkType ) ) {
878
- questionList.questionEdit.push( { sectionName: ele.section, questions: [ { previous: qn }, { new: question } ] } );
878
+ questionList.questionEdit.push( { sectionName: ele.section, questions: [ { previous: qn, new: question } ] } );
879
879
  }
880
880
  } else {
881
881
  let sectionIndex = questionList.questionDelete.findIndex( ( sec ) => sec.sectionName === ele.section );
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- import { getchecklist, viewchecklist, getMobileUseagelist, storeOpencloselist, getcustomerunattendedlist, storesList, checklistDropdown, redoChecklist, approveChecklist, approvalstatus, getLogs, headerStoresV2, teamsList, userList } from '../controllers/gallery.controller.js';
3
+ import { getchecklist, viewchecklist, getMobileUseagelist, storeOpencloselist, getcustomerunattendedlist, storesList, checklistDropdown, redoChecklist, redomultiChecklist, approveChecklist, approvalstatus, getLogs, headerStoresV2, teamsList, userList } from '../controllers/gallery.controller.js';
4
4
  import express from 'express';
5
5
  export const galleryRouter = express.Router();
6
6
  import { validate, isAllowedSessionHandler, isAllowedClient, getAssinedStore } from 'tango-app-api-middleware';
@@ -24,6 +24,7 @@ galleryRouter
24
24
  galleryRouter
25
25
  .post( '/updateApprove', isAllowedSessionHandler, approveChecklist )
26
26
  .post( '/redo', isAllowedSessionHandler, redoChecklist )
27
+ .post( '/multiredo', isAllowedSessionHandler, redomultiChecklist )
27
28
  .post( '/approvalstatus', isAllowedSessionHandler, approvalstatus )
28
29
  .post( '/getLogs', isAllowedSessionHandler, getLogs );
29
30
  galleryRouter