tango-app-api-audit 3.4.11-alpha.1 → 3.4.11-alpha.11

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.1",
3
+ "version": "3.4.11-alpha.11",
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.37",
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,8 +527,8 @@ export async function getAuditFile( req, res ) {
527
527
  img_name: indexes[1],
528
528
  img_id: image[0],
529
529
  selected: false,
530
- demographic: 'a',
531
530
  dropped: false,
531
+ demographic: '',
532
532
  count: 1,
533
533
  mappedid: [ mapimg ],
534
534
  } );
@@ -716,7 +716,7 @@ export async function getAuditImage( msg ) {
716
716
  img_name: indexes[1],
717
717
  img_id: image[0],
718
718
  selected: false,
719
- demographic: 'a',
719
+ // demographic: '',
720
720
  dropped: false,
721
721
  count: 1,
722
722
  mappedid: [ mapimg ],
@@ -1168,14 +1168,14 @@ export async function saveDraft( req, res ) {
1168
1168
  };
1169
1169
 
1170
1170
  if ( getUserAuditData?.startTime ) {
1171
- const isoDate = getUserAuditData.startTime;
1172
- const currentTime = dayjs();
1173
- const isoDateTime = dayjs( isoDate );
1174
- const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
1171
+ // const isoDate = getUserAuditData.startTime;
1172
+ // const currentTime = dayjs();
1173
+ // const isoDateTime = dayjs( isoDate );
1174
+ // const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
1175
1175
 
1176
- userRecord.timeSpent = timeDifferenceInMinutes;
1176
+ userRecord.timeSpent = inputData.timeSpent;
1177
1177
 
1178
- storeRecord.timeSpent = timeDifferenceInMinutes;
1178
+ storeRecord.timeSpent =inputData.timeSpent;
1179
1179
  }
1180
1180
 
1181
1181
  if ( inputData.userCommands ) {
@@ -1192,6 +1192,7 @@ export async function saveDraft( req, res ) {
1192
1192
  clientName: inputData.queueName,
1193
1193
  beforeCount: inputData.totalCount,
1194
1194
  afterCount: inputData.customerCount,
1195
+ timeSpent: inputData.timeSpent,
1195
1196
  auditId: inputData.auditId,
1196
1197
  moduleType: inputData.moduleType,
1197
1198
  zoneName: inputData.zoneName,
@@ -1322,10 +1323,10 @@ export async function save( req, res ) {
1322
1323
  // // moduleType: inputData.moduleType,
1323
1324
  // // zoneName: inputData.zoneName,
1324
1325
  // } );
1325
- const isoDate = req.userAudit?.startTime;
1326
- const currentTime = dayjs();
1327
- const isoDateTime = dayjs( isoDate );
1328
- const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
1326
+ // const isoDate = req.userAudit?.startTime;
1327
+ // const currentTime = dayjs();
1328
+ // const isoDateTime = dayjs( isoDate );
1329
+ // const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
1329
1330
 
1330
1331
  await updateOneUserAudit(
1331
1332
  { _id: new mongoose.Types.ObjectId( inputData.auditId ) },
@@ -1334,7 +1335,7 @@ export async function save( req, res ) {
1334
1335
  endTime: Date.now(),
1335
1336
  isDraft: false,
1336
1337
  afterCount: inputData.customerCount,
1337
- timeSpent: timeDifferenceInMinutes,
1338
+ timeSpent: inputData.timeSpent,
1338
1339
  },
1339
1340
  );
1340
1341
 
@@ -1355,7 +1356,7 @@ export async function save( req, res ) {
1355
1356
  afterCount: inputData.customerCount,
1356
1357
  startTime: req.userAudit?.startTime,
1357
1358
  endTime: Date.now(),
1358
- timeSpent: timeDifferenceInMinutes,
1359
+ timeSpent: inputData.timeSpent,
1359
1360
  auditId: new mongoose.Types.ObjectId( inputData.auditId ),
1360
1361
  },
1361
1362
  createdAt: Date.now(),
@@ -1422,7 +1423,7 @@ export async function save( req, res ) {
1422
1423
  status: 'not_assign',
1423
1424
  afterCount: inputData.customerCount,
1424
1425
  auditType: 'ReAudit',
1425
- timeSpent: timeDifferenceInMinutes,
1426
+ timeSpent: inputData.timeSpent,
1426
1427
  },
1427
1428
  );
1428
1429
 
@@ -1443,7 +1444,7 @@ export async function save( req, res ) {
1443
1444
  afterCount: inputData.customerCount,
1444
1445
  startTime: req.userAudit?.startTime,
1445
1446
  endTime: Date.now(),
1446
- timeSpent: timeDifferenceInMinutes,
1447
+ timeSpent: inputData.timeSpent,
1447
1448
  auditId: new mongoose.Types.ObjectId( inputData.auditId ),
1448
1449
  },
1449
1450
  createdAt: Date.now(),
@@ -1465,7 +1466,7 @@ export async function save( req, res ) {
1465
1466
  {
1466
1467
  status: 'completed',
1467
1468
  afterCount: inputData.customerCount,
1468
- timeSpent: timeDifferenceInMinutes,
1469
+ timeSpent: inputData.timeSpent,
1469
1470
  },
1470
1471
  );
1471
1472
  const sqsProduceQueue = {
@@ -4672,8 +4673,7 @@ export async function auditViewLogs( req, res ) {
4672
4673
  },
4673
4674
  };
4674
4675
  break;
4675
- case 'uniform-detection':
4676
- case 'mobile-detection': // Handle both in the same block
4676
+ case 'mobile-detection':
4677
4677
  logsQuery = {
4678
4678
  'size': 100,
4679
4679
  'query': {
@@ -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;
@@ -1005,7 +998,7 @@ export async function getAuditFile( req, res ) {
1005
998
  logger.info( { query: query } );
1006
999
  const traxInfo = await findOneTraxAuditData( query );
1007
1000
  if ( !traxInfo ) {
1008
- return res.sendError( 'The sorce record not found', 400 );
1001
+ return res.sendError( 'The source record not found', 400 );
1009
1002
  }
1010
1003
  msg =traxInfo?.sqs?.Body;
1011
1004
  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 = [];
@@ -1262,46 +1251,35 @@ export async function getUpdatedFile( req, res ) {
1262
1251
  },
1263
1252
  ];
1264
1253
  break;
1265
- case 'unattended-customer':
1266
- for ( let i =0; i< msg.fileDetails.length; i++ ) {
1267
- const files = [];
1268
- const params ={
1254
+
1255
+ case 'uniform-detection':
1256
+ const files = [];
1257
+
1258
+ const params ={
1259
+ Bucket: msg.inputBucketName,
1260
+ Key: msg?.filePath,
1261
+ };
1262
+
1263
+ const isExists = await checkFileExist( params );
1264
+
1265
+ if ( isExists ) {
1266
+ const signedParams ={
1269
1267
  Bucket: msg.inputBucketName,
1270
- file_path: msg?.fileDetails[i]?.folderPath,
1271
- MaxKeys: 1000,
1268
+ file_path: msg?.filePath,
1272
1269
  };
1273
- const list = await listFileByPath( params );
1274
- const folderPath = list.data;
1275
- logger.info( { folderPath: list, params: params, list: list } );
1276
- if ( folderPath?.length ) {
1277
- for ( let i = 0; i < folderPath.length; i++ ) {
1278
- // const img = folderPath[i].Key.split( '/' );
1279
- // const image = img[3].split( '.' );
1280
- // const indexes = image[0].split( '_' );
1281
- const signedParams ={
1282
- Bucket: msg.inputBucketName,
1283
- file_path: folderPath[i].Key,
1284
- };
1285
- const data = await signedUrl( signedParams );
1270
+ const data = await signedUrl( signedParams );
1286
1271
 
1287
- files.push(
1288
- data,
1289
- );
1290
- }
1291
- } else {
1292
- logger.error( {
1293
- error: { folderPath: folderPath },
1294
- function: `getAuditFile - ${inputData.moduleType}`,
1295
- message: 'Bucket image data not availale',
1296
- } );
1297
- return res.sendError( 'Bucket is Empty', 204 );
1298
- }
1299
- result.push( {
1300
- type: msg.fileDetails[i].type,
1301
- file: files,
1302
- } );
1272
+ files.push(
1273
+ data,
1274
+ );
1303
1275
  }
1276
+ result.push( {
1277
+ type: 'image',
1278
+ file: files,
1279
+ } );
1280
+
1304
1281
  break;
1282
+ case 'unattended-customer':
1305
1283
  case 'left-in-middle':
1306
1284
  for ( let i =0; i< msg.fileDetails.length; i++ ) {
1307
1285
  const files = [];
@@ -1404,6 +1382,7 @@ export async function getUpdatedFile( req, res ) {
1404
1382
  export async function saveBinary( req, res ) {
1405
1383
  try {
1406
1384
  const openSearch = JSON.parse( process.env.OPENSEARCH );
1385
+ const sqs = JSON.parse( process.env.SQS );
1407
1386
  const inputData = req.body;
1408
1387
  const isoDate = req.userAudit?.startTime;
1409
1388
  const currentTime = dayjs();
@@ -1457,11 +1436,94 @@ export async function saveBinary( req, res ) {
1457
1436
  createdAt: Date.now(),
1458
1437
  };
1459
1438
  await insertOpenSearchData( openSearch.auditLog, logData2 );
1460
- logger.info( 'update in binary data', { query: unattendedquery, update: update } );
1461
1439
  return res.sendSuccess( `Successfully updated in ${value}` );
1462
1440
 
1463
1441
  break;
1464
1442
 
1443
+ case 'uniform-detection':
1444
+ let uniformDetectionQuery ={
1445
+ _id: inputData.auditId,
1446
+ storeId: inputData.storeId,
1447
+ fileDate: inputData.fileDate,
1448
+ tempId: inputData.tempId,
1449
+ moduleType: inputData.moduleType,
1450
+ };
1451
+
1452
+ let updateUniform={
1453
+ auditStatus: 'completed',
1454
+ answer: inputData.answer,
1455
+ userComments: inputData.userComments || '',
1456
+ endTime: new Date(),
1457
+ timeSpent: timeDifferenceInMinutes,
1458
+ };
1459
+ let updatDataUniform= await updateOneBinaryAuditModel( uniformDetectionQuery, updateUniform );
1460
+ if ( updatDataUniform.modifiedCount==0 ) {
1461
+ return res.sendError( 'Update failed, it may be invalid request', 400 );
1462
+ }
1463
+ const getFilePath = await findOneTraxAuditData(
1464
+ {
1465
+ fileDate: inputData.fileDate,
1466
+ storeId: inputData.storeId,
1467
+ moduleType: inputData.moduleType,
1468
+ tempId: inputData.tempId,
1469
+ },
1470
+ );
1471
+ if ( !getFilePath ) {
1472
+ return res.sendError( ' SQS is not sent due to Inserted Data is not there', 400 );
1473
+ }
1474
+ const sqsProduceQueue = {
1475
+ QueueUrl: `${sqs.url}${sqs.uniformOutput}`,
1476
+ MessageBody: JSON.stringify( {
1477
+ storeId: inputData.storeId,
1478
+ fileDate: inputData.fileDate,
1479
+ tempId: inputData.tempId,
1480
+ moduleType: inputData.moduleType,
1481
+ answer: inputData.answer,
1482
+ inputBucketName: getFilePath?.sqs?.Body?.inputBucketName,
1483
+ filePath: getFilePath?.sqs?.Body?.filePath,
1484
+ } ),
1485
+ };
1486
+ const sqsQueue = await sendMessageToQueue(
1487
+ sqsProduceQueue.QueueUrl,
1488
+ sqsProduceQueue.MessageBody,
1489
+ );
1490
+
1491
+ if ( sqsQueue.statusCode ) {
1492
+ logger.error( {
1493
+ error: `${sqsQueue}`,
1494
+ type: 'UPLOAD_ERROR',
1495
+ } );
1496
+ return res.sendError( 'SQS not sent', 500 );
1497
+ }
1498
+ const logData3 = {
1499
+ userId: req.user._id,
1500
+ userName: req.user.userName,
1501
+ logType: 'traxAudit',
1502
+ logSubType: 'auditDone',
1503
+ logData: {
1504
+ fileDate: req.userAudit?.fileDate,
1505
+ auditType: req.userAudit?.auditType,
1506
+ storeId: req.userAudit?.storeId,
1507
+ moduleType: req.userAudit?.moduleType,
1508
+ queueName: req.userAudit?.queueName,
1509
+ clientId: req.userAudit?.clientId,
1510
+ // beforeCount: req.userAudit?.beforeCount,
1511
+ // afterCount: inputData.employeeCount,
1512
+ startTime: req.userAudit?.startTime,
1513
+ streamName: req.userAudit?.streamName,
1514
+ tempId: req.userAudit?.tempId,
1515
+ question: req.userAudit?.question,
1516
+ result: req.userAudit?.answer,
1517
+ endTime: Date.now(),
1518
+ timeSpent: timeDifferenceInMinutes,
1519
+ auditId: new mongoose.Types.ObjectId( inputData.auditId ),
1520
+ },
1521
+ createdAt: Date.now(),
1522
+ };
1523
+ await insertOpenSearchData( openSearch.auditLog, logData3 );
1524
+ return res.sendSuccess( `Successfully updated in ${value}` );
1525
+ break;
1526
+
1465
1527
  case 'left-in-middle':
1466
1528
  let leftquery ={
1467
1529
  _id: inputData.auditId,
@@ -1507,7 +1569,6 @@ export async function saveBinary( req, res ) {
1507
1569
  createdAt: Date.now(),
1508
1570
  };
1509
1571
  await insertOpenSearchData( openSearch.auditLog, logData1 );
1510
- logger.info( 'update in binary data', { query: leftquery, update: leftupdate } );
1511
1572
  return res.sendSuccess( `Successfully updated in ${value}` );
1512
1573
 
1513
1574
  break;
@@ -1558,7 +1619,6 @@ export async function saveBinary( req, res ) {
1558
1619
  createdAt: Date.now(),
1559
1620
  };
1560
1621
  await insertOpenSearchData( openSearch.auditLog, logData );
1561
- logger.info( 'update in binary data', { query: cameraquery, update: cameraupdate } );
1562
1622
  return res.sendSuccess( `Successfully updated in ${value}` );
1563
1623
 
1564
1624
  break;
@@ -1781,7 +1841,7 @@ export async function userAuditHistory( req, res ) {
1781
1841
  },
1782
1842
  );
1783
1843
  }
1784
- const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
1844
+ const count = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
1785
1845
  if ( count.length == 0 ) {
1786
1846
  return res.sendError( 'No Data Found', 204 );
1787
1847
  }
@@ -1826,9 +1886,10 @@ export async function userAuditHistory( req, res ) {
1826
1886
  temp['User Comments'] = element.userComments;
1827
1887
  break;
1828
1888
  case 'uniform-detection':
1829
- temp['Before Count'] = element.beforeCount;
1830
- temp['After Count'] = element.afterCount;
1831
- temp['Accuracy'] = element.accuracy || '';
1889
+ temp['Customer ID'] = element.tempId;
1890
+ temp['Question'] = element.question;
1891
+ temp['Result'] = element.answer;
1892
+ temp['User Comments'] = element.userComments;
1832
1893
  break;
1833
1894
  case 'mobile-detection':
1834
1895
  temp['Before Count'] = element.beforeCount;
@@ -1853,7 +1914,7 @@ export async function userAuditHistory( req, res ) {
1853
1914
  {
1854
1915
  $limit: limit,
1855
1916
  } );
1856
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
1917
+ const result = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
1857
1918
 
1858
1919
  return res.sendSuccess( { result: result, count: count.length } );
1859
1920
  } catch ( error ) {
@@ -2178,7 +2239,7 @@ export async function clientMetrics( req, res ) {
2178
2239
  );
2179
2240
  }
2180
2241
 
2181
- const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
2242
+ const count = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
2182
2243
  logger.info( { count: count } );
2183
2244
  if ( count.length == 0 ) {
2184
2245
  return res.sendError( 'No Data Found', 204 );
@@ -2245,7 +2306,7 @@ export async function clientMetrics( req, res ) {
2245
2306
  );
2246
2307
  }
2247
2308
 
2248
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
2309
+ const result = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
2249
2310
  if ( result.length == 0 ) {
2250
2311
  return res.sendError( 'No Data Found', 204 );
2251
2312
  }
@@ -2280,7 +2341,7 @@ export async function storeMetrics( req, res ) {
2280
2341
  }
2281
2342
 
2282
2343
  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 } } );
2344
+ [ 'mobile-detection' ].includes( inputData.moduleType )? filter.push( { status: { $in: inputData.filterByStatus } } ) : filter.push( { auditStatus: { $in: inputData.filterByStatus } } );
2284
2345
  }
2285
2346
 
2286
2347
  if ( inputData.filterByAuditType && inputData.filterByAuditType?.length > 0 ) {
@@ -2713,8 +2774,7 @@ export async function storeMetrics( req, res ) {
2713
2774
  },
2714
2775
  );
2715
2776
  }
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 );
2777
+ const count = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
2718
2778
 
2719
2779
 
2720
2780
  if ( count.length == 0 ) {
@@ -2738,7 +2798,7 @@ export async function storeMetrics( req, res ) {
2738
2798
  $limit: limit,
2739
2799
  } );
2740
2800
  }
2741
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
2801
+ const result = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
2742
2802
  if ( inputData.isExport ) {
2743
2803
  const exportdata = [];
2744
2804
  result.forEach( ( element ) => {
@@ -2779,10 +2839,11 @@ export async function storeMetrics( req, res ) {
2779
2839
  temp['Accuracy'] = element.accuracy;
2780
2840
  break;
2781
2841
  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;
2842
+ temp['Customer ID'] = element.tempId;
2843
+ temp['Question'] = element.question;
2844
+ temp['User Comments'] = element.userComments;
2845
+ temp['Status'] = toCamelCase( element.auditStatus );
2846
+ temp['Result'] = element.answer;
2786
2847
  break;
2787
2848
  }
2788
2849
  exportdata.push( temp );
@@ -3056,7 +3117,7 @@ export async function userMetrics( req, res ) {
3056
3117
  );
3057
3118
  }
3058
3119
 
3059
- const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3120
+ const count = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3060
3121
  if ( count.length == 0 ) {
3061
3122
  return res.sendError( 'No Data Found', 204 );
3062
3123
  }
@@ -3092,7 +3153,7 @@ export async function userMetrics( req, res ) {
3092
3153
  'Audited Date': { $dateToString: { format: '%Y-%m-%d', date: '$createdAt' } },
3093
3154
  // 'Mapping Percentage': '$mappingPerc',
3094
3155
  };
3095
- [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?
3156
+ [ 'mobile-detection' ].includes( inputData.moduleType )?
3096
3157
  query.push(
3097
3158
  {
3098
3159
  $project: detection,
@@ -3106,7 +3167,7 @@ export async function userMetrics( req, res ) {
3106
3167
  }
3107
3168
 
3108
3169
 
3109
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3170
+ const result = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3110
3171
  if ( inputData.isExport ) {
3111
3172
  await download( result, res );
3112
3173
  return;
@@ -3250,7 +3311,7 @@ export async function pendingSummaryTable( req, res ) {
3250
3311
  },
3251
3312
  );
3252
3313
  }
3253
- const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3314
+ const count = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3254
3315
  if ( count.length == 0 ) {
3255
3316
  return res.sendError( 'No Data Found', 204 );
3256
3317
  }
@@ -3266,7 +3327,7 @@ export async function pendingSummaryTable( req, res ) {
3266
3327
  } );
3267
3328
  }
3268
3329
 
3269
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3330
+ const result = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3270
3331
  if ( inputData.isExport ) {
3271
3332
  const exportdata = [];
3272
3333
  result.forEach( ( element ) => {
@@ -3295,7 +3356,8 @@ export async function pendingSummaryTable( req, res ) {
3295
3356
  temp['Before Count'] = element.beforeCount;
3296
3357
  break;
3297
3358
  case 'uniform-detection':
3298
- temp['Before Count'] = element.beforeCount;
3359
+ temp['Customer ID'] = element.tempId;
3360
+ temp['Question'] = element.question;
3299
3361
  break;
3300
3362
  }
3301
3363
  exportdata.push( temp );
@@ -3460,7 +3522,7 @@ export async function overAllAuditSummary( req, res ) {
3460
3522
  },
3461
3523
  ];
3462
3524
 
3463
- const storeAudit = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( binaryAuditQuery );
3525
+ const storeAudit = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( binaryAuditQuery );
3464
3526
  if ( storeAudit.length > 0 ) {
3465
3527
  temp.inprogressStores= storeAudit[0].inprogressStores;
3466
3528
  temp.completedStores = storeAudit[0].completedStores;
@@ -3648,7 +3710,7 @@ export async function summarySplit( req, res ) {
3648
3710
  },
3649
3711
  },
3650
3712
  ];
3651
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryAuditQuery );
3713
+ const result = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryAuditQuery );
3652
3714
  const totalCount = await aggregateTraxAuditData( totalQuery );
3653
3715
  result[0].totalCount = totalCount[0]?.total;
3654
3716
  return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
@@ -3678,7 +3740,7 @@ export async function overviewTable( req, res ) {
3678
3740
  }
3679
3741
 
3680
3742
  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 } } );
3743
+ [ 'mobile-detection' ].includes( inputData.moduleType )? filters.push( { status: { $in: inputData.filterByStatus } } ):filters.push( { auditStatus: { $in: inputData.filterByStatus } } );
3682
3744
  }
