tango-app-api-audit 3.4.11-alpha.4 → 3.4.11-alpha.6

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.11-alpha.4",
3
+ "version": "3.4.11-alpha.6",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  "mongodb": "^6.7.0",
25
25
  "nodemon": "^3.1.3",
26
26
  "swagger-ui-express": "^5.0.1",
27
- "tango-api-schema": "^2.1.28",
27
+ "tango-api-schema": "^2.1.36",
28
28
  "tango-app-api-middleware": "^3.1.33",
29
29
  "winston": "^3.13.0",
30
30
  "winston-daily-rotate-file": "^5.0.0"
@@ -527,7 +527,6 @@ export async function getAuditFile( req, res ) {
527
527
  img_name: indexes[1],
528
528
  img_id: image[0],
529
529
  selected: false,
530
- demographic: '',
531
530
  dropped: false,
532
531
  count: 1,
533
532
  mappedid: [ mapimg ],
@@ -1167,14 +1166,14 @@ export async function saveDraft( req, res ) {
1167
1166
  };
1168
1167
 
1169
1168
  if ( getUserAuditData?.startTime ) {
1170
- // const isoDate = getUserAuditData.startTime;
1171
- // const currentTime = dayjs();
1172
- // const isoDateTime = dayjs( isoDate );
1173
- // const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
1169
+ const isoDate = getUserAuditData.startTime;
1170
+ const currentTime = dayjs();
1171
+ const isoDateTime = dayjs( isoDate );
1172
+ const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
1174
1173
 
1175
- userRecord.timeSpent = inputData.timeSpent;
1174
+ userRecord.timeSpent = timeDifferenceInMinutes;
1176
1175
 
1177
- storeRecord.timeSpent = inputData.timeSpent;
1176
+ storeRecord.timeSpent =timeDifferenceInMinutes;
1178
1177
  }
1179
1178
 
1180
1179
  if ( inputData.userCommands ) {
@@ -1191,7 +1190,7 @@ export async function saveDraft( req, res ) {
1191
1190
  clientName: inputData.queueName,
1192
1191
  beforeCount: inputData.totalCount,
1193
1192
  afterCount: inputData.customerCount,
1194
- timeSpent: inputData.timeSpent,
1193
+ timeSpent: timeDifferenceInMinutes,
1195
1194
  auditId: inputData.auditId,
1196
1195
  moduleType: inputData.moduleType,
1197
1196
  zoneName: inputData.zoneName,
@@ -1322,10 +1321,10 @@ export async function save( req, res ) {
1322
1321
  // // moduleType: inputData.moduleType,
1323
1322
  // // zoneName: inputData.zoneName,
1324
1323
  // } );
1325
- // const isoDate = req.userAudit?.startTime;
1326
- // const currentTime = dayjs();
1327
- // const isoDateTime = dayjs( isoDate );
1328
- // const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
1324
+ const isoDate = req.userAudit?.startTime;
1325
+ const currentTime = dayjs();
1326
+ const isoDateTime = dayjs( isoDate );
1327
+ const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
1329
1328
 
1330
1329
  await updateOneUserAudit(
1331
1330
  { _id: new mongoose.Types.ObjectId( inputData.auditId ) },
@@ -1334,7 +1333,7 @@ export async function save( req, res ) {
1334
1333
  endTime: Date.now(),
1335
1334
  isDraft: false,
1336
1335
  afterCount: inputData.customerCount,
1337
- timeSpent: inputData.timeSpent,
1336
+ timeSpent: timeDifferenceInMinutes,
1338
1337
  },
1339
1338
  );
1340
1339
 
@@ -1355,7 +1354,7 @@ export async function save( req, res ) {
1355
1354
  afterCount: inputData.customerCount,
1356
1355
  startTime: req.userAudit?.startTime,
1357
1356
  endTime: Date.now(),
1358
- timeSpent: inputData.timeSpent,
1357
+ timeSpent: timeDifferenceInMinutes,
1359
1358
  auditId: new mongoose.Types.ObjectId( inputData.auditId ),
1360
1359
  },
1361
1360
  createdAt: Date.now(),
@@ -1422,7 +1421,7 @@ export async function save( req, res ) {
1422
1421
  status: 'not_assign',
1423
1422
  afterCount: inputData.customerCount,
1424
1423
  auditType: 'ReAudit',
1425
- timeSpent: inputData.timeSpent,
1424
+ timeSpent: timeDifferenceInMinutes,
1426
1425
  },
1427
1426
  );
1428
1427
 
@@ -1443,7 +1442,7 @@ export async function save( req, res ) {
1443
1442
  afterCount: inputData.customerCount,
1444
1443
  startTime: req.userAudit?.startTime,
1445
1444
  endTime: Date.now(),
1446
- timeSpent: inputData.timeSpent,
1445
+ timeSpent: timeDifferenceInMinutes,
1447
1446
  auditId: new mongoose.Types.ObjectId( inputData.auditId ),
1448
1447
  },
1449
1448
  createdAt: Date.now(),
@@ -1465,7 +1464,7 @@ export async function save( req, res ) {
1465
1464
  {
1466
1465
  status: 'completed',
1467
1466
  afterCount: inputData.customerCount,
1468
- timeSpent: inputData.timeSpent,
1467
+ timeSpent: timeDifferenceInMinutes,
1469
1468
  },
1470
1469
  );
1471
1470
  const sqsProduceQueue = {
@@ -746,7 +746,6 @@ export async function workSpace( req, res ) {
746
746
  },
747
747
  ];
748
748
 
749
- logger.info( { moduleType: inputData.moduleType, key: [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType ), dateStart: new Date( dayjs( fileDate ).format( 'YYYY-MM-DD' ) ), end: dateRange.end, user: req.user._id, client: clientList } );
750
749
 
751
750
  const userAsignAudit = [
752
751
  {
@@ -800,11 +799,11 @@ export async function workSpace( req, res ) {
800
799
  },
801
800
  ];
802
801
 
803
- const auditUserCount = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( auditFiles ) : await aggregateBinaryAudit( auditFiles );
804
- const userIncompleteFilesCount = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( userIncompleteFiles ) : await aggregateBinaryAudit( userIncompleteFiles );
802
+ const auditUserCount = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( auditFiles ) : await aggregateBinaryAudit( auditFiles );
803
+ const userIncompleteFilesCount = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( userIncompleteFiles ) : await aggregateBinaryAudit( userIncompleteFiles );
805
804
  logger.info( { moduleType: inputData.moduleType, userIncompleteFiles: userIncompleteFilesCount } );
806
805
  const userAsignAuditCount = await aggregateAssignAudit( userAsignAudit );
807
- const completedStoresCount = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( completedStores ) : await aggregateBinaryAudit( binarCompletedStores );
806
+ const completedStoresCount = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( completedStores ) : await aggregateBinaryAudit( binarCompletedStores );
808
807
  const clientAssignedCount = await aggregateAssignAudit( clientAssign );
809
808
  const auditStoreData = await aggregateTraxAuditData(
810
809
  auditStoreDataQuery,
@@ -981,13 +980,7 @@ export async function getAuditFile( req, res ) {
981
980
  query ={
982
981
  storeId: userDetails[0].storeId,
983
982
  fileDate: userDetails[0].fileDate,
984
- moduleType: userDetails[0].moduleType,
985
- };
986
- break;
987
- case 'mobile-detection':
988
- query ={
989
- storeId: userDetails[0].storeId,
990
- fileDate: userDetails[0].fileDate,
983
+ tempId: userDetails[0].tempId,
991
984
  moduleType: userDetails[0].moduleType,
992
985
  };
993
986
  break;
@@ -1049,46 +1042,42 @@ export async function getAuditFile( req, res ) {
1049
1042
  },
1050
1043
  ];
1051
1044
  break;
1052
- case 'unattended-customer':
1053
- for ( let i =0; i< msg.fileDetails.length; i++ ) {
1054
- const files = [];
1055
- const params ={
1045
+ case 'uniform-detection':
1046
+ const files = [];
1047
+
1048
+ const params ={
1049
+ Bucket: msg.inputBucketName,
1050
+ Key: msg?.filePath,
1051
+ };
1052
+
1053
+ const isExists = await checkFileExist( params );
1054
+
1055
+ if ( isExists ) {
1056
+ const signedParams ={
1056
1057
  Bucket: msg.inputBucketName,
1057
- file_path: msg?.fileDetails[i]?.folderPath,
1058
- MaxKeys: 1000,
1058
+ file_path: msg?.filePath,
1059
1059
  };
1060
- const list = await listFileByPath( params );
1061
- const folderPath = list.data;
1062
- logger.info( { folderPath: list, params: params, list: list } );
1063
- if ( folderPath?.length ) {
1064
- for ( let i = 0; i < folderPath.length; i++ ) {
1065
- // const img = folderPath[i].Key.split( '/' );
1066
- // const image = img[3].split( '.' );
1067
- // const indexes = image[0].split( '_' );
1068
- const signedParams ={
1069
- Bucket: msg.inputBucketName,
1070
- file_path: folderPath[i].Key,
1071
- };
1072
- const data = await signedUrl( signedParams );
1060
+ const data = await signedUrl( signedParams );
1073
1061
 
1074
- files.push(
1075
- data,
1076
- );
1077
- }
1078
- } else {
1079
- logger.error( {
1080
- error: { folderPath: folderPath },
1081
- function: `getAuditFile - ${inputData.moduleType}`,
1082
- message: 'Bucket image data not availale',
1083
- } );
1084
- return res.sendError( 'Bucket is Empty', 204 );
1085
- }
1086
- result.push( {
1087
- type: msg.fileDetails[i].type,
1088
- file: files,
1089
- } );
1062
+ files.push(
1063
+ data,
1064
+ );
1090
1065
  }
1066
+ // else {
1067
+ // logger.error( {
1068
+ // error: { folderPath: folderPath },
1069
+ // function: `getAuditFile - ${inputData.moduleType}`,
1070
+ // message: 'Bucket image data not availale',
1071
+ // } );
1072
+ // return res.sendError( 'Bucket is Empty', 204 );
1073
+ // }
1074
+ result.push( {
1075
+ type: 'image',
1076
+ file: files,
1077
+ } );
1078
+
1091
1079
  break;
1080
+ case 'unattended-customer':
1092
1081
  case 'left-in-middle':
1093
1082
  for ( let i =0; i< msg.fileDetails.length; i++ ) {
1094
1083
  const files = [];
@@ -1404,6 +1393,7 @@ export async function getUpdatedFile( req, res ) {
1404
1393
  export async function saveBinary( req, res ) {
1405
1394
  try {
1406
1395
  const openSearch = JSON.parse( process.env.OPENSEARCH );
1396
+ const sqs = JSON.parse( process.env.SQS );
1407
1397
  const inputData = req.body;
1408
1398
  const isoDate = req.userAudit?.startTime;
1409
1399
  const currentTime = dayjs();
@@ -1457,11 +1447,93 @@ export async function saveBinary( req, res ) {
1457
1447
  createdAt: Date.now(),
1458
1448
  };
1459
1449
  await insertOpenSearchData( openSearch.auditLog, logData2 );
1460
- logger.info( 'update in binary data', { query: unattendedquery, update: update } );
1461
1450
  return res.sendSuccess( `Successfully updated in ${value}` );
1462
1451
 
1463
1452
  break;
1464
1453
 
1454
+ case 'uniform-detection':
1455
+ let uniformDetectionQuery ={
1456
+ _id: inputData.auditId,
1457
+ storeId: inputData.storeId,
1458
+ fileDate: inputData.fileDate,
1459
+ tempId: inputData.tempId,
1460
+ moduleType: inputData.moduleType,
1461
+ };
1462
+
1463
+ let updateUniform={
1464
+ auditStatus: 'completed',
1465
+ answer: inputData.answer,
1466
+ userComments: inputData.userComments || '',
1467
+ endTime: new Date(),
1468
+ timeSpent: timeDifferenceInMinutes,
1469
+ };
1470
+ let updatDataUniform= await updateOneBinaryAuditModel( uniformDetectionQuery, updateUniform );
1471
+ if ( updatDataUniform.modifiedCount==0 ) {
1472
+ return res.sendError( 'Update failed, it may be invalid request', 400 );
1473
+ }
1474
+ const getFilePath = await findOneTraxAuditData(
1475
+ {
1476
+ fileDate: inputData.fileDate,
1477
+ storeId: inputData.storeId,
1478
+ moduleType: inputData.moduleType,
1479
+ tempId: inputData.tempId,
1480
+ },
1481
+ );
1482
+ if ( !getFilePath ) {
1483
+ return res.sendError( ' SQS is not sent due to Inserted Data is not there', 400 );
1484
+ }
1485
+ const sqsProduceQueue = {
1486
+ QueueUrl: `${sqs.url}${sqs.uniformOutput}`,
1487
+ MessageBody: JSON.stringify( {
1488
+ storeId: inputData.storeId,
1489
+ fileDate: inputData.fileDate,
1490
+ tempId: inputData.tempId,
1491
+ moduleType: inputData.moduleType,
1492
+ answer: inputData.answer,
1493
+ filePath: getFilePath?.sqs?.Body?.filePath,
1494
+ } ),
1495
+ };
1496
+ const sqsQueue = await sendMessageToQueue(
1497
+ sqsProduceQueue.QueueUrl,
1498
+ sqsProduceQueue.MessageBody,
1499
+ );
1500
+
1501
+ if ( sqsQueue.statusCode ) {
1502
+ logger.error( {
1503
+ error: `${sqsQueue}`,
1504
+ type: 'UPLOAD_ERROR',
1505
+ } );
1506
+ return res.sendError( 'SQS not sent', 500 );
1507
+ }
1508
+ const logData3 = {
1509
+ userId: req.user._id,
1510
+ userName: req.user.userName,
1511
+ logType: 'traxAudit',
1512
+ logSubType: 'auditDone',
1513
+ logData: {
1514
+ fileDate: req.userAudit?.fileDate,
1515
+ auditType: req.userAudit?.auditType,
1516
+ storeId: req.userAudit?.storeId,
1517
+ moduleType: req.userAudit?.moduleType,
1518
+ queueName: req.userAudit?.queueName,
1519
+ clientId: req.userAudit?.clientId,
1520
+ // beforeCount: req.userAudit?.beforeCount,
1521
+ // afterCount: inputData.employeeCount,
1522
+ startTime: req.userAudit?.startTime,
1523
+ streamName: req.userAudit?.streamName,
1524
+ tempId: req.userAudit?.tempId,
1525
+ question: req.userAudit?.question,
1526
+ result: req.userAudit?.answer,
1527
+ endTime: Date.now(),
1528
+ timeSpent: timeDifferenceInMinutes,
1529
+ auditId: new mongoose.Types.ObjectId( inputData.auditId ),
1530
+ },
1531
+ createdAt: Date.now(),
1532
+ };
1533
+ await insertOpenSearchData( openSearch.auditLog, logData3 );
1534
+ return res.sendSuccess( `Successfully updated in ${value}` );
1535
+ break;
1536
+
1465
1537
  case 'left-in-middle':
1466
1538
  let leftquery ={
1467
1539
  _id: inputData.auditId,
@@ -1507,7 +1579,6 @@ export async function saveBinary( req, res ) {
1507
1579
  createdAt: Date.now(),
1508
1580
  };
1509
1581
  await insertOpenSearchData( openSearch.auditLog, logData1 );
1510
- logger.info( 'update in binary data', { query: leftquery, update: leftupdate } );
1511
1582
  return res.sendSuccess( `Successfully updated in ${value}` );
1512
1583
 
1513
1584
  break;
@@ -1558,7 +1629,6 @@ export async function saveBinary( req, res ) {
1558
1629
  createdAt: Date.now(),
1559
1630
  };
1560
1631
  await insertOpenSearchData( openSearch.auditLog, logData );
1561
- logger.info( 'update in binary data', { query: cameraquery, update: cameraupdate } );
1562
1632
  return res.sendSuccess( `Successfully updated in ${value}` );
1563
1633
 
1564
1634
  break;
@@ -1781,7 +1851,7 @@ export async function userAuditHistory( req, res ) {
1781
1851
  },
1782
1852
  );
1783
1853
  }
1784
- const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
1854
+ const count = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
1785
1855
  if ( count.length == 0 ) {
1786
1856
  return res.sendError( 'No Data Found', 204 );
1787
1857
  }
@@ -1826,9 +1896,10 @@ export async function userAuditHistory( req, res ) {
1826
1896
  temp['User Comments'] = element.userComments;
1827
1897
  break;
1828
1898
  case 'uniform-detection':
1829
- temp['Before Count'] = element.beforeCount;
1830
- temp['After Count'] = element.afterCount;
1831
- temp['Accuracy'] = element.accuracy || '';
1899
+ temp['Customer ID'] = element.tempId;
1900
+ temp['Question'] = element.question;
1901
+ temp['Result'] = element.answer;
1902
+ temp['User Comments'] = element.userComments;
1832
1903
  break;
1833
1904
  case 'mobile-detection':
1834
1905
  temp['Before Count'] = element.beforeCount;
@@ -1853,7 +1924,7 @@ export async function userAuditHistory( req, res ) {
1853
1924
  {
1854
1925
  $limit: limit,
1855
1926
  } );
1856
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
1927
+ const result = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
1857
1928
 
1858
1929
  return res.sendSuccess( { result: result, count: count.length } );
1859
1930
  } catch ( error ) {
@@ -2178,7 +2249,7 @@ export async function clientMetrics( req, res ) {
2178
2249
  );
2179
2250
  }
2180
2251
 
2181
- const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
2252
+ const count = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
2182
2253
  logger.info( { count: count } );
2183
2254
  if ( count.length == 0 ) {
2184
2255
  return res.sendError( 'No Data Found', 204 );
@@ -2245,7 +2316,7 @@ export async function clientMetrics( req, res ) {
2245
2316
  );
2246
2317
  }
2247
2318
 
2248
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
2319
+ const result = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
2249
2320
  if ( result.length == 0 ) {
2250
2321
  return res.sendError( 'No Data Found', 204 );
2251
2322
  }
@@ -2280,7 +2351,7 @@ export async function storeMetrics( req, res ) {
2280
2351
  }
2281
2352
 
2282
2353
  if ( inputData.filterByStatus && inputData.filterByStatus?.length > 0 ) {
2283
- [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? filter.push( { status: { $in: inputData.filterByStatus } } ) : filter.push( { auditStatus: { $in: inputData.filterByStatus } } );
2354
+ [ 'mobile-detection' ].includes( inputData.moduleType )? filter.push( { status: { $in: inputData.filterByStatus } } ) : filter.push( { auditStatus: { $in: inputData.filterByStatus } } );
2284
2355
  }
2285
2356
 
2286
2357
  if ( inputData.filterByAuditType && inputData.filterByAuditType?.length > 0 ) {
@@ -2713,8 +2784,7 @@ export async function storeMetrics( req, res ) {
2713
2784
  },
2714
2785
  );
2715
2786
  }
2716
- logger.info( { keyss: [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType ) } );
2717
- const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
2787
+ const count = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
2718
2788
 
2719
2789
 
2720
2790
  if ( count.length == 0 ) {
@@ -2738,7 +2808,7 @@ export async function storeMetrics( req, res ) {
2738
2808
  $limit: limit,
2739
2809
  } );
2740
2810
  }
2741
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
2811
+ const result = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
2742
2812
  if ( inputData.isExport ) {
2743
2813
  const exportdata = [];
2744
2814
  result.forEach( ( element ) => {
@@ -2779,10 +2849,11 @@ export async function storeMetrics( req, res ) {
2779
2849
  temp['Accuracy'] = element.accuracy;
2780
2850
  break;
2781
2851
  case 'uniform-detection':
2782
- temp['Before Count'] = element.beforeCount;
2783
- temp['After Count'] = element.afterCount;
2784
- temp['Status'] = toCamelCase( element.status );
2785
- temp['Accuracy'] = element.accuracy;
2852
+ temp['Customer ID'] = element.tempId;
2853
+ temp['Question'] = element.question;
2854
+ temp['User Comments'] = element.userComments;
2855
+ temp['Status'] = toCamelCase( element.auditStatus );
2856
+ temp['Result'] = element.answer;
2786
2857
  break;
2787
2858
  }
2788
2859
  exportdata.push( temp );
@@ -3056,7 +3127,7 @@ export async function userMetrics( req, res ) {
3056
3127
  );
3057
3128
  }
3058
3129
 
3059
- const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3130
+ const count = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3060
3131
  if ( count.length == 0 ) {
3061
3132
  return res.sendError( 'No Data Found', 204 );
3062
3133
  }
@@ -3092,7 +3163,7 @@ export async function userMetrics( req, res ) {
3092
3163
  'Audited Date': { $dateToString: { format: '%Y-%m-%d', date: '$createdAt' } },
3093
3164
  // 'Mapping Percentage': '$mappingPerc',
3094
3165
  };
3095
- [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?
3166
+ [ 'mobile-detection' ].includes( inputData.moduleType )?
3096
3167
  query.push(
3097
3168
  {
3098
3169
  $project: detection,
@@ -3106,7 +3177,7 @@ export async function userMetrics( req, res ) {
3106
3177
  }
3107
3178
 
3108
3179
 
3109
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3180
+ const result = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3110
3181
  if ( inputData.isExport ) {
3111
3182
  await download( result, res );
3112
3183
  return;
@@ -3250,7 +3321,7 @@ export async function pendingSummaryTable( req, res ) {
3250
3321
  },
3251
3322
  );
3252
3323
  }
3253
- const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3324
+ const count = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3254
3325
  if ( count.length == 0 ) {
3255
3326
  return res.sendError( 'No Data Found', 204 );
3256
3327
  }
@@ -3266,7 +3337,7 @@ export async function pendingSummaryTable( req, res ) {
3266
3337
  } );
3267
3338
  }
3268
3339
 
3269
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3340
+ const result = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3270
3341
  if ( inputData.isExport ) {
3271
3342
  const exportdata = [];
3272
3343
  result.forEach( ( element ) => {
@@ -3295,7 +3366,8 @@ export async function pendingSummaryTable( req, res ) {
3295
3366
  temp['Before Count'] = element.beforeCount;
3296
3367
  break;
3297
3368
  case 'uniform-detection':
3298
- temp['Before Count'] = element.beforeCount;
3369
+ temp['Customer ID'] = element.tempId;
3370
+ temp['Question'] = element.question;
3299
3371
  break;
3300
3372
  }
3301
3373
  exportdata.push( temp );
@@ -3460,7 +3532,7 @@ export async function overAllAuditSummary( req, res ) {
3460
3532
  },
3461
3533
  ];
3462
3534
 
3463
- const storeAudit = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( binaryAuditQuery );
3535
+ const storeAudit = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( binaryAuditQuery );
3464
3536
  if ( storeAudit.length > 0 ) {
3465
3537
  temp.inprogressStores= storeAudit[0].inprogressStores;
3466
3538
  temp.completedStores = storeAudit[0].completedStores;
@@ -3648,7 +3720,7 @@ export async function summarySplit( req, res ) {
3648
3720
  },
3649
3721
  },
3650
3722
  ];
3651
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryAuditQuery );
3723
+ const result = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryAuditQuery );
3652
3724
  const totalCount = await aggregateTraxAuditData( totalQuery );
3653
3725
  result[0].totalCount = totalCount[0]?.total;
3654
3726
  return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
@@ -3678,7 +3750,7 @@ export async function overviewTable( req, res ) {
3678
3750
  }
3679
3751
 
3680
3752
  if ( inputData.filterByStatus.length > 0 ) {
3681
- [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? filters.push( { status: { $in: inputData.filterByStatus } } ):filters.push( { auditStatus: { $in: inputData.filterByStatus } } );
3753
+ [ 'mobile-detection' ].includes( inputData.moduleType )? filters.push( { status: { $in: inputData.filterByStatus } } ):filters.push( { auditStatus: { $in: inputData.filterByStatus } } );
3682
3754
  }
3683
3755
 
3684
3756
  const query =[
@@ -3795,7 +3867,7 @@ export async function overviewTable( req, res ) {
3795
3867
  },
3796
3868
  );
3797
3869
  }
3798
- const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
3870
+ const count = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
3799
3871
  if ( count.length == 0 ) {
3800
3872
  return res.sendError( 'No Data Found', 204 );
3801
3873
  }
@@ -3810,7 +3882,7 @@ export async function overviewTable( req, res ) {
3810
3882
  $limit: limit,
3811
3883
  } );
3812
3884
  }
3813
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
3885
+ const result = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
3814
3886
  if ( inputData.isExport ) {
3815
3887
  const exportdata = [];
3816
3888
  result.forEach( ( element ) => {
@@ -3847,10 +3919,11 @@ export async function overviewTable( req, res ) {
3847
3919
  temp['Status'] = toCamelCase( element.status );
3848
3920
  break;
3849
3921
  case 'uniform-detection':
3850
- temp['Before Count'] = element.beforeCount;
3851
- temp['After Count'] = element.afterCount;
3922
+ temp['Customer ID'] = element.tempId;
3923
+ temp['Question'] = element.question;
3924
+ temp['User Comments'] = element.userComments;
3852
3925
  temp['Audit Type'] = element.auditType;
3853
- temp['Status'] = toCamelCase( element.status );
3926
+ temp['Status'] = toCamelCase( element.auditStatus );
3854
3927
  break;
3855
3928
  }
3856
3929
  exportdata.push( temp );
@@ -4423,6 +4496,7 @@ export async function getDraftedData( req, res ) {
4423
4496
  export async function save( req, res ) {
4424
4497
  try {
4425
4498
  const openSearch = JSON.parse( process.env.OPENSEARCH );
4499
+ const sqs = JSON.parse( process.env.SQS );
4426
4500
  const inputData = req.body;
4427
4501
  const isoDate = req.userAudit?.startTime;
4428
4502
  const currentTime = dayjs();
@@ -4447,6 +4521,47 @@ export async function save( req, res ) {
4447
4521
  };
4448
4522
  await updateOneUserEmpDetection( { _id: inputData.auditId }, userUpdated );
4449
4523
  await updateOneStoreEmpDetection( query, storeUpdated );
4524
+
4525
+ const getFilePath = await findOneTraxAuditData(
4526
+ {
4527
+ fileDate: inputData.fileDate,
4528
+ storeId: inputData.storeId,
4529
+ moduleType: inputData.moduleType,
4530
+ },
4531
+ );
4532
+ if ( !getFilePath ) {
4533
+ return res.sendError( ' SQS is not sent due to Inserted Data is not there', 400 );
4534
+ }
4535
+ const tempId=[];
4536
+ if ( inputData.employeeCount > 0 ) {
4537
+ for ( let i =0; i<employee.length; i++ ) {
4538
+ tempId.push( employee[i].img_id );
4539
+ }
4540
+ }
4541
+ const sqsProduceQueue = {
4542
+ QueueUrl: `${sqs.url}${sqs.uniformOutput}`,
4543
+ MessageBody: JSON.stringify( {
4544
+ storeId: inputData.storeId,
4545
+ fileDate: inputData.fileDate,
4546
+ moduleType: inputData.moduleType,
4547
+ tempId: tempId,
4548
+ count: inputData.employeeCount,
4549
+ folderPath: getFilePath?.sqs?.Body?.folderPath,
4550
+ } ),
4551
+ };
4552
+ const sqsQueue = await sendMessageToQueue(
4553
+ sqsProduceQueue.QueueUrl,
4554
+ sqsProduceQueue.MessageBody,
4555
+ );
4556
+
4557
+ if ( sqsQueue.statusCode ) {
4558
+ logger.error( {
4559
+ error: `${sqsQueue}`,
4560
+ type: 'UPLOAD_ERROR',
4561
+ } );
4562
+ return res.sendError( 'SQS not sent', 500 );
4563
+ }
4564
+
4450
4565
  const logData = {
4451
4566
  userId: req.user._id,
4452
4567
  userName: req.user.userName,
@@ -52,7 +52,6 @@ export const saveDraftSchema = joi.object( {
52
52
  auditId: joi.string().required(),
53
53
  moduleType: joi.string().required(),
54
54
  zoneName: joi.string().required(),
55
- timeSpent: joi.number().required(),
56
55
  auditType: joi.string().required(),
57
56
  fileDate: joi.string().required(),
58
57
  queueName: joi.string().required(),
@@ -89,7 +88,6 @@ export const saveSchema = joi.object( {
89
88
  storeId: joi.string().required(),
90
89
  fileDate: joi.string().required(),
91
90
  auditType: joi.string().required(),
92
- timeSpent: joi.number().required(),
93
91
  moduleType: joi.string().required(),
94
92
  zoneName: joi.string().required(),
95
93
  beforeCount: joi.number().required(),
@@ -154,7 +154,6 @@ const mapFunction = async ( chunkData, filterData ) => {
154
154
  if ( mappedId.img_name === item.temp_ids ) {
155
155
  item.temp_ids = data.img_name;
156
156
  item.query_status = '';
157
- item.demographic = data.demographic || '';
158
157
  }
159
158
  } );
160
159
  }