tango-app-api-audit 3.4.59 → 3.4.61

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-audit",
3
- "version": "3.4.59",
3
+ "version": "3.4.61",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "mongodb": "^6.7.0",
27
27
  "nodemon": "^3.1.3",
28
28
  "swagger-ui-express": "^5.0.1",
29
- "tango-api-schema": "^2.2.93",
30
- "tango-app-api-middleware": "^3.1.48",
29
+ "tango-api-schema": "^2.2.95",
30
+ "tango-app-api-middleware": "^3.1.71",
31
31
  "winston": "^3.13.0",
32
32
  "winston-daily-rotate-file": "^5.0.0"
33
33
  },
@@ -4845,6 +4845,9 @@ export async function auditViewLogs( req, res ) {
4845
4845
  break;
4846
4846
  case 'uniform-detection':
4847
4847
  case 'mobile-detection':
4848
+ case 'cleaning':
4849
+ case 'open-time':
4850
+ case 'close-time':
4848
4851
  logsQuery = {
4849
4852
  'size': 100,
4850
4853
  'query': {
@@ -4956,41 +4959,41 @@ export async function auditViewLogs( req, res ) {
4956
4959
  ],
4957
4960
  };
4958
4961
  break;
4959
- case 'scrum':
4962
+
4960
4963
  case 'cleaning':
4961
- logsQuery = {
4962
- 'size': 100,
4963
- 'query': {
4964
- 'bool': {
4965
- 'must': [
4966
- {
4967
- 'term': {
4968
- 'logData.fileDate.keyword': inputData.fileDate,
4969
- },
4970
- },
4971
- {
4972
- 'term': {
4973
- 'logData.storeId.keyword': inputData.storeId,
4974
- },
4975
- },
4976
- {
4977
- 'term': {
4978
- 'logData.moduleType.keyword': inputData.moduleType,
4979
- },
4980
- },
4981
- {
4982
- 'terms': {
4983
- 'logSubType.keyword': [ 'auditDone', 'reTrigger' ],
4984
- },
4985
- },
4986
- ],
4987
- },
4988
- },
4989
- 'sort': [
4990
- { createdAt: { order: 'desc' } },
4991
- ],
4992
- };
4993
- break;
4964
+ // logsQuery = {
4965
+ // 'size': 100,
4966
+ // 'query': {
4967
+ // 'bool': {
4968
+ // 'must': [
4969
+ // {
4970
+ // 'term': {
4971
+ // 'logData.fileDate.keyword': inputData.fileDate,
4972
+ // },
4973
+ // },
4974
+ // {
4975
+ // 'term': {
4976
+ // 'logData.storeId.keyword': inputData.storeId,
4977
+ // },
4978
+ // },
4979
+ // {
4980
+ // 'term': {
4981
+ // 'logData.moduleType.keyword': inputData.moduleType,
4982
+ // },
4983
+ // },
4984
+ // {
4985
+ // 'terms': {
4986
+ // 'logSubType.keyword': [ 'auditDone', 'reTrigger' ],
4987
+ // },
4988
+ // },
4989
+ // ],
4990
+ // },
4991
+ // },
4992
+ // 'sort': [
4993
+ // { createdAt: { order: 'desc' } },
4994
+ // ],
4995
+ // };
4996
+ // break;
4994
4997
  default:
4995
4998
  return res.sendError( 'Please give valid modueType', 400 );
4996
4999
  }
@@ -1,4 +1,4 @@
1
- import { checkFileExist, chunkArray, download, getDate, getDateWithCustomizeTime, getJsonFileData, getObject, getOpenSearchData, getUTC, insertOpenSearchData, listFileByPath, logger, signedUrl, sqsReceive, updateOpenSearchData } from 'tango-app-api-middleware';
1
+ import { checkFileExist, chunkArray, download, getDate, getDateWithCustomizeTime, getJsonFileData, getObject, getOpenSearchData, getUTC, insertOpenSearchData, listFileByPath, logger, signedUrl, sqsReceive, updateOpenSearchData, sendMessageToQueue, listQueue, copyImage } from 'tango-app-api-middleware';
2
2
  import { aggregateBinaryAudit, findOneBinaryAudit, updateOneBinaryAuditModel, updateOneUpsertBinaryAudit } from '../service/binaryAudit.service.js';
3
3
  import { countDocumentsStore, findOneStore } from '../service/store.service.js';
4
4
  import { findOneUser } from '../service/user.service.js';
@@ -8,7 +8,6 @@ import { aggregateClient, findOneClient } from '../service/client.service.js';
8
8
  import dayjs from 'dayjs';
9
9
  import { aggregateAssignAudit } from '../service/assignAudit.service.js';
10
10
  import { aggregateStoreEmpDetection, updateManyStoreEmpDetection, updateOneStoreEmpDetection } from '../service/storeEmpDetection.service.js';
11
- import { listQueue, sendMessageToQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
12
11
  import _ from 'lodash';
13
12
  import mongoose from 'mongoose';
14
13
  import { findOneAuditLog, createAuditLog,
@@ -19,7 +18,6 @@ import {
19
18
  import { updateOneEmpDetectionOutput } from '../service/empDetectionOutput.service.js';
20
19
  import axios from 'axios';
21
20
  import FormData from 'form-data';
22
-
23
21
  export async function workSpace( req, res ) {
24
22
  try {
25
23
  const inputData = req.body;
@@ -547,6 +545,7 @@ export async function getAuditFile( req, res ) {
547
545
  };
548
546
  break;
549
547
  case 'camera-angle-change':
548
+ case 'anomaly-audit':
550
549
  query ={
551
550
  storeId: userDetails[0].storeId,
552
551
  fileDate: userDetails[0].fileDate,
@@ -714,6 +713,19 @@ export async function getAuditFile( req, res ) {
714
713
  file: eyeTestfiles,
715
714
  } );
716
715
  break;
716
+ case 'anomaly-audit':
717
+ for ( let i =0; i< msg.fileDetails.length; i++ ) {
718
+ const files = [];
719
+ const data = msg.fileDetails[i].folderPath;
720
+ files.push(
721
+ data,
722
+ );
723
+ result.push( {
724
+ type: msg.fileDetails[i].type,
725
+ file: files,
726
+ } );
727
+ }
728
+ break;
717
729
  default:
718
730
  return res.sendError( 'Please given valid moduleType', 400 );
719
731
  }
@@ -753,7 +765,7 @@ export async function getAuditFile( req, res ) {
753
765
  questionType: msg.questionType,
754
766
  streamName: msg.streamName,
755
767
  };
756
- record.streamName = inputData.moduleType == 'camera-angle-change' || inputData.moduleType == 'eye-test-camera' || inputData.moduleType == 'scrum'? msg.streamName : '';
768
+ record.streamName =[ 'camera-angle-change', 'eye-test-camera', 'anomaly-audit', 'scrum' ].includes( inputData.moduleType )? msg.streamName : '';
757
769
  record.videoDetails = inputData.moduleType == 'left-in-middle'? {
758
770
  'startHour': msg.startHour,
759
771
  'inspectHour': msg.inspectHour,
@@ -783,6 +795,7 @@ export async function getAuditFile( req, res ) {
783
795
  break;
784
796
  case 'camera-angle-change':
785
797
  case 'eye-test-camera':
798
+ case 'anomaly-audit':
786
799
  getQuery ={
787
800
  storeId: msg.storeId,
788
801
  fileDate: msg.fileDate,
@@ -1009,6 +1022,19 @@ export async function getUpdatedFile( req, res ) {
1009
1022
  file: eyeTestfiles,
1010
1023
  } );
1011
1024
  break;
1025
+ case 'anomaly-audit':
1026
+ for ( let i =0; i< msg.fileDetails.length; i++ ) {
1027
+ const files = [];
1028
+ const data = msg.fileDetails[i].folderPath;
1029
+ files.push(
1030
+ data,
1031
+ );
1032
+ result.push( {
1033
+ type: msg.fileDetails[i].type,
1034
+ file: files,
1035
+ } );
1036
+ }
1037
+ break;
1012
1038
  default:
1013
1039
  return res.sendError( 'Please given valid moduleType', 400 );
1014
1040
  }
@@ -1239,7 +1265,7 @@ export async function saveBinary( req, res ) {
1239
1265
  _id: inputData.auditId,
1240
1266
  storeId: inputData.storeId,
1241
1267
  fileDate: inputData.fileDate,
1242
- tempId: inputData.tempId,
1268
+ streamName: req.userAudit?.streamName,
1243
1269
  moduleType: inputData.moduleType,
1244
1270
  };
1245
1271
 
@@ -1294,12 +1320,6 @@ export async function saveBinary( req, res ) {
1294
1320
  streamName: req.userAudit?.streamName,
1295
1321
  },
1296
1322
  );
1297
- logger.info( { getScrumFilePath: getScrumFilePath, data: {
1298
- fileDate: inputData.fileDate,
1299
- storeId: inputData.storeId,
1300
- moduleType: inputData.moduleType,
1301
- streamName: req.userAudit?.streamName,
1302
- }, mesage: '.............1' } );
1303
1323
  const scrumOutput = {
1304
1324
  clientId: req.userAudit?.clientId,
1305
1325
  clientName: getClient1?.clientName,
@@ -1622,6 +1642,120 @@ export async function saveBinary( req, res ) {
1622
1642
  return res.sendSuccess( `Successfully updated in ${value}` );
1623
1643
  }
1624
1644
 
1645
+ case 'anomaly-audit':
1646
+ let anomalyQury ={
1647
+ _id: inputData.auditId,
1648
+ storeId: inputData.storeId,
1649
+ fileDate: inputData.fileDate,
1650
+ streamName: req.userAudit?.streamName,
1651
+ moduleType: inputData.moduleType,
1652
+ };
1653
+
1654
+ let anomalyRecord={
1655
+ auditStatus: 'completed',
1656
+ answer: inputData.answer,
1657
+ userComments: inputData.userComments || '',
1658
+ endTime: new Date(),
1659
+ timeSpent: timeDifferenceInMinutes,
1660
+ };
1661
+ let updatedAnomaly= await updateOneBinaryAuditModel( anomalyQury, anomalyRecord );
1662
+ if ( updatedAnomaly==0 ) {
1663
+ return res.sendError( 'Update failed, it may be invalid request', 400 );
1664
+ }
1665
+ let anomalyFilter= [
1666
+ {
1667
+ 'term': {
1668
+ 'storeId.keyword': inputData.storeId,
1669
+ },
1670
+ },
1671
+ {
1672
+ 'term': {
1673
+ 'fileDate.keyword': inputData.fileDate,
1674
+ },
1675
+ },
1676
+ {
1677
+ 'term': {
1678
+ 'moduleType.keyword': inputData.moduleType,
1679
+ },
1680
+ },
1681
+ {
1682
+ 'term': {
1683
+ 'streamName.keyword': inputData.streamName,
1684
+ },
1685
+ },
1686
+ ];
1687
+ let anomalySearchQuery={
1688
+ 'size': 1,
1689
+ 'query': {
1690
+ 'bool': {
1691
+ 'must': anomalyFilter,
1692
+ },
1693
+ },
1694
+ };
1695
+ const [ getStore2, getClient2 ] = await Promise.all( [ findOneStore( { storeId: inputData.storeId }, { storeName: 1, storeProfile: 1, spocDetails: 1 } ), findOneClient( { clientId: req.userAudit?.clientId }, { clientName: 1 } ) ] );
1696
+ const getData = await findOneTraxAuditData(
1697
+ {
1698
+ fileDate: inputData.fileDate,
1699
+ storeId: inputData.storeId,
1700
+ moduleType: inputData.moduleType,
1701
+ streamName: req.userAudit?.streamName,
1702
+ },
1703
+ );
1704
+ const anomalyOutput = {
1705
+ clientId: req.userAudit?.clientId,
1706
+ clientName: getClient2?.clientName,
1707
+ storeId: inputData.storeId,
1708
+ storeName: getStore2?.storeName,
1709
+ question: getData?.sqs?.Body?.question,
1710
+ spocName: getStore2?.spocDetails? getStore2?.spocDetails[0]?.name : '',
1711
+ spocEmail: getStore2?.spocDetails? getStore2?.spocDetails[0]?.email:'',
1712
+ spocContact: getStore2?.spocDetails? getStore2?.spocDetails[0].contact:'',
1713
+ address: getStore2?.storeProfile?.address,
1714
+ fileDate: inputData.fileDate,
1715
+ moduleType: inputData.moduleType,
1716
+ Answer: inputData.answer,
1717
+ configTime: getData?.sqs?.Body?.configTime,
1718
+ inputBucketName: getData?.sqs?.Body?.inputBucketName,
1719
+ incidentType: getData?.sqs?.Body?.incidentType,
1720
+ incidentId: getData?.sqs?.Body?.incidentId,
1721
+ incidentTime: getData?.sqs?.Body?.incidentTime,
1722
+ thumnailImage: getData?.sqs?.Body?.thumnailImage,
1723
+ folderPath: getData?.sqs?.Body?.fileDetails[0]?.outputFilePath,
1724
+ createdAt: new Date(),
1725
+ };
1726
+ const anomalySearchData= await getOpenSearchData( openSearch.traxDetectionOutput, anomalySearchQuery );
1727
+ logger.info( { length: anomalySearchData?.body?.hits?.hits?.length, _id: anomalySearchData?.body?.hits?.hits[0]?._id, output: anomalyOutput } );
1728
+ if ( anomalySearchData?.body?.hits?.hits?.length >0 ) {
1729
+ await updateOpenSearchData( openSearch.traxDetectionOutput, anomalySearchData?.body?.hits?.hits[0]?._id, { doc: anomalyOutput } );
1730
+ } else {
1731
+ await insertOpenSearchData( openSearch.traxDetectionOutput, anomalyOutput );
1732
+ }
1733
+
1734
+ const logData4 = {
1735
+ userId: req.user._id,
1736
+ userName: req.user.userName,
1737
+ logType: 'traxAudit',
1738
+ logSubType: 'auditDone',
1739
+ logData: {
1740
+ fileDate: req.userAudit?.fileDate,
1741
+ auditType: req.userAudit?.auditType,
1742
+ storeId: req.userAudit?.storeId,
1743
+ moduleType: req.userAudit?.moduleType,
1744
+ queueName: req.userAudit?.queueName,
1745
+ clientId: req.userAudit?.clientId,
1746
+ startTime: req.userAudit?.startTime,
1747
+ streamName: req.userAudit?.streamName,
1748
+ tempId: req.userAudit?.tempId,
1749
+ question: req.userAudit?.question,
1750
+ result: req.userAudit?.answer,
1751
+ endTime: Date.now(),
1752
+ timeSpent: timeDifferenceInMinutes,
1753
+ auditId: new mongoose.Types.ObjectId( inputData.auditId ),
1754
+ },
1755
+ createdAt: Date.now(),
1756
+ };
1757
+ await insertOpenSearchData( openSearch.auditLog, logData4 );
1758
+ return res.sendSuccess( `Successfully updated in ${value}` );
1625
1759
 
1626
1760
  default:
1627
1761
  res.sendError( 'No Data', 204 );
@@ -1738,6 +1872,7 @@ export async function userAuditHistory( req, res ) {
1738
1872
  },
1739
1873
  ];
1740
1874
  break;
1875
+ case 'anomaly-audit':
1741
1876
  case 'camera-angle-change':
1742
1877
  traxAuditDataQuery= {
1743
1878
  fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType', streamName: '$streamName',
@@ -1925,9 +2060,6 @@ export async function userAuditHistory( req, res ) {
1925
2060
  timezone: 'Asia/Kolkata',
1926
2061
  },
1927
2062
  },
1928
- // timeSpent: { $round: [
1929
- // { $divide: [ '$timeSpent', 60 ] }, 2,
1930
- // ] },
1931
2063
  timeSpent: {
1932
2064
 
1933
2065
  $cond: [
@@ -2018,6 +2150,7 @@ export async function userAuditHistory( req, res ) {
2018
2150
 
2019
2151
  };
2020
2152
  switch ( inputData.moduleType ) {
2153
+ case 'anomaly-audit':
2021
2154
  case 'camera-angle-change':
2022
2155
  temp['stream Name'] = element.streamName;
2023
2156
  temp['Result'] = element.answer;
@@ -2450,6 +2583,126 @@ export async function storeMetrics( req, res ) {
2450
2583
  if ( inputData.filterByAuditType && inputData.filterByAuditType?.length > 0 ) {
2451
2584
  filter.push( { auditType: { $in: inputData.filterByAuditType } } );
2452
2585
  }
2586
+ let traxAuditDataQuery ={};
2587
+ let traxAuditDataFilter = [];
2588
+ switch ( inputData.moduleType ) {
2589
+ case 'unattended-customer':
2590
+ traxAuditDataQuery= {
2591
+ fileDate: '$fileDate', storeId: '$storeId', tempId: '$tempId', moduleType: '$moduleType',
2592
+ };
2593
+ traxAuditDataFilter=[ {
2594
+ $eq: [ '$fileDate', '$$fileDate' ],
2595
+ },
2596
+ {
2597
+ $eq: [ '$storeId', '$$storeId' ],
2598
+ },
2599
+ {
2600
+ $eq: [ '$tempId', '$$tempId' ],
2601
+ },
2602
+ {
2603
+ $eq: [ '$moduleType', '$$moduleType' ],
2604
+ },
2605
+ ];
2606
+ break;
2607
+ case 'left-in-middle':
2608
+ traxAuditDataQuery= {
2609
+ fileDate: '$fileDate', storeId: '$storeId', tempId: '$tempId', moduleType: '$moduleType',
2610
+ };
2611
+ traxAuditDataFilter=[ {
2612
+ $eq: [ '$fileDate', '$$fileDate' ],
2613
+ },
2614
+ {
2615
+ $eq: [ '$storeId', '$$storeId' ],
2616
+ },
2617
+ {
2618
+ $eq: [ '$question', '$$question' ],
2619
+ },
2620
+ {
2621
+ $eq: [ '$moduleType', '$$moduleType' ],
2622
+ },
2623
+ ];
2624
+ break;
2625
+ case 'uniform-detection':
2626
+ case 'mobile-detection':
2627
+ case 'scrum':
2628
+ case 'cleaning':
2629
+ case 'open-time':
2630
+ case 'close-time':
2631
+ traxAuditDataQuery= {
2632
+ fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType',
2633
+ };
2634
+ traxAuditDataFilter=[ {
2635
+ $eq: [ '$fileDate', '$$fileDate' ],
2636
+ },
2637
+ {
2638
+ $eq: [ '$storeId', '$$storeId' ],
2639
+ },
2640
+ {
2641
+ $eq: [ '$moduleType', '$$moduleType' ],
2642
+ },
2643
+ ];
2644
+ break;
2645
+ case 'anomaly-audit':
2646
+ case 'camera-angle-change':
2647
+ traxAuditDataQuery= {
2648
+ fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType', streamName: '$streamName',
2649
+ };
2650
+ traxAuditDataFilter=[ {
2651
+ $eq: [ '$fileDate', '$$fileDate' ],
2652
+ },
2653
+ {
2654
+ $eq: [ '$storeId', '$$storeId' ],
2655
+ },
2656
+ {
2657
+ $eq: [ '$streamName', '$$streamName' ],
2658
+ },
2659
+ {
2660
+ $eq: [ '$moduleType', '$$moduleType' ],
2661
+ },
2662
+ ];
2663
+ break;
2664
+ case 'hygiene':
2665
+ traxAuditDataQuery= {
2666
+ fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType', zoneName: '$zoneName',
2667
+ };
2668
+ traxAuditDataFilter=[ {
2669
+ $eq: [ '$fileDate', '$$fileDate' ],
2670
+ },
2671
+ {
2672
+ $eq: [ '$storeId', '$$storeId' ],
2673
+ },
2674
+ {
2675
+ $eq: [ '$zoneName', '$$zoneName' ],
2676
+ },
2677
+ {
2678
+ $eq: [ '$moduleType', '$$moduleType' ],
2679
+ },
2680
+ ];
2681
+ break;
2682
+ case 'eye-test-camera':
2683
+ traxAuditDataQuery= {
2684
+ fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType', question: '$question', streamName: '$streamName',
2685
+ };
2686
+ traxAuditDataFilter=[ {
2687
+ $eq: [ '$fileDate', '$$fileDate' ],
2688
+ },
2689
+ {
2690
+ $eq: [ '$storeId', '$$storeId' ],
2691
+ },
2692
+ {
2693
+ $eq: [ '$question', '$$question' ],
2694
+ },
2695
+ {
2696
+ $eq: [ '$streamName', '$$streamName' ],
2697
+ },
2698
+ {
2699
+ $eq: [ '$moduleType', '$$moduleType' ],
2700
+ },
2701
+ ];
2702
+ break;
2703
+ default:
2704
+ return res.sendError( 'Please give valid modueType', 400 );
2705
+ }
2453
2706
 
2454
2707
 
2455
2708
  const query = [
@@ -2489,24 +2742,12 @@ export async function storeMetrics( req, res ) {
2489
2742
  {
2490
2743
  $lookup: {
2491
2744
  from: 'traxAuditData',
2492
- let: {
2493
- fileDate: '$fileDate', storeId: '$storeId', zoneName: '$zoneName',
2494
- },
2745
+ let: traxAuditDataQuery,
2495
2746
  pipeline: [
2496
2747
  {
2497
2748
  $match: {
2498
2749
  $expr: {
2499
- $and: [
2500
- {
2501
- $eq: [ '$fileDate', '$$fileDate' ],
2502
- },
2503
- {
2504
- $eq: [ '$storeId', '$$storeId' ],
2505
- },
2506
- {
2507
- $eq: [ '$zoneName', '$$zoneName' ],
2508
- },
2509
- ],
2750
+ $and: traxAuditDataFilter,
2510
2751
  },
2511
2752
  },
2512
2753
  },
@@ -2958,6 +3199,7 @@ export async function storeMetrics( req, res ) {
2958
3199
  };
2959
3200
  switch ( inputData.moduleType ) {
2960
3201
  case 'camera-angle-change':
3202
+ case 'anomaly-audit':
2961
3203
  temp['stream Name'] = element.streamName;
2962
3204
  temp['User Comments'] = element.userComments;
2963
3205
  temp['Status'] = toCamelCase( element.auditStatus );
@@ -3354,7 +3596,127 @@ export async function pendingSummaryTable( req, res ) {
3354
3596
  if ( inputData.filterByStatus.length > 0 ) {
3355
3597
  filters.push( { auditStatus: { $in: inputData.filterByStatus } } );
3356
3598
  }
3357
- const query =[
3599
+
3600
+ let traxAuditDataQuery={};
3601
+ let traxAuditDataFilter = [];
3602
+ switch ( inputData.moduleType ) {
3603
+ case 'unattended-customer':
3604
+ traxAuditDataQuery= {
3605
+ fileDate: '$fileDate', storeId: '$storeId', tempId: '$tempId', moduleType: '$moduleType',
3606
+ };
3607
+ traxAuditDataFilter=[ {
3608
+ $eq: [ '$fileDate', '$$fileDate' ],
3609
+ },
3610
+ {
3611
+ $eq: [ '$storeId', '$$storeId' ],
3612
+ },
3613
+ {
3614
+ $eq: [ '$tempId', '$$tempId' ],
3615
+ },
3616
+ {
3617
+ $eq: [ '$moduleType', '$$moduleType' ],
3618
+ },
3619
+ ];
3620
+ break;
3621
+ case 'left-in-middle':
3622
+ traxAuditDataQuery= {
3623
+ fileDate: '$fileDate', storeId: '$storeId', tempId: '$tempId', moduleType: '$moduleType',
3624
+ };
3625
+ traxAuditDataFilter=[ {
3626
+ $eq: [ '$fileDate', '$$fileDate' ],
3627
+ },
3628
+ {
3629
+ $eq: [ '$storeId', '$$storeId' ],
3630
+ },
3631
+ {
3632
+ $eq: [ '$question', '$$question' ],
3633
+ },
3634
+ {
3635
+ $eq: [ '$moduleType', '$$moduleType' ],
3636
+ },
3637
+ ];
3638
+ break;
3639
+ case 'uniform-detection':
3640
+ case 'mobile-detection':
3641
+ case 'scrum':
3642
+ case 'cleaning':
3643
+ case 'open-time':
3644
+ case 'close-time':
3645
+ traxAuditDataQuery= {
3646
+ fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType',
3647
+ };
3648
+ traxAuditDataFilter=[ {
3649
+ $eq: [ '$fileDate', '$$fileDate' ],
3650
+ },
3651
+ {
3652
+ $eq: [ '$storeId', '$$storeId' ],
3653
+ },
3654
+ {
3655
+ $eq: [ '$moduleType', '$$moduleType' ],
3656
+ },
3657
+ ];
3658
+ break;
3659
+ case 'anomaly-audit':
3660
+ case 'camera-angle-change':
3661
+ traxAuditDataQuery= {
3662
+ fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType', streamName: '$streamName',
3663
+ };
3664
+ traxAuditDataFilter=[ {
3665
+ $eq: [ '$fileDate', '$$fileDate' ],
3666
+ },
3667
+ {
3668
+ $eq: [ '$storeId', '$$storeId' ],
3669
+ },
3670
+ {
3671
+ $eq: [ '$streamName', '$$streamName' ],
3672
+ },
3673
+ {
3674
+ $eq: [ '$moduleType', '$$moduleType' ],
3675
+ },
3676
+ ];
3677
+ break;
3678
+ case 'hygiene':
3679
+ traxAuditDataQuery= {
3680
+ fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType', zoneName: '$zoneName',
3681
+ };
3682
+ traxAuditDataFilter=[ {
3683
+ $eq: [ '$fileDate', '$$fileDate' ],
3684
+ },
3685
+ {
3686
+ $eq: [ '$storeId', '$$storeId' ],
3687
+ },
3688
+ {
3689
+ $eq: [ '$zoneName', '$$zoneName' ],
3690
+ },
3691
+ {
3692
+ $eq: [ '$moduleType', '$$moduleType' ],
3693
+ },
3694
+ ];
3695
+ break;
3696
+ case 'eye-test-camera':
3697
+ traxAuditDataQuery= {
3698
+ fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType', question: '$question', streamName: '$streamName',
3699
+ };
3700
+ traxAuditDataFilter=[ {
3701
+ $eq: [ '$fileDate', '$$fileDate' ],
3702
+ },
3703
+ {
3704
+ $eq: [ '$storeId', '$$storeId' ],
3705
+ },
3706
+ {
3707
+ $eq: [ '$question', '$$question' ],
3708
+ },
3709
+ {
3710
+ $eq: [ '$streamName', '$$streamName' ],
3711
+ },
3712
+ {
3713
+ $eq: [ '$moduleType', '$$moduleType' ],
3714
+ },
3715
+ ];
3716
+ break;
3717
+ default:
3718
+ return res.sendError( 'Please give valid modueType', 400 );
3719
+ } const query =[
3358
3720
  {
3359
3721
  $match: {
3360
3722
  $and: filters,
@@ -3364,24 +3726,12 @@ export async function pendingSummaryTable( req, res ) {
3364
3726
  {
3365
3727
  $lookup: {
3366
3728
  from: 'traxAuditData',
3367
- let: {
3368
- fileDate: '$fileDate', storeId: '$storeId', zoneName: '$zoneName',
3369
- },
3729
+ let: traxAuditDataQuery,
3370
3730
  pipeline: [
3371
3731
  {
3372
3732
  $match: {
3373
3733
  $expr: {
3374
- $and: [
3375
- {
3376
- $eq: [ '$fileDate', '$$fileDate' ],
3377
- },
3378
- {
3379
- $eq: [ '$storeId', '$$storeId' ],
3380
- },
3381
- {
3382
- $eq: [ '$zoneName', '$$zoneName' ],
3383
- },
3384
- ],
3734
+ $and: traxAuditDataFilter,
3385
3735
  },
3386
3736
  },
3387
3737
  },
@@ -3492,7 +3842,7 @@ export async function pendingSummaryTable( req, res ) {
3492
3842
  { userName: { $regex: inputData.searchValue, $options: 'i' } },
3493
3843
  { userEmail: { $regex: inputData.searchValue, $options: 'i' } },
3494
3844
  { value: { $regex: inputData.searchValue, $options: 'i' } },
3495
- { question: { $regex: inputData.searchData, $options: 'i' } },
3845
+ { question: { $regex: inputData.searchValue, $options: 'i' } },
3496
3846
  ],
3497
3847
 
3498
3848
  },
@@ -3537,6 +3887,7 @@ export async function pendingSummaryTable( req, res ) {
3537
3887
  'Status': toCamelCase( element.auditStatus ),
3538
3888
  };
3539
3889
  switch ( inputData.moduleType ) {
3890
+ case 'anomaly-audit':
3540
3891
  case 'camera-angle-change':
3541
3892
  temp['stream Name'] = element.streamName;
3542
3893
  break;
@@ -4006,6 +4357,7 @@ export async function overviewTable( req, res ) {
4006
4357
  },
4007
4358
  ];
4008
4359
  break;
4360
+ case 'anomaly-audit':
4009
4361
  case 'camera-angle-change':
4010
4362
  traxAuditDataQuery= {
4011
4363
  fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType', streamName: '$streamName',
@@ -4063,6 +4415,7 @@ export async function overviewTable( req, res ) {
4063
4415
  },
4064
4416
  ];
4065
4417
  break;
4418
+
4066
4419
  default:
4067
4420
  return res.sendError( 'Please give valid modueType', 400 );
4068
4421
  }
@@ -4203,6 +4556,7 @@ export async function overviewTable( req, res ) {
4203
4556
  };
4204
4557
 
4205
4558
  switch ( inputData.moduleType ) {
4559
+ case 'anomaly-audit':
4206
4560
  case 'camera-angle-change':
4207
4561
  temp['stream Name'] = element.streamName;
4208
4562
  temp['User Comments'] = element.userComments;
@@ -4544,12 +4898,12 @@ export async function getDetectionAuditFile( req, res ) {
4544
4898
  const mapimg = {
4545
4899
  img_path: data,
4546
4900
  img_name: time,
4547
- img_id: `${item?.file_path}_${time}`,
4901
+ img_id: `${item?.file_path}__${time}`,
4548
4902
  };
4549
4903
  files.push( {
4550
4904
  img_path: data,
4551
4905
  img_name: time,
4552
- img_id: `${item?.file_path}_${time}`,
4906
+ img_id: `${item?.file_path}__${time}`,
4553
4907
  selected: false,
4554
4908
  dropped: false,
4555
4909
  singleDetection: false,
@@ -4794,6 +5148,7 @@ export async function getDraftedData( req, res ) {
4794
5148
  export async function save( req, res ) {
4795
5149
  try {
4796
5150
  const openSearch = JSON.parse( process.env.OPENSEARCH );
5151
+ const bucket = JSON.parse( process.env.BUCKET );
4797
5152
  const sqs = JSON.parse( process.env.SQS );
4798
5153
  const inputData = req.body;
4799
5154
  const isoDate = req.userAudit?.startTime;
@@ -4823,12 +5178,7 @@ export async function save( req, res ) {
4823
5178
 
4824
5179
  logger.info( { userUpdate: userUpdate, storeUpdate: storeUpdate, function: 'saveUpdate' } );
4825
5180
  const getFilePath = await findOneTraxAuditData(
4826
- {
4827
- fileDate: inputData.fileDate,
4828
- storeId: inputData.storeId,
4829
- zoneName: inputData.zoneName,
4830
- moduleType: inputData.moduleType,
4831
- },
5181
+ query,
4832
5182
  );
4833
5183
  if ( !getFilePath ) {
4834
5184
  return res.sendError( 'SQS is not sent due to Inserted Data is not there', 400 );
@@ -4870,7 +5220,7 @@ export async function save( req, res ) {
4870
5220
  }
4871
5221
  }
4872
5222
 
4873
- const outputFilePath = tempId[0]?.split( '_' );
5223
+ const outputFilePath = tempId[0]?.split( '__' );
4874
5224
  // trax output in open serach
4875
5225
  const folderPath = getFilePath?.sqs?.Body?.folderPath;
4876
5226
  const output = {
@@ -4889,9 +5239,9 @@ export async function save( req, res ) {
4889
5239
  inputBucketName: getFilePath?.sqs?.Body?.inputBucketName,
4890
5240
  tempId: tempId,
4891
5241
  count: inputData.employeeCount,
4892
- time: [ 'open-time', 'close-time' ].includes( inputData?.moduleType )?outputFilePath[1]:'',
5242
+ time: [ 'open-time', 'close-time' ].includes( inputData?.moduleType )?outputFilePath?outputFilePath[1]:'':'',
4893
5243
  bufferTime: [ 'open-time', 'close-time' ].includes( inputData?.moduleType )? getFilePath?.sqs?.Body?.bufferTime : '',
4894
- folderPath: [ 'open-time', 'close-time' ].includes( inputData?.moduleType )? outputFilePath[0]: folderPath.split( '/' ).slice( 0, -1 ).join( '/' ) + '/',
5244
+ folderPath: [ 'open-time', 'close-time' ].includes( inputData?.moduleType )?outputFilePath? outputFilePath[0]:'': folderPath.split( '/' ).slice( 0, -1 ).join( '/' ) + '/',
4895
5245
  createdAt: new Date(),
4896
5246
  };
4897
5247
  let filter= [
@@ -4931,6 +5281,17 @@ export async function save( req, res ) {
4931
5281
  await insertOpenSearchData( openSearch.traxDetectionOutput, output );
4932
5282
  }
4933
5283
 
5284
+ if ( [ 'open-time', 'close-time' ].includes( inputData.moduleType ) && outputFilePath ) {
5285
+ const temp = inputData.moduleType.split( '-' );
5286
+ const copyParams = {
5287
+ Bucket: bucket.outputSnap,
5288
+ CopySource: `/${getFilePath?.sqs?.Body?.inputBucketName}/${outputFilePath[0]}`,
5289
+ Key: `${inputData.storeId}/${ inputData.fileDate}/operation_snaps/${temp[0]}.jpeg`,
5290
+ };
5291
+
5292
+ await copyImage( copyParams );
5293
+ }
5294
+
4934
5295
  const logData = {
4935
5296
  userId: req.user._id,
4936
5297
  userName: req.user.userName,
@@ -4954,6 +5315,7 @@ export async function save( req, res ) {
4954
5315
  },
4955
5316
  createdAt: Date.now(),
4956
5317
  };
5318
+
4957
5319
  await insertOpenSearchData( openSearch.auditLog, logData );
4958
5320
  return res.sendSuccess( { result: 'Updated Successfully' } );
4959
5321
  } else {
@@ -4995,8 +5357,8 @@ export async function reTrigger( req, res ) {
4995
5357
  default:
4996
5358
  return res.sendError( 'Please give valid module type' );
4997
5359
  }
4998
- if ( !getQueueName || queueName == '' ) {
4999
- return res.sendError( 'queueName does not create', 400 );
5360
+ if ( !getQueueName || [ null, '', undefined ].includes( queueName ) ) {
5361
+ return res.sendError( `The queueName ${queueName} does not create`, 400 );
5000
5362
  }
5001
5363
  let getQuery ={
5002
5364
  storeId: message.storeId,
@@ -90,6 +90,7 @@ export async function isTraxAuditDocumentExist( req, res, next ) {
90
90
  break;
91
91
  case 'camera-angle-change':
92
92
  case 'eye-test-camera':
93
+ case 'anomaly-audit':
93
94
  case 'scrum':
94
95
  query ={
95
96
  storeId: inputData.storeId,