3683
3745
 
3684
3746
  const query =[
@@ -3795,7 +3857,7 @@ export async function overviewTable( req, res ) {
3795
3857
  },
3796
3858
  );
3797
3859
  }
3798
- const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
3860
+ const count = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
3799
3861
  if ( count.length == 0 ) {
3800
3862
  return res.sendError( 'No Data Found', 204 );
3801
3863
  }
@@ -3810,7 +3872,7 @@ export async function overviewTable( req, res ) {
3810
3872
  $limit: limit,
3811
3873
  } );
3812
3874
  }
3813
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
3875
+ const result = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
3814
3876
  if ( inputData.isExport ) {
3815
3877
  const exportdata = [];
3816
3878
  result.forEach( ( element ) => {
@@ -3847,10 +3909,11 @@ export async function overviewTable( req, res ) {
3847
3909
  temp['Status'] = toCamelCase( element.status );
3848
3910
  break;
3849
3911
  case 'uniform-detection':
3850
- temp['Before Count'] = element.beforeCount;
3851
- temp['After Count'] = element.afterCount;
3912
+ temp['Customer ID'] = element.tempId;
3913
+ temp['Question'] = element.question;
3914
+ temp['User Comments'] = element.userComments;
3852
3915
  temp['Audit Type'] = element.auditType;
3853
- temp['Status'] = toCamelCase( element.status );
3916
+ temp['Status'] = toCamelCase( element.auditStatus );
3854
3917
  break;
3855
3918
  }
3856
3919
  exportdata.push( temp );
@@ -4423,6 +4486,7 @@ export async function getDraftedData( req, res ) {
4423
4486
  export async function save( req, res ) {
4424
4487
  try {
4425
4488
  const openSearch = JSON.parse( process.env.OPENSEARCH );
4489
+ const sqs = JSON.parse( process.env.SQS );
4426
4490
  const inputData = req.body;
4427
4491
  const isoDate = req.userAudit?.startTime;
4428
4492
  const currentTime = dayjs();
@@ -4447,6 +4511,48 @@ export async function save( req, res ) {
4447
4511
  };
4448
4512
  await updateOneUserEmpDetection( { _id: inputData.auditId }, userUpdated );
4449
4513
  await updateOneStoreEmpDetection( query, storeUpdated );
4514
+
4515
+ const getFilePath = await findOneTraxAuditData(
4516
+ {
4517
+ fileDate: inputData.fileDate,
4518
+ storeId: inputData.storeId,
4519
+ moduleType: inputData.moduleType,
4520
+ },
4521
+ );
4522
+ if ( !getFilePath ) {
4523
+ return res.sendError( ' SQS is not sent due to Inserted Data is not there', 400 );
4524
+ }
4525
+ const tempId=[];
4526
+ if ( inputData.employeeCount > 0 ) {
4527
+ for ( let i =0; i<inputData?.employee.length; i++ ) {
4528
+ tempId.push( inputData?.employee[i].img_id );
4529
+ }
4530
+ }
4531
+ const sqsProduceQueue = {
4532
+ QueueUrl: `${sqs.url}${sqs.uniformOutput}`,
4533
+ MessageBody: JSON.stringify( {
4534
+ storeId: inputData.storeId,
4535
+ fileDate: inputData.fileDate,
4536
+ moduleType: inputData.moduleType,
4537
+ inputBucketName: getFilePath?.sqs?.Body?.inputBucketName,
4538
+ tempId: tempId,
4539
+ count: inputData.employeeCount,
4540
+ folderPath: getFilePath?.sqs?.Body?.folderPath,
4541
+ } ),
4542
+ };
4543
+ const sqsQueue = await sendMessageToQueue(
4544
+ sqsProduceQueue.QueueUrl,
4545
+ sqsProduceQueue.MessageBody,
4546
+ );
4547
+
4548
+ if ( sqsQueue.statusCode ) {
4549
+ logger.error( {
4550
+ error: `${sqsQueue}`,
4551
+ type: 'UPLOAD_ERROR',
4552
+ } );
4553
+ return res.sendError( 'SQS not sent', 500 );
4554
+ }
4555
+
4450
4556
  const logData = {
4451
4557
  userId: req.user._id,
4452
4558
  userName: req.user.userName,
@@ -51,6 +51,7 @@ export const saveDraftSchema = joi.object( {
51
51
  storeId: joi.string().required(),
52
52
  auditId: joi.string().required(),
53
53
  moduleType: joi.string().required(),
54
+ timeSpent: joi.number().required(),
54
55
  zoneName: joi.string().required(),
55
56
  auditType: joi.string().required(),
56
57
  fileDate: joi.string().required(),
@@ -89,6 +90,7 @@ export const saveSchema = joi.object( {
89
90
  fileDate: joi.string().required(),
90
91
  auditType: joi.string().required(),
91
92
  moduleType: joi.string().required(),
93
+ timeSpent: joi.number().required(),
92
94
  zoneName: joi.string().required(),
93
95
  beforeCount: joi.number().required(),
94
96
  junkCount: joi.number().required(),
@@ -154,6 +154,7 @@ 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 || '';
157
158
  }
158
159
  } );
159
160
  }
@@ -83,6 +83,7 @@ export async function isTraxAuditDocumentExist( req, res, next ) {
83
83
  query ={
84
84
  storeId: inputData.storeId,
85
85
  fileDate: inputData.fileDate,
86
+ tempId: inputData.tempId,
86
87
  moduleType: inputData.moduleType,
87
88
  };
88
89
  break;