tango-app-api-trax 3.3.1-hotfix-11 → 3.4.0-alpha-1

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.3.1-hotfix-11",
3
+ "version": "3.4.0-alpha-1",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -27,7 +27,7 @@
27
27
  "nodemon": "^3.1.4",
28
28
  "path": "^0.12.7",
29
29
  "tango-api-schema": "^2.2.70",
30
- "tango-app-api-middleware": "^3.1.65",
30
+ "tango-app-api-middleware": "^3.1.55",
31
31
  "url": "^0.11.4",
32
32
  "winston": "^3.13.1",
33
33
  "winston-daily-rotate-file": "^5.0.0"
@@ -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 ) {
@@ -1644,51 +1644,3 @@ async function getUserToken( clientId, userEmail ) {
1644
1644
  return false;
1645
1645
  }
1646
1646
  }
1647
-
1648
- export async function internalAISendPushNotification( req, res ) {
1649
- try {
1650
- let requestData = req.body;
1651
- if ( !requestData.clientId ) {
1652
- return res.sendError( 'clientId is Required', 400 );
1653
- }
1654
- if ( !( requestData?.email || requestData?.storeId ) ) {
1655
- return res.sendError( 'Email or StoreId is Required', 400 );
1656
- }
1657
-
1658
- if ( !requestData.title ) {
1659
- return res.sendError( 'Title is Required', 400 );
1660
- }
1661
-
1662
- if ( !requestData.description ) {
1663
- return res.sendError( 'Description is Required', 400 );
1664
- }
1665
-
1666
- let fcmToken;
1667
- if ( requestData.email && requestData.email !='' ) {
1668
- fcmToken = await getUserToken( requestData.clientId, requestData.email );
1669
- } else {
1670
- let storeData = await storeService.findOne( { clientId: requestData.clientId, storeId: requestData.storeId }, { spocDetails: 1 } );
1671
- if ( storeData && storeData.spocDetails.length > 0 && storeData.spocDetails[0].email ) {
1672
- fcmToken = await getUserToken( storeData.spocDetails[0].email );
1673
- }
1674
- }
1675
- if ( !fcmToken ) {
1676
- return res.sendSuccess( 'Notification Send Successfully' );
1677
- }
1678
- let custom = {
1679
- type: req.body?.type,
1680
- storeId: req.body?.storeId,
1681
- date: req.body?.date,
1682
- };
1683
- let responseData = await sendPushNotification( requestData.title, requestData.description, fcmToken, custom );
1684
- if ( responseData ) {
1685
- return res.sendSuccess( 'Notification Send Successfully' );
1686
- } else {
1687
- return res.sendSuccess( 'Notification Send Successfully' );
1688
- }
1689
- } catch ( e ) {
1690
- logger.error( { error: e, function: 'internalAISendPushNotification' } );
1691
- if ( e.name === 'ValidationError' ) res.sendBadRequest( e );
1692
- else res.sendError( e, 500 );
1693
- }
1694
- };
@@ -2462,7 +2462,7 @@ export async function checklistv1( req, res ) {
2462
2462
  ...projectExtraConditions,
2463
2463
  client_id: { $ifNull: [ '$client_id', '' ] },
2464
2464
  coverage: { $ifNull: [ '$coverage', '' ] },
2465
- taskType: { $ifNull: [ '$planoType', '' ] },
2465
+ taskType: { $ifNull: [ '$type', '' ] },
2466
2466
  },
2467
2467
  },
2468
2468
  ];
@@ -3426,19 +3426,11 @@ export async function updatePlanoStatus( req, res ) {
3426
3426
  if ( !processCheckDetails ) {
3427
3427
  return res.sendError( 'No data found', 204 );
3428
3428
  }
3429
- let storeTimeZone = await storeService.findOne( { storeName: { $regex: processCheckDetails.storeName, $options: 'i' }, clientId: processCheckDetails.client_id }, { 'storeProfile.timeZone': 1 } );
3430
- let currentDateTime;
3431
- if ( storeTimeZone?.storeProfile?.timeZone ) {
3432
- currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
3433
- } else {
3434
- currentDateTime = requestData?.currentTime ? dayjs( requestData.currentTime, 'HH:mm:ss' ) : dayjs();
3435
- }
3436
- let submitTimeString = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
3437
- await processedchecklist.updateOne( { _id: req.body.id }, { checklistStatus: req.body.status, ...( req.body.status == 'inprogress' ) ? { startTime_string: submitTimeString } : { submitTime_string: submitTimeString } } );
3429
+ processCheckDetails.checklistStatus = req.body.status;
3430
+ processCheckDetails.save();
3438
3431
  return res.sendSuccess( 'Status updated Successfully' );
3439
3432
  } catch ( e ) {
3440
3433
  logger.error( { error: e, function: 'updatePlanoStatus' } );
3441
3434
  return res.sendError( e, 500 );
3442
3435
  }
3443
3436
  }
3444
-