tango-app-api-audit 3.4.7 → 3.4.8

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.7",
3
+ "version": "3.4.8",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -4589,6 +4589,7 @@ export async function auditViewLogs( req, res ) {
4589
4589
  } else {
4590
4590
  switch ( inputData.moduleType ) {
4591
4591
  case 'unattended-customer':
4592
+ const tempId = Number( inputData.tempId );
4592
4593
  logsQuery = {
4593
4594
  'size': 100,
4594
4595
  'query': {
@@ -4596,22 +4597,22 @@ export async function auditViewLogs( req, res ) {
4596
4597
  'must': [
4597
4598
  {
4598
4599
  'term': {
4599
- 'data.fileDate.keyword': inputData.fileDate,
4600
+ 'logData.fileDate.keyword': inputData.fileDate,
4600
4601
  },
4601
4602
  },
4602
4603
  {
4603
4604
  'term': {
4604
- 'data.storeId.keyword': inputData.storeId,
4605
+ 'logData.storeId.keyword': inputData.storeId,
4605
4606
  },
4606
4607
  },
4607
4608
  {
4608
4609
  'term': {
4609
- 'data.moduleType.keyword': inputData.moduleType,
4610
+ 'logData.moduleType.keyword': inputData.moduleType,
4610
4611
  },
4611
4612
  },
4612
4613
  {
4613
4614
  'term': {
4614
- 'data.tempId.keyword': inputData.tempId,
4615
+ 'logData.tempId.keyword': tempId,
4615
4616
  },
4616
4617
  },
4617
4618
  {
@@ -4632,22 +4633,22 @@ export async function auditViewLogs( req, res ) {
4632
4633
  'must': [
4633
4634
  {
4634
4635
  'term': {
4635
- 'data.fileDate.keyword': inputData.fileDate,
4636
+ 'logData.fileDate.keyword': inputData.fileDate,
4636
4637
  },
4637
4638
  },
4638
4639
  {
4639
4640
  'term': {
4640
- 'data.storeId.keyword': inputData.storeId,
4641
+ 'logData.storeId.keyword': inputData.storeId,
4641
4642
  },
4642
4643
  },
4643
4644
  {
4644
4645
  'term': {
4645
- 'data.moduleType.keyword': inputData.moduleType,
4646
+ 'logData.moduleType.keyword': inputData.moduleType,
4646
4647
  },
4647
4648
  },
4648
4649
  {
4649
4650
  'term': {
4650
- 'data.question.keyword': inputData.question,
4651
+ 'logData.question.keyword': inputData.question,
4651
4652
  },
4652
4653
  },
4653
4654
  {
@@ -4700,22 +4701,22 @@ export async function auditViewLogs( req, res ) {
4700
4701
  'must': [
4701
4702
  {
4702
4703
  'term': {
4703
- 'data.fileDate.keyword': inputData.fileDate,
4704
+ 'logData.fileDate.keyword': inputData.fileDate,
4704
4705
  },
4705
4706
  },
4706
4707
  {
4707
4708
  'term': {
4708
- 'data.storeId.keyword': inputData.storeId,
4709
+ 'logData.storeId.keyword': inputData.storeId,
4709
4710
  },
4710
4711
  },
4711
4712
  {
4712
4713
  'term': {
4713
- 'data.moduleType.keyword': inputData.moduleType,
4714
+ 'logData.moduleType.keyword': inputData.moduleType,
4714
4715
  },
4715
4716
  },
4716
4717
  {
4717
4718
  'term': {
4718
- 'data.streamName.keyword': inputData.streamName,
4719
+ 'logData.streamName.keyword': inputData.streamName,
4719
4720
  },
4720
4721
  },
4721
4722
  {
@@ -1194,7 +1194,7 @@ export async function getAuditFile( req, res ) {
1194
1194
  userName: userdata.name,
1195
1195
  logType: 'traxAudit',
1196
1196
  logSubType: 'auditStart',
1197
- data: {
1197
+ logData: {
1198
1198
  fileDate: msg.fileDate,
1199
1199
  storeId: msg.storeId,
1200
1200
  clientId: storeInfo?.clientId,
@@ -1362,7 +1362,7 @@ export async function getUpdatedFile( req, res ) {
1362
1362
  userName: userdata.name,
1363
1363
  logType: 'traxAudit',
1364
1364
  logSubType: 'auditStart',
1365
- data: {
1365
+ logData: {
1366
1366
  fileDate: msg.fileDate,
1367
1367
  storeId: msg.storeId,
1368
1368
  clientId: storeInfo?.clientId,
@@ -1431,6 +1431,32 @@ export async function saveBinary( req, res ) {
1431
1431
  if ( updatDataunattended.modifiedCount==0 ) {
1432
1432
  return res.sendError( 'Update failed, it may be invalid request', 400 );
1433
1433
  }
1434
+ const logData2 = {
1435
+ userId: req.user._id,
1436
+ userName: req.user.userName,
1437
+ logType: 'traxAudit',
1438
+ logSubType: 'auditDone',
1439
+ logData: {
1440
+ fileDate: req.userAudit?.fileDate,
1441
+ auditType: req.userAudit?.auditType,
1442
+ storeId: req.userAudit?.storeId,
1443
+ moduleType: req.userAudit?.moduleType,
1444
+ queueName: req.userAudit?.queueName,
1445
+ clientId: req.userAudit?.clientId,
1446
+ // beforeCount: req.userAudit?.beforeCount,
1447
+ // afterCount: inputData.employeeCount,
1448
+ startTime: req.userAudit?.startTime,
1449
+ streamName: req.userAudit?.streamName,
1450
+ tempId: req.userAudit?.tempId,
1451
+ question: req.userAudit?.question,
1452
+ result: req.userAudit?.answer,
1453
+ endTime: Date.now(),
1454
+ timeSpent: timeDifferenceInMinutes,
1455
+ auditId: new mongoose.Types.ObjectId( inputData.auditId ),
1456
+ },
1457
+ createdAt: Date.now(),
1458
+ };
1459
+ await insertOpenSearchData( openSearch.auditLog, logData2 );
1434
1460
  logger.info( 'update in binary data', { query: unattendedquery, update: update } );
1435
1461
  return res.sendSuccess( `Successfully updated in ${value}` );
1436
1462
 
@@ -1455,6 +1481,32 @@ export async function saveBinary( req, res ) {
1455
1481
  if ( updatDataleft.modifiedCount==0 ) {
1456
1482
  return res.sendError( 'Update failed, it may be invalid request', 400 );
1457
1483
  }
1484
+ const logData1 = {
1485
+ userId: req.user._id,
1486
+ userName: req.user.userName,
1487
+ logType: 'traxAudit',
1488
+ logSubType: 'auditDone',
1489
+ logData: {
1490
+ fileDate: req.userAudit?.fileDate,
1491
+ auditType: req.userAudit?.auditType,
1492
+ storeId: req.userAudit?.storeId,
1493
+ moduleType: req.userAudit?.moduleType,
1494
+ queueName: req.userAudit?.queueName,
1495
+ clientId: req.userAudit?.clientId,
1496
+ // beforeCount: req.userAudit?.beforeCount,
1497
+ // afterCount: inputData.employeeCount,
1498
+ startTime: req.userAudit?.startTime,
1499
+ streamName: req.userAudit?.streamName,
1500
+ tempId: req.userAudit?.tempId,
1501
+ question: req.userAudit?.question,
1502
+ result: req.userAudit?.answer,
1503
+ endTime: Date.now(),
1504
+ timeSpent: timeDifferenceInMinutes,
1505
+ auditId: new mongoose.Types.ObjectId( inputData.auditId ),
1506
+ },
1507
+ createdAt: Date.now(),
1508
+ };
1509
+ await insertOpenSearchData( openSearch.auditLog, logData1 );
1458
1510
  logger.info( 'update in binary data', { query: leftquery, update: leftupdate } );
1459
1511
  return res.sendSuccess( `Successfully updated in ${value}` );
1460
1512
 
@@ -1477,33 +1529,35 @@ export async function saveBinary( req, res ) {
1477
1529
  };
1478
1530
  let updatDatacamera= await updateOneBinaryAuditModel( cameraquery, cameraupdate );
1479
1531
  if ( updatDatacamera.modifiedCount==0 ) {
1480
- const logData = {
1481
- userId: req.user._id,
1482
- userName: req.user.userName,
1483
- logType: 'traxAudit',
1484
- logSubType: 'auditDone',
1485
- logData: {
1486
- fileDate: req.userAudit?.fileDate,
1487
- auditType: req.userAudit?.auditType,
1488
- storeId: req.userAudit?.storeId,
1489
- moduleType: req.userAudit?.moduleType,
1490
- queueName: req.userAudit?.queueName,
1491
- clientId: req.userAudit?.clientId,
1492
- beforeCount: req.userAudit?.beforeCount,
1493
- afterCount: inputData.employeeCount,
1494
- startTime: req.userAudit?.startTime,
1495
- streamName: req.userAudit?.streamName,
1496
- tempId: req.userAudit?.tempId,
1497
- question: req.userAudit?.question,
1498
- endTime: Date.now(),
1499
- timeSpent: timeDifferenceInMinutes,
1500
- auditId: new mongoose.Types.ObjectId( inputData.auditId ),
1501
- },
1502
- createdAt: Date.now(),
1503
- };
1504
- await insertOpenSearchData( openSearch.auditLog, logData );
1505
1532
  return res.sendError( 'Update failed, it may be invalid request', 400 );
1506
1533
  }
1534
+
1535
+ const logData = {
1536
+ userId: req.user._id,
1537
+ userName: req.user.userName,
1538
+ logType: 'traxAudit',
1539
+ logSubType: 'auditDone',
1540
+ logData: {
1541
+ fileDate: req.userAudit?.fileDate,
1542
+ auditType: req.userAudit?.auditType,
1543
+ storeId: req.userAudit?.storeId,
1544
+ moduleType: req.userAudit?.moduleType,
1545
+ queueName: req.userAudit?.queueName,
1546
+ clientId: req.userAudit?.clientId,
1547
+ // beforeCount: req.userAudit?.beforeCount,
1548
+ // afterCount: inputData.employeeCount,
1549
+ startTime: req.userAudit?.startTime,
1550
+ streamName: req.userAudit?.streamName,
1551
+ tempId: req.userAudit?.tempId,
1552
+ question: req.userAudit?.question,
1553
+ result: req.userAudit?.answer,
1554
+ endTime: Date.now(),
1555
+ timeSpent: timeDifferenceInMinutes,
1556
+ auditId: new mongoose.Types.ObjectId( inputData.auditId ),
1557
+ },
1558
+ createdAt: Date.now(),
1559
+ };
1560
+ await insertOpenSearchData( openSearch.auditLog, logData );
1507
1561
  logger.info( 'update in binary data', { query: cameraquery, update: cameraupdate } );
1508
1562
  return res.sendSuccess( `Successfully updated in ${value}` );
1509
1563
 
@@ -1879,9 +1933,9 @@ export async function clientMetrics( req, res ) {
1879
1933
  },
1880
1934
  {
1881
1935
  $project: {
1882
- completedStores: { $cond: [ { $eq: [ '$status', 'completed' ] }, 1, 0 ] },
1883
- notAssignedStores: { $cond: [ { $eq: [ '$status', 'not_assign' ] }, 1, 0 ] },
1884
- inprogressStores: { $cond: [ { $in: [ '$status', [ 'inprogress', 'drafted', 'assigned' ] ] }, 1, 0 ] },
1936
+ completedStores: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ] },
1937
+ notAssignedStores: { $cond: [ { $eq: [ '$auditStatus', 'not_assign' ] }, 1, 0 ] },
1938
+ inprogressStores: { $cond: [ { $in: [ '$auditStatus', [ 'inprogress', 'drafted', 'assigned' ] ] }, 1, 0 ] },
1885
1939
  },
1886
1940
  },
1887
1941
  {
@@ -2077,6 +2131,12 @@ export async function clientMetrics( req, res ) {
2077
2131
  },
2078
2132
 
2079
2133
  );
2134
+ MappingQuery.push(
2135
+ {
2136
+ $match: { clientStatus: { $in: inputData.filterByStatus } },
2137
+ },
2138
+
2139
+ );
2080
2140
  }
2081
2141
 
2082
2142
  if ( inputData.searchValue && inputData.searchValue!== '' ) {
@@ -2091,6 +2151,18 @@ export async function clientMetrics( req, res ) {
2091
2151
 
2092
2152
  },
2093
2153
  } );
2154
+
2155
+ MappingQuery.push( {
2156
+ $match: {
2157
+ $or: [
2158
+ { clientId: { $regex: inputData.searchValue, $options: 'i' } },
2159
+ { clientName: { $regex: inputData.searchValue, $options: 'i' } },
2160
+ { moduleType: { $regex: inputData.searchValue, $options: 'i' } },
2161
+ { clientStatus: { $regex: inputData.searchValue, $options: 'i' } },
2162
+ ],
2163
+
2164
+ },
2165
+ } );
2094
2166
  }
2095
2167
  if ( inputData.sortColumnName ) {
2096
2168
  const sortBy = inputData.sortBy || -1;
@@ -2099,6 +2171,11 @@ export async function clientMetrics( req, res ) {
2099
2171
  $sort: { [sortColumn]: sortBy },
2100
2172
  },
2101
2173
  );
2174
+
2175
+ MappingQuery.push( {
2176
+ $sort: { [sortColumn]: sortBy },
2177
+ },
2178
+ );
2102
2179
  }
2103
2180
 
2104
2181
  const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
@@ -2107,10 +2184,25 @@ export async function clientMetrics( req, res ) {
2107
2184
  return res.sendError( 'No Data Found', 204 );
2108
2185
  }
2109
2186
 
2110
- query.push(
2111
- { $skip: offset },
2112
- { $limit: limit },
2113
- );
2187
+ if ( inputData.isExport ) {
2188
+ query.push( { $limit: 10000 } );
2189
+
2190
+ MappingQuery.push( { $limit: 10000 } );
2191
+ } else {
2192
+ query.push( {
2193
+ $skip: offset,
2194
+ },
2195
+ {
2196
+ $limit: limit,
2197
+ } );
2198
+
2199
+ MappingQuery.push( {
2200
+ $skip: offset,
2201
+ },
2202
+ {
2203
+ $limit: limit,
2204
+ } );
2205
+ }
2114
2206
  if ( inputData.isExport ) {
2115
2207
  query.push(
2116
2208
  {
@@ -2131,9 +2223,28 @@ export async function clientMetrics( req, res ) {
2131
2223
  },
2132
2224
  },
2133
2225
  );
2226
+
2227
+ MappingQuery.push(
2228
+ {
2229
+ $project: {
2230
+ '_id': 0,
2231
+ 'File Date': '$fileDate',
2232
+ 'Brand Name': '$clientName',
2233
+ 'Brand Id': '$clientId',
2234
+ 'Product Type': '$value',
2235
+ // 'Completed Percentage': '$completionPercentage',
2236
+ 'Installed Stores': '$installedStore',
2237
+ 'Audit Stores': '$totalFilesCount',
2238
+ 'Inprogress Stores': '$inprogressStoresCount',
2239
+ 'Not Assigned Stores': '$notAssignedCount',
2240
+ // 'Not Assigned Stores': '$notAssignedStores',
2241
+ 'Completed Stores': '$completedStores',
2242
+ 'Status': '$clientStatus',
2243
+ },
2244
+ },
2245
+ );
2134
2246
  }
2135
2247
 
2136
- logger.info( { query: query } );
2137
2248
  const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
2138
2249
  if ( result.length == 0 ) {
2139
2250
  return res.sendError( 'No Data Found', 204 );
@@ -2169,7 +2280,7 @@ export async function storeMetrics( req, res ) {
2169
2280
  }
2170
2281
 
2171
2282
  if ( inputData.filterByStatus && inputData.filterByStatus?.length > 0 ) {
2172
- filter.push( { status: { $in: inputData.filterByStatus } } );
2283
+ [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? filter.push( { status: { $in: inputData.filterByStatus } } ) : filter.push( { auditStatus: { $in: inputData.filterByStatus } } );
2173
2284
  }
2174
2285
 
2175
2286
  if ( inputData.filterByAuditType && inputData.filterByAuditType?.length > 0 ) {
@@ -2567,6 +2678,26 @@ export async function storeMetrics( req, res ) {
2567
2678
  ],
2568
2679
  },
2569
2680
  } );
2681
+
2682
+ binaryQuery.push( {
2683
+ $match: {
2684
+ $or: [
2685
+ { clientId: { $regex: inputData.searchValue, $options: 'i' } },
2686
+ { clientName: { $regex: inputData.searchValue, $options: 'i' } },
2687
+ { storeId: { $regex: inputData.searchValue, $options: 'i' } },
2688
+ { storeName: { $regex: inputData.searchValue, $options: 'i' } },
2689
+ { userName: { $regex: inputData.searchValue, $options: 'i' } },
2690
+ { status: { $regex: inputData.searchValue, $options: 'i' } },
2691
+ { auditType: { $regex: inputData.searchValue, $options: 'i' } },
2692
+ { value: { $regex: inputData.searchValue, $options: 'i' } },
2693
+ { tempId: { $regex: inputData.searchValue, $options: 'i' } },
2694
+ { question: { $regex: inputData.searchValue, $options: 'i' } },
2695
+ { answer: { $regex: inputData.searchValue, $options: 'i' } },
2696
+ { auditStatus: { $regex: inputData.searchValue, $options: 'i' } },
2697
+ { userComments: { $regex: inputData.searchValue, $options: 'i' } },
2698
+ ],
2699
+ },
2700
+ } );
2570
2701
  }
2571
2702
 
2572
2703
  if ( inputData.sortColumnName ) {
@@ -2576,6 +2707,11 @@ export async function storeMetrics( req, res ) {
2576
2707
  $sort: { [sortColumn]: sortBy },
2577
2708
  },
2578
2709
  );
2710
+
2711
+ binaryQuery.push( {
2712
+ $sort: { [sortColumn]: sortBy },
2713
+ },
2714
+ );
2579
2715
  }
2580
2716
  logger.info( { keyss: [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType ) } );
2581
2717
  const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
@@ -2584,15 +2720,23 @@ export async function storeMetrics( req, res ) {
2584
2720
  if ( count.length == 0 ) {
2585
2721
  return res.sendError( 'No data Found', 204 );
2586
2722
  }
2587
- if ( !inputData.isExport ) {
2723
+ if ( inputData.isExport ) {
2724
+ query.push( { $limit: 10000 } );
2725
+ binaryQuery.push( { $limit: 10000 } );
2726
+ } else {
2588
2727
  query.push( {
2589
2728
  $skip: offset,
2590
2729
  },
2591
2730
  {
2592
2731
  $limit: limit,
2593
2732
  } );
2594
- } else {
2595
- query.push( { $limit: 10000 } );
2733
+
2734
+ binaryQuery.push( {
2735
+ $skip: offset,
2736
+ },
2737
+ {
2738
+ $limit: limit,
2739
+ } );
2596
2740
  }
2597
2741
  const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
2598
2742
  if ( inputData.isExport ) {
@@ -2612,12 +2756,14 @@ export async function storeMetrics( req, res ) {
2612
2756
  case 'camera-angle-change':
2613
2757
  temp['stream Name'] = element.streamName;
2614
2758
  temp['User Comments'] = element.userComments;
2759
+ temp['Status'] = toCamelCase( element.auditStatus );
2615
2760
  temp['Result'] = element.answer;
2616
2761
  break;
2617
2762
  case 'unattended-customer':
2618
2763
  temp['Customer ID'] = element.tempId;
2619
2764
  temp['Question'] = element.question;
2620
2765
  temp['User Comments'] = element.userComments;
2766
+ temp['Status'] = toCamelCase( element.auditStatus );
2621
2767
  temp['Result'] = element.answer;
2622
2768
  break;
2623
2769
  case 'left-in-middle':
@@ -2694,12 +2840,13 @@ export async function userMetrics( req, res ) {
2694
2840
  $and: filter,
2695
2841
  },
2696
2842
  },
2843
+
2697
2844
  {
2698
2845
  $project: {
2699
2846
  userId: 1,
2700
2847
  fileDate: 1,
2701
2848
  startTime: 1,
2702
- endTime: 1,
2849
+ endTime: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$endTime', '$$REMOVE' ] },
2703
2850
  beforeCount: 1,
2704
2851
  moduleType: 1,
2705
2852
  afterCount: 1,
@@ -2711,6 +2858,11 @@ export async function userMetrics( req, res ) {
2711
2858
  $replaceAll: { input: '$moduleType', find: '-', replacement: ' ' },
2712
2859
  } },
2713
2860
  },
2861
+ {
2862
+ $sort: {
2863
+ endTime: -1,
2864
+ },
2865
+ },
2714
2866
  {
2715
2867
  $group: {
2716
2868
  _id: { userId: '$userId', fileDate: '$fileDate' },
@@ -2720,7 +2872,7 @@ export async function userMetrics( req, res ) {
2720
2872
  beforeCount: { $sum: '$beforeCount' },
2721
2873
  afterCount: { $sum: '$afterCount' },
2722
2874
  checkIntime: { $first: '$startTime' },
2723
- checkOutTime: { $last: '$endTime' },
2875
+ checkOutTime: { $first: '$endTime' },
2724
2876
  moduleType: { $last: '$moduleType' },
2725
2877
  value: { $last: '$value' },
2726
2878
  createdAt: { $first: '$createdAt' },