tango-app-api-audit 3.4.0-alpha.4 → 3.4.0-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.0-alpha.4",
3
+ "version": "3.4.0-alpha.6",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1450,6 +1450,9 @@ export async function userAuditHistory( req, res ) {
1450
1450
  const dateRangeCreatedAt = await getDateWithCustomizeTime( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
1451
1451
  let filter = [
1452
1452
  { userId: { $eq: userId } },
1453
+ {
1454
+ moduleType: { $eq: inputData.moduleType },
1455
+ },
1453
1456
  ];
1454
1457
 
1455
1458
  if ( inputData.dateType == 'fileDate' ) {
@@ -1464,12 +1467,6 @@ export async function userAuditHistory( req, res ) {
1464
1467
  );
1465
1468
  }
1466
1469
 
1467
- if ( inputData.filterByModuleType?.length > 0 ) {
1468
- filter.push( {
1469
- moduleType: { $in: inputData.filterByModuleType },
1470
- } );
1471
- }
1472
-
1473
1470
  if ( inputData.filterByAuditType?.length > 0 ) {
1474
1471
  filter.push( {
1475
1472
  auditType: { $in: inputData.filterByAuditType },
@@ -1705,23 +1702,18 @@ export async function clientMetrics( req, res ) {
1705
1702
  let filter = [
1706
1703
  { fileDateISO: { $gte: dateRange.start } },
1707
1704
  { fileDateISO: { $lte: dateRange.end } },
1705
+ { moduleType: { $eq: inputData.moduleType } },
1708
1706
  ];
1709
1707
 
1710
1708
  let storeAuditFilter = [
1711
1709
  { $eq: [ '$clientId', '$$clientId' ] },
1712
1710
  { $eq: [ '$fileDate', '$$fileDate' ] },
1711
+ {
1712
+ $eq: [ '$moduleType', inputData.moduleType ],
1713
+ },
1713
1714
 
1714
1715
  ];
1715
1716
 
1716
- if ( inputData?.filterByModuleType?.length> 0 ) {
1717
- filter.push(
1718
- { moduleType: { $in: inputData.filterByModuleType } },
1719
- );
1720
- storeAuditFilter.push( {
1721
- $in: [ '$moduleType', inputData.filterByModuleType ],
1722
- } );
1723
- }
1724
-
1725
1717
  if ( inputData?.filterByClient?.length> 0 ) {
1726
1718
  filter.push(
1727
1719
  { clientId: { $in: inputData.filterByClient } },
@@ -1930,6 +1922,7 @@ export async function storeMetrics( req, res ) {
1930
1922
  let filter = [
1931
1923
  { fileDateISO: { $gte: dateRange.start } },
1932
1924
  { fileDateISO: { $lte: dateRange.end } },
1925
+ { moduleType: { $eq: inputData.moduleType } },
1933
1926
 
1934
1927
  ];
1935
1928
  if ( inputData.filterByClientId && inputData.filterByClientId?.length > 0 ) {
@@ -1948,11 +1941,6 @@ export async function storeMetrics( req, res ) {
1948
1941
  filter.push( { auditType: { $in: inputData.filterByAuditType } } );
1949
1942
  }
1950
1943
 
1951
- if ( inputData.filterByModuleType && inputData.filterByModuleType?.length > 0 ) {
1952
- filter.push( { moduleType: { $in: inputData.filterByModuleType } } );
1953
- }
1954
-
1955
-
1956
1944
  const query = [
1957
1945
  {
1958
1946
  $match: {
@@ -2219,20 +2207,17 @@ export async function userMetrics( req, res ) {
2219
2207
  filter.push(
2220
2208
  { updatedAt: { $gte: dateRangeUpdatedAt.start } },
2221
2209
  { updatedAt: { $lte: dateRangeUpdatedAt.end } },
2210
+ { moduleType: { $eq: inputData.moduleType } },
2222
2211
 
2223
2212
  );
2224
2213
  } else {
2225
2214
  filter.push(
2226
2215
  { fileDateISO: { $gte: dateRange.start } },
2227
2216
  { fileDateISO: { $lte: dateRange.end } },
2217
+ { moduleType: { $eq: inputData.moduleType } },
2228
2218
 
2229
2219
  );
2230
2220
  }
2231
- if ( inputData?.filterByModuleType?.length> 0 ) {
2232
- filter.push(
2233
- { moduleType: { $in: inputData.filterByModuleType } },
2234
- );
2235
- }
2236
2221
  if ( inputData?.filterByStatus?.length> 0 ) {
2237
2222
  filter.push(
2238
2223
  { auditStatus: { $in: inputData.filterByStatus } },
@@ -2489,6 +2474,7 @@ export async function pendingSummaryTable( req, res ) {
2489
2474
  { fileDateISO: { $gte: dateRange.start } },
2490
2475
  { fileDateISO: { $lte: dateRange.end } },
2491
2476
  { auditStatus: { $ne: 'completed' } },
2477
+ { moduleType: { $eq: inputData.moduleType } },
2492
2478
 
2493
2479
  ];
2494
2480
 
@@ -2496,10 +2482,6 @@ export async function pendingSummaryTable( req, res ) {
2496
2482
  filters.push( { clientId: { $in: inputData.clientId } } );
2497
2483
  }
2498
2484
 
2499
- if ( inputData.filterByModuleType.length > 0 ) {
2500
- filters.push( { moduleType: { $in: inputData.filterByModuleType } } );
2501
- }
2502
-
2503
2485
  if ( inputData.filterByAuditType.length > 0 ) {
2504
2486
  filters.push( { auditType: { $in: inputData.filterByAuditType } } );
2505
2487
  }
@@ -2680,7 +2662,7 @@ export async function overAllAuditSummary( req, res ) {
2680
2662
  let filters =[
2681
2663
  { fileDateISO: { $gte: dateRange.start } },
2682
2664
  { fileDateISO: { $lte: dateRange.end } },
2683
- { moduleType: { $in: inputData.moduleType },
2665
+ { moduleType: { $eq: inputData.moduleType },
2684
2666
  },
2685
2667
  ];
2686
2668
  if ( inputData.clientId.length > 0 ) {
@@ -3030,13 +3012,11 @@ export async function summarySplit( req, res ) {
3030
3012
  let filters =[
3031
3013
  { fileDateISO: { $gte: dateRange.start } },
3032
3014
  { fileDateISO: { $lte: dateRange.end } },
3015
+ { moduleType: { $eq: inputData.moduleType } },
3033
3016
  ];
3034
3017
  if ( inputData.clientId.length > 0 ) {
3035
3018
  filters.push( { clientId: { $in: inputData.clientId } } );
3036
3019
  }
3037
- if ( inputData?.moduleType?.length > 0 ) {
3038
- filters.push( { moduleType: { $in: inputData.moduleType } } );
3039
- }
3040
3020
  const query =[
3041
3021
  {
3042
3022
  $match: {
@@ -3146,6 +3126,7 @@ export async function overviewTable( req, res ) {
3146
3126
  let filters =[
3147
3127
  { fileDateISO: { $gte: dateRange.start } },
3148
3128
  { fileDateISO: { $lte: dateRange.end } },
3129
+ { moduleType: { $eq: inputData.moduleType } },
3149
3130
 
3150
3131
  ];
3151
3132
 
@@ -3153,10 +3134,6 @@ export async function overviewTable( req, res ) {
3153
3134
  filters.push( { clientId: { $in: inputData.clientId } } );
3154
3135
  }
3155
3136
 
3156
- if ( inputData.filterByModuleType.length > 0 ) {
3157
- filters.push( { moduleType: { $in: inputData.filterByModuleType } } );
3158
- }
3159
-
3160
3137
  if ( inputData.filterByAuditType.length > 0 ) {
3161
3138
  filters.push( { auditType: { $in: inputData.filterByAuditType } } );
3162
3139
  }
@@ -1,6 +1,6 @@
1
1
  import { checkFileExist, download, getDate, getDateWithCustomizeTime, getUTC, insertOpenSearchData, listFileByPath, logger, signedUrl, sqsReceive } from 'tango-app-api-middleware';
2
2
  import { aggregateBinaryAudit, createBinaryAudit, updateOneBinaryAuditModel } from '../service/binaryAudit.service.js';
3
- import { findOneStore } from '../service/store.service.js';
3
+ import { countDocumentsStore, findOneStore } from '../service/store.service.js';
4
4
  import { findOneUser } from '../service/user.service.js';
5
5
  import { aggregateUserEmpDetection, createUserEmpDetection } from '../service/userEmpDetection.service.js';
6
6
  import { aggregateTraxAuditData, findOneTraxAuditData } from '../service/traxAuditData.service.js';
@@ -10,6 +10,7 @@ import { aggregateAssignAudit } from '../service/assignAudit.service.js';
10
10
  import { aggregateStoreEmpDetection } from '../service/storeEmpDetection.service.js';
11
11
  import { listQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
12
12
  import _ from 'lodash';
13
+ import mongoose from 'mongoose';
13
14
 
14
15
 
15
16
  export async function getDetectionAuditFile( req, res ) {
@@ -1181,6 +1182,7 @@ export async function saveBinary( req, res ) {
1181
1182
  let leftupdate={
1182
1183
  auditStatus: 'completed',
1183
1184
  answer: inputData.answer,
1185
+ userCommands: inputData.userComments || '',
1184
1186
  };
1185
1187
  let updatDataleft= await updateOneBinaryAuditModel( leftquery, leftupdate );
1186
1188
  if ( updatDataleft.modifiedCount==0 ) {
@@ -1202,6 +1204,7 @@ export async function saveBinary( req, res ) {
1202
1204
  let cameraupdate={
1203
1205
  auditStatus: 'completed',
1204
1206
  answer: inputData.answer,
1207
+ userCommands: inputData.userComments || '',
1205
1208
  };
1206
1209
  let updatDatacamera= await updateOneBinaryAuditModel( cameraquery, cameraupdate );
1207
1210
  if ( updatDatacamera.modifiedCount==0 ) {
@@ -1780,6 +1783,7 @@ export async function storeMetrics( req, res ) {
1780
1783
  // userId: {
1781
1784
  // $arrayElemAt: [ '$userId', { $subtract: [ { $size: '$userId' }, 1 ] } ], //need to check if no data
1782
1785
  // },
1786
+ userId: 1,
1783
1787
  auditType: 1,
1784
1788
  beforeCount: 1,
1785
1789
  afterCount: { $ifNull: [ '$afterCount', null ] },
@@ -1791,6 +1795,7 @@ export async function storeMetrics( req, res ) {
1791
1795
  }, null ] },
1792
1796
  timeSpent: 1,
1793
1797
  status: 1,
1798
+ auditStatus: 1,
1794
1799
  },
1795
1800
  },
1796
1801
  {
@@ -1898,6 +1903,7 @@ export async function storeMetrics( req, res ) {
1898
1903
 
1899
1904
  },
1900
1905
  status: 1,
1906
+ auditStatus: 1,
1901
1907
  },
1902
1908
  },
1903
1909
 
@@ -1918,6 +1924,7 @@ export async function storeMetrics( req, res ) {
1918
1924
  { tempId: { $regex: inputData.searchValue, $options: 'i' } },
1919
1925
  { question: { $regex: inputData.searchValue, $options: 'i' } },
1920
1926
  { answer: { $regex: inputData.searchValue, $options: 'i' } },
1927
+ { auditStatus: { $regex: inputData.searchValue, $options: 'i' } },
1921
1928
  ],
1922
1929
  },
1923
1930
  } );
@@ -1966,6 +1973,7 @@ export async function storeMetrics( req, res ) {
1966
1973
  'Accuracy': element.accuracy,
1967
1974
  'Time Spent': element.timeSpent,
1968
1975
  'Status': element.status,
1976
+ 'Audit Status': element.auditStatus,
1969
1977
  } );
1970
1978
  } else {
1971
1979
  exportdata.push( {
@@ -1983,6 +1991,7 @@ export async function storeMetrics( req, res ) {
1983
1991
  'Accuracy': element.accuracy,
1984
1992
  'Time Spent': element.timeSpent,
1985
1993
  'Status': element.status,
1994
+ 'Audit Status': element.auditStatus,
1986
1995
  } );
1987
1996
  }
1988
1997
  } );
@@ -2052,6 +2061,7 @@ export async function userMetrics( req, res ) {
2052
2061
  totalCompletedFiles: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ] },
2053
2062
  beforeCount: 1,
2054
2063
  afterCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$afterCount', 0 ] },
2064
+ auditStatus: 1,
2055
2065
  },
2056
2066
  },
2057
2067
  {
@@ -2068,6 +2078,7 @@ export async function userMetrics( req, res ) {
2068
2078
  tempId: { $last: '$tempId' },
2069
2079
  question: { $last: '$question' },
2070
2080
  answer: { $last: '$answer' },
2081
+ auditStatus: { $last: '$auditStatus' },
2071
2082
 
2072
2083
  },
2073
2084
  },
@@ -2093,6 +2104,7 @@ export async function userMetrics( req, res ) {
2093
2104
  differenceInSeconds: {
2094
2105
  $divide: [ { $subtract: [ '$checkOutTime', '$checkIntime' ] }, 1000 ],
2095
2106
  },
2107
+ auditStatus: 1,
2096
2108
  },
2097
2109
  },
2098
2110
  {
@@ -2112,6 +2124,7 @@ export async function userMetrics( req, res ) {
2112
2124
  hours: { $floor: { $divide: [ '$differenceInSeconds', 3600 ] } },
2113
2125
  minutes: { $floor: { $divide: [ { $mod: [ '$differenceInSeconds', 3600 ] }, 60 ] } },
2114
2126
  seconds: { $mod: [ '$differenceInSeconds', 60 ] },
2127
+ auditStatus: 1,
2115
2128
  },
2116
2129
  },
2117
2130
  {
@@ -2150,7 +2163,7 @@ export async function userMetrics( req, res ) {
2150
2163
  else: { $toString: { $round: [ '$seconds', 0 ] } },
2151
2164
  },
2152
2165
  },
2153
-
2166
+ auditStatus: 1,
2154
2167
  },
2155
2168
  },
2156
2169
  {
@@ -2172,6 +2185,7 @@ export async function userMetrics( req, res ) {
2172
2185
  workingHours: {
2173
2186
  $concat: [ '$hours', ':', '$minutes', ':', '$seconds' ],
2174
2187
  },
2188
+ auditStatus: 1,
2175
2189
  },
2176
2190
  },
2177
2191
  {
@@ -2229,6 +2243,7 @@ export async function userMetrics( req, res ) {
2229
2243
  },
2230
2244
  },
2231
2245
  workingHours: 1,
2246
+ auditStatus: 1,
2232
2247
  },
2233
2248
  },
2234
2249
  ];
@@ -2279,6 +2294,7 @@ export async function userMetrics( req, res ) {
2279
2294
  'Stream Name': '$streamName',
2280
2295
  'Question': '$question',
2281
2296
  'Answer': '$answer',
2297
+ 'Audit Status': '$auditStatus',
2282
2298
  },
2283
2299
  },
2284
2300
  );
@@ -2541,7 +2557,7 @@ export async function overAllAuditSummary( req, res ) {
2541
2557
  },
2542
2558
  },
2543
2559
  ];
2544
- const auditClientData = await aggregateAuditStoreData( auditClientDataQuery );
2560
+ const auditClientData = await aggregateTraxAuditData( auditClientDataQuery );
2545
2561
  if ( auditClientData.length >0 ) {
2546
2562
  temp.auditStores = auditClientData[0].totalFilesCount;
2547
2563
  }
@@ -2593,7 +2609,7 @@ export async function overAllAuditSummary( req, res ) {
2593
2609
  },
2594
2610
  },
2595
2611
  ];
2596
- const storeAudit = await aggregateStoreAudit( storeAuditQuery );
2612
+ const storeAudit = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( storeAuditQuery );
2597
2613
  if ( storeAudit.length > 0 ) {
2598
2614
  temp.inprogressStores= storeAudit[0].inprogressStores;
2599
2615
  temp.completedStores = storeAudit[0].completedStores;
@@ -2613,3 +2629,327 @@ export async function overAllAuditSummary( req, res ) {
2613
2629
  return res.sendError( err, 500 );
2614
2630
  }
2615
2631
  }
2632
+
2633
+ export async function summarySplit( req, res ) {
2634
+ try {
2635
+ const inputData = req.body;
2636
+ const temp = {
2637
+ total: 0,
2638
+ auditInprogress: 0,
2639
+ reAuditInprogress: 0,
2640
+ draft: 0,
2641
+ assigned: 0,
2642
+ auditCompleted: 0,
2643
+ reAuditCompleted: 0,
2644
+ };
2645
+
2646
+ const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
2647
+ let filters =[
2648
+ { fileDateISO: { $gte: dateRange.start } },
2649
+ { fileDateISO: { $lte: dateRange.end } },
2650
+ { moduleType: { $eq: inputData.moduleType } },
2651
+ ];
2652
+ if ( inputData.clientId.length > 0 ) {
2653
+ filters.push( { clientId: { $in: inputData.clientId } } );
2654
+ }
2655
+ const query =[
2656
+ {
2657
+ $match: {
2658
+ $and: filters,
2659
+ },
2660
+
2661
+ },
2662
+ {
2663
+ $project: {
2664
+ auditInprogress: {
2665
+ $cond: [
2666
+ { $and: [ { $eq: [ '$auditType', 'Audit' ] }, { $eq: [ '$status', 'inprogress' ] } ] }, 1, 0,
2667
+ ],
2668
+ },
2669
+ reAuditInprogress: {
2670
+ $cond: [
2671
+ { $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$status', 'inprogress' ] } ] }, 1, 0,
2672
+ ],
2673
+ },
2674
+ draft: {
2675
+ $cond: [
2676
+ { $eq: [ '$status', 'drafted' ] }, 1, 0,
2677
+ ],
2678
+ },
2679
+ assigned: {
2680
+ $cond: [
2681
+ { $eq: [ '$status', 'assigned' ] }, 1, 0,
2682
+ ],
2683
+ },
2684
+
2685
+ reAuditCompleted: {
2686
+ $cond: [
2687
+ { $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$status', 'completed' ] } ] }, 1, 0,
2688
+ ],
2689
+ },
2690
+ auditCompleted: {
2691
+ $cond: [
2692
+ { $and: [ { $eq: [ '$auditType', 'Audit' ] }, { $eq: [ '$status', 'completed' ] } ] }, 1, 0,
2693
+ ],
2694
+ },
2695
+ },
2696
+ },
2697
+ {
2698
+ $group: {
2699
+ _id: null,
2700
+ auditInprogress: { $sum: '$auditInprogress' },
2701
+ reAuditInprogress: { $sum: '$reAuditInprogress' },
2702
+ draft: { $sum: '$draft' },
2703
+ assigned: { $sum: '$assigned' },
2704
+ reAuditCompleted: { $sum: '$reAuditCompleted' },
2705
+ auditCompleted: { $sum: '$auditCompleted' },
2706
+
2707
+ },
2708
+ },
2709
+ {
2710
+ $project: {
2711
+ _id: 0,
2712
+ totalInprogress: 1,
2713
+ auditInprogress: 1,
2714
+ reAuditInprogress: 1,
2715
+ draft: 1,
2716
+ assigned: 1,
2717
+ reAuditCompleted: 1,
2718
+ auditCompleted: 1,
2719
+ totalCount: { $ifNull: [ 0, 0 ] },
2720
+
2721
+ },
2722
+ },
2723
+ ];
2724
+ const totalQuery = [
2725
+ {
2726
+ $match: {
2727
+ $and: filters,
2728
+ },
2729
+
2730
+ },
2731
+ {
2732
+ $group: {
2733
+ _id: null,
2734
+ total: { $sum: 1 },
2735
+ },
2736
+ },
2737
+ {
2738
+ $project: {
2739
+ _id: 0,
2740
+ total: 1,
2741
+ },
2742
+ },
2743
+ ];
2744
+ const result = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
2745
+ const totalCount = await aggregateTraxAuditData( totalQuery );
2746
+ result[0].totalCount = totalCount[0]?.total;
2747
+ return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
2748
+ } catch ( error ) {
2749
+ const err = error.message || 'Internal Server Error';
2750
+ logger.error( { error: error, message: req.body, function: 'summarySplit' } );
2751
+ return res.sendError( err, 500 );
2752
+ }
2753
+ }
2754
+
2755
+ export async function overviewTable( req, res ) {
2756
+ try {
2757
+ const inputData = req.body;
2758
+ const limit = inputData.limit || 10;
2759
+ const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
2760
+ const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
2761
+ let filters =[
2762
+ { fileDateISO: { $gte: dateRange.start } },
2763
+ { fileDateISO: { $lte: dateRange.end } },
2764
+ { moduleType: { $eq: inputData.moduleType } },
2765
+
2766
+ ];
2767
+
2768
+ if ( inputData.clientId.length > 0 ) {
2769
+ filters.push( { clientId: { $in: inputData.clientId } } );
2770
+ }
2771
+
2772
+ if ( inputData.filterByAuditType.length > 0 ) {
2773
+ filters.push( { auditType: { $in: inputData.filterByAuditType } } );
2774
+ }
2775
+
2776
+ if ( inputData.filterByStatus.length > 0 ) {
2777
+ filters.push( { status: { $in: inputData.filterByStatus } } );
2778
+ }
2779
+
2780
+ const query =[
2781
+ {
2782
+ $match: {
2783
+ $and: filters,
2784
+ },
2785
+
2786
+ },
2787
+ {
2788
+ $project: {
2789
+ _id: 0,
2790
+ storeId: 1,
2791
+ clientId: 1,
2792
+ streamName: 1,
2793
+ tempId: 1,
2794
+ question: 1,
2795
+ answer: 1,
2796
+ userCommands: 1,
2797
+ fileDate: 1,
2798
+ moduleType: 1,
2799
+ beforeCount: 1,
2800
+ afterCount: 1,
2801
+ auditType: 1,
2802
+ status: 1,
2803
+ auditStatus: 1,
2804
+ // userId: 1,
2805
+ },
2806
+ },
2807
+ // {
2808
+ // $lookup: {
2809
+ // from: 'users',
2810
+ // let: { userId: '$userId' },
2811
+ // pipeline: [
2812
+ // {
2813
+ // $match: {
2814
+ // $expr: {
2815
+ // $eq: [ '$_id', '$$userId' ],
2816
+ // },
2817
+ // },
2818
+ // },
2819
+ // {
2820
+ // $project: {
2821
+ // userName: 1,
2822
+ // userEmail: '$email',
2823
+ // },
2824
+ // },
2825
+ // ], as: 'user',
2826
+ // },
2827
+ // },
2828
+ // {
2829
+ // $unwind: {
2830
+ // path: '$user',
2831
+ // preserveNullAndEmptyArrays: true,
2832
+ // },
2833
+ // },
2834
+ {
2835
+ $project: {
2836
+ storeId: 1,
2837
+ clientId: 1,
2838
+ streamName: 1,
2839
+ tempId: 1,
2840
+ question: 1,
2841
+ answer: 1,
2842
+ userCommands: 1,
2843
+ fileDate: 1,
2844
+ moduleType: 1,
2845
+ beforeCount: 1,
2846
+ afterCount: 1,
2847
+ auditType: 1,
2848
+ status: 1,
2849
+ auditStatus: 1,
2850
+ // userName: '$user.userName',
2851
+ // userEmail: '$user.userEmail',
2852
+
2853
+ },
2854
+ },
2855
+ ];
2856
+ if ( inputData.searchValue && inputData.searchValue!== '' ) {
2857
+ query.push( {
2858
+ $match: {
2859
+ $or: [
2860
+ { storeId: { $regex: inputData.searchValue, $options: 'i' } },
2861
+ { clientId: { $regex: inputData.searchValue, $options: 'i' } },
2862
+ { fileDate: { $regex: inputData.searchValue, $options: 'i' } },
2863
+ { auditType: { $regex: inputData.searchValue, $options: 'i' } },
2864
+ { status: { $regex: inputData.searchValue, $options: 'i' } },
2865
+ { auditStatus: { $regex: inputData.searchValue, $options: 'i' } },
2866
+ { moduleType: { $regex: inputData.searchValue, $options: 'i' } },
2867
+ { streamName: { $regex: inputData.searchValue, $options: 'i' } },
2868
+ { tempId: { $regex: inputData.searchValue, $options: 'i' } },
2869
+ { question: { $regex: inputData.searchValue, $options: 'i' } },
2870
+ { answer: { $regex: inputData.searchValue, $options: 'i' } },
2871
+ { userCommands: { $regex: inputData.searchValue, $options: 'i' } },
2872
+ // { userName: { $regex: inputData.searchValue, $options: 'i' } },
2873
+ // { userEmail: { $regex: inputData.searchValue, $options: 'i' } },
2874
+ ],
2875
+
2876
+ },
2877
+ } );
2878
+ }
2879
+ if ( inputData.sortColumnName ) {
2880
+ const sortBy = inputData.sortBy || -1;
2881
+ const sortColumn = inputData.sortColumnName;
2882
+ query.push( {
2883
+ $sort: { [sortColumn]: sortBy },
2884
+ },
2885
+ );
2886
+ }
2887
+ const count = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
2888
+ if ( count.length == 0 ) {
2889
+ return res.sendError( 'No Data Found', 204 );
2890
+ }
2891
+
2892
+ if ( inputData.isExport ) {
2893
+ query.push( { $limit: 10000 } );
2894
+ } else {
2895
+ query.push( {
2896
+ $skip: offset,
2897
+ },
2898
+ {
2899
+ $limit: limit,
2900
+ } );
2901
+ }
2902
+ const result = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
2903
+ if ( inputData.isExport ) {
2904
+ const exportdata = [];
2905
+ result.forEach( ( element ) => {
2906
+ if ( element.moduleType == 'zone' ) {
2907
+ exportdata.push( {
2908
+ 'Store ID': element.storeId,
2909
+ 'Brand ID': element.clientId,
2910
+ 'Stream Name': element.streamName,
2911
+ 'Customer ID': element.tempId,
2912
+ 'Question': element.question,
2913
+ 'Answer': element.answer,
2914
+ 'User Comments': element.userCommands,
2915
+ 'File Date': element.fileDate,
2916
+ 'Product Type': element.moduleType,
2917
+ 'Audit Type': element.auditType,
2918
+ 'Before Count': element.beforeCount,
2919
+ 'After Count': element.afterCount,
2920
+ // 'User Name': element.userName,
2921
+ // 'User Email': element.userEmail,
2922
+ 'Status': element.status,
2923
+ 'Audit Status': element.status,
2924
+ } );
2925
+ } else {
2926
+ exportdata.push( {
2927
+ 'Store ID': element.storeId,
2928
+ 'Brand ID': element.clientId,
2929
+ 'File Date': element.fileDate,
2930
+ 'Stream Name': element.streamName,
2931
+ 'Customer ID': element.tempId,
2932
+ 'Question': element.question,
2933
+ 'Answer': element.answer,
2934
+ 'User Comments': element.userCommands,
2935
+ 'Product Type': element.moduleType,
2936
+ 'Audit Type': element.auditType,
2937
+ 'Before Count': element.beforeCount,
2938
+ 'After Count': element.afterCount,
2939
+ // 'User Name': element.userName,
2940
+ // 'User Email': element.userEmail,
2941
+ 'Status': element.status,
2942
+ 'Audit Status': element.status,
2943
+ } );
2944
+ }
2945
+ } );
2946
+ await download( exportdata, res );
2947
+ return;
2948
+ }
2949
+ return res.sendSuccess( { result: result, count: count.length } );
2950
+ } catch ( error ) {
2951
+ const err = error.message || 'Internal Server Error';
2952
+ logger.error( { error: error, message: req.body, function: 'overviewTable' } );
2953
+ return res.sendError( err, 500 );
2954
+ }
2955
+ }
@@ -1,5 +1,5 @@
1
1
  import j2s from 'joi-to-swagger';
2
- import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema, pendingSummaryTableSchema } from '../dtos/traxAudit.dtos.js';
2
+ import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema, pendingSummaryTableSchema, overAllAuditSummarySchema, overviewTableSchema, summarySplitSchema } from '../dtos/traxAudit.dtos.js';
3
3
 
4
4
  export const traxAuditDocs = {
5
5
 
@@ -200,4 +200,72 @@ export const traxAuditDocs = {
200
200
  },
201
201
  },
202
202
  },
203
+ '/v3/trax-audit/metrics/overall-audit-summary': {
204
+ post: {
205
+ tags: [ 'Trax Audit' ],
206
+ description: `Get overall user taken data with some filters `,
207
+ operationId: 'metrics/overall-audit-summary',
208
+ parameters: {},
209
+ requestBody: {
210
+ content: {
211
+ 'application/json': {
212
+ schema: j2s( overAllAuditSummarySchema ).swagger,
213
+ },
214
+ },
215
+ },
216
+ responses: {
217
+ 200: { description: 'Successful' },
218
+ 401: { description: 'Unauthorized User' },
219
+ 422: { description: 'Field Error' },
220
+ 500: { description: 'Server Error' },
221
+ 204: { description: 'Not Found' },
222
+ },
223
+ },
224
+ },
225
+
226
+ '/v3/trax-audit/metrics/summary-split-up': {
227
+ post: {
228
+ tags: [ 'Trax Audit' ],
229
+ description: `Get overall high level audited files count splitup`,
230
+ operationId: 'metrics/summary-split-up',
231
+ parameters: {},
232
+ requestBody: {
233
+ content: {
234
+ 'application/json': {
235
+ schema: j2s( summarySplitSchema ).swagger,
236
+ },
237
+ },
238
+ },
239
+ responses: {
240
+ 200: { description: 'Successful' },
241
+ 401: { description: 'Unauthorized User' },
242
+ 422: { description: 'Field Error' },
243
+ 500: { description: 'Server Error' },
244
+ 204: { description: 'Not Found' },
245
+ },
246
+ },
247
+ },
248
+
249
+ '/v3/trax-audit/metrics/overview-table': {
250
+ post: {
251
+ tags: [ 'Trax Audit' ],
252
+ description: `Get overall user taken data with some filters `,
253
+ operationId: 'metrics/overview-table',
254
+ parameters: {},
255
+ requestBody: {
256
+ content: {
257
+ 'application/json': {
258
+ schema: j2s( overviewTableSchema ).swagger,
259
+ },
260
+ },
261
+ },
262
+ responses: {
263
+ 200: { description: 'Successful' },
264
+ 401: { description: 'Unauthorized User' },
265
+ 422: { description: 'Field Error' },
266
+ 500: { description: 'Server Error' },
267
+ 204: { description: 'Not Found' },
268
+ },
269
+ },
270
+ },
203
271
  };
@@ -148,7 +148,7 @@ export const userAuditHistorySchema = joi.object(
148
148
  dateType: joi.string().required(),
149
149
  clientId: joi.array().optional(),
150
150
  filterByStoreId: joi.array().required(),
151
- filterByModuleType: joi.array().optional(),
151
+ moduleType: joi.string().required(),
152
152
  filterByAuditType: joi.array().optional(),
153
153
  filterByStatus: joi.array().optional(),
154
154
  searchValue: joi.string().optional().allow( '' ),
@@ -170,7 +170,7 @@ export const clientMetricsSchema = joi.object(
170
170
  fromDate: joi.string().required(),
171
171
  toDate: joi.string().required(),
172
172
  searchValue: joi.string().optional().allow( '' ),
173
- filterByModuleType: joi.array().optional(),
173
+ moduleType: joi.string().required(),
174
174
  filterByClient: joi.array().required(),
175
175
  filterByStatus: joi.array().optional(),
176
176
  sortColumnName: joi.string().optional(),
@@ -195,7 +195,7 @@ export const storeMetricsSchema = joi.object(
195
195
  filterByStoreId: joi.array().optional(),
196
196
  filterByStatus: joi.array().optional(),
197
197
  filterByAuditType: joi.array().optional(),
198
- filterByModuleType: joi.array().optional(),
198
+ moduleType: joi.string().required(),
199
199
  sortColumnName: joi.string().optional(),
200
200
  sortBy: joi.number().optional(),
201
201
  limit: joi.number().optional(),
@@ -215,7 +215,7 @@ export const userMetricsSchema = joi.object(
215
215
  dateType: joi.string().required(),
216
216
  searchValue: joi.string().optional().allow( '' ),
217
217
  filterByUser: joi.array().optional(),
218
- filterByModuleType: joi.array().optional(),
218
+ moduleType: joi.string().required(),
219
219
  filterByStatus: joi.array().optional(),
220
220
  sortColumnName: joi.string().optional(),
221
221
  sortBy: joi.number().optional(),
@@ -238,7 +238,7 @@ export const pendingSummaryTableSchema = joi.object(
238
238
  offset: joi.number().optional(),
239
239
  searchValue: joi.string().optional().allow( '' ),
240
240
  filterByStatus: joi.array().required(),
241
- filterByModuleType: joi.array().optional(),
241
+ moduleType: joi.string().required(),
242
242
  filterByAuditType: joi.array().optional(),
243
243
  sortColumnName: joi.string().optional(),
244
244
  sortBy: joi.number().optional(),
@@ -259,7 +259,7 @@ export const overviewTableSchema = joi.object(
259
259
  offset: joi.number().optional(),
260
260
  searchValue: joi.string().optional().allow( '' ),
261
261
  filterByStatus: joi.array().optional(),
262
- filterByModuleType: joi.array().optional(),
262
+ moduleType: joi.string().required(),
263
263
  filterByAuditType: joi.array().optional(),
264
264
  sortColumnName: joi.string().optional(),
265
265
  sortBy: joi.number().optional(),
@@ -276,7 +276,7 @@ export const overAllAuditSummarySchema = joi.object(
276
276
  fromDate: joi.string().required(),
277
277
  toDate: joi.string().required(),
278
278
  clientId: joi.array().optional(),
279
- moduleType: joi.array().required(),
279
+ moduleType: joi.string().required(),
280
280
  },
281
281
  );
282
282
 
@@ -319,7 +319,7 @@ export const summarySplitSchema = joi.object(
319
319
  fromDate: joi.string().required(),
320
320
  toDate: joi.string().required(),
321
321
  clientId: joi.array().optional(),
322
- moduleType: joi.array().optional(),
322
+ moduleType: joi.string().required(),
323
323
  },
324
324
  );
325
325
 
@@ -218,3 +218,37 @@ export const overAllAuditSummarySchema = joi.object(
218
218
  export const overAllAuditSummaryValid = {
219
219
  body: overAllAuditSummarySchema,
220
220
  };
221
+
222
+ export const summarySplitSchema = joi.object(
223
+ {
224
+ fromDate: joi.string().required(),
225
+ toDate: joi.string().required(),
226
+ clientId: joi.array().optional(),
227
+ moduleType: joi.string().optional(),
228
+ },
229
+ );
230
+
231
+ export const summarySplitValid = {
232
+ body: summarySplitSchema,
233
+ };
234
+
235
+ export const overviewTableSchema = joi.object(
236
+ {
237
+ fromDate: joi.string().required(),
238
+ toDate: joi.string().required(),
239
+ clientId: joi.array().optional(),
240
+ limit: joi.number().optional(),
241
+ offset: joi.number().optional(),
242
+ searchValue: joi.string().optional().allow( '' ),
243
+ filterByStatus: joi.array().optional(),
244
+ moduleType: joi.string().optional(),
245
+ filterByAuditType: joi.array().optional(),
246
+ sortColumnName: joi.string().optional(),
247
+ sortBy: joi.number().optional(),
248
+ isExport: joi.boolean().optional(),
249
+ },
250
+ );
251
+
252
+ export const overviewTableValid= {
253
+ body: overviewTableSchema,
254
+ };
@@ -1,8 +1,8 @@
1
1
  import { Router } from 'express';
2
2
  import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
3
- import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid } from '../dtos/traxAudit.dtos.js';
3
+ import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid, summarySplitValid, overviewTableValid } from '../dtos/traxAudit.dtos.js';
4
4
  import { isExistsQueue } from '../validation/audit.validation.js';
5
- import { clientMetrics, getAuditFile, getDetectionAuditFile, overAllAuditSummary, pendingSummaryTable, saveBinary, storeMetrics, userAuditHistory, userMetrics, workSpace } from '../controllers/traxAudit.controllers.js';
5
+ import { clientMetrics, getAuditFile, getDetectionAuditFile, overAllAuditSummary, overviewTable, pendingSummaryTable, saveBinary, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace } from '../controllers/traxAudit.controllers.js';
6
6
  import { validateBinaryAudit } from '../validation/traxAuditValidation.js';
7
7
 
8
8
  export const traxAuditRouter = Router();
@@ -28,4 +28,9 @@ traxAuditRouter.post( '/metrics/user-metrics', isAllowedSessionHandler, validate
28
28
  traxAuditRouter.post( '/metrics/pending-summary-table', isAllowedSessionHandler, validate( pendingSummaryTableValid ), pendingSummaryTable );
29
29
  traxAuditRouter.post( '/metrics/overall-audit-summary', isAllowedSessionHandler, validate( overAllAuditSummaryValid ), overAllAuditSummary );
30
30
 
31
+ // summary
32
+
33
+ traxAuditRouter.post( '/metrics/summary-split-up', isAllowedSessionHandler, validate( summarySplitValid ), summarySplit );
34
+ traxAuditRouter.post( '/metrics/overview-table', isAllowedSessionHandler, validate( overviewTableValid ), overviewTable );
35
+
31
36
  export default traxAuditRouter;