tango-app-api-audit 3.4.0-alpha.13 → 3.4.0-alpha.15

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.13",
3
+ "version": "3.4.0-alpha.15",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -619,6 +619,48 @@ export async function workSpace( req, res ) {
619
619
  },
620
620
  ];
621
621
 
622
+ const binarCompletedStores = [
623
+ {
624
+ $match: {
625
+ $and: [
626
+ { clientId: { $in: clientList } },
627
+ { fileDate: { $eq: latestDate } },
628
+ { moduleType: { $eq: inputData.moduleType } },
629
+ ],
630
+ },
631
+ },
632
+ {
633
+ $project: {
634
+ clientId: 1,
635
+ completed: {
636
+ $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ],
637
+ },
638
+ },
639
+ },
640
+ // {
641
+ // $group: {
642
+ // _id: { clientId: '$clientId', storeId: '$storeId' },
643
+ // clientId: { $first: '$clientId' },
644
+ // completedStoresCount: { $sum: '$completed' },
645
+ // },
646
+ // },
647
+ {
648
+ $group: {
649
+ _id: '$clientId',
650
+ clientId: { $first: '$clientId' },
651
+ // completedStoresCount: { $first: '$completedStoresCount' },
652
+ completedStoresCount: { $sum: '$completed' },
653
+ },
654
+ },
655
+ {
656
+ $project: {
657
+ _id: 0,
658
+ clientId: 1,
659
+ completedStoresCount: 1,
660
+ },
661
+ },
662
+ ];
663
+
622
664
  const auditFiles = [
623
665
  {
624
666
  $match: {
@@ -754,7 +796,7 @@ export async function workSpace( req, res ) {
754
796
  const auditUserCount = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateUserEmpDetection( auditFiles ) : await aggregateBinaryAudit( auditFiles );
755
797
  const userIncompleteFilesCount = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateUserEmpDetection( userIncompleteFiles ) : await aggregateBinaryAudit( userIncompleteFiles );
756
798
  const userAsignAuditCount = await aggregateAssignAudit( userAsignAudit );
757
- const completedStoresCount = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )? await aggregateStoreEmpDetection( completedStores ) : await aggregateBinaryAudit( completedStores );
799
+ const completedStoresCount = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )? await aggregateStoreEmpDetection( completedStores ) : await aggregateBinaryAudit( binarCompletedStores );
758
800
  const clientAssignedCount = await aggregateAssignAudit( clientAssign );
759
801
  const auditStoreData = await aggregateTraxAuditData(
760
802
  auditStoreDataQuery,
@@ -1959,6 +2001,189 @@ export async function storeMetrics( req, res ) {
1959
2001
 
1960
2002
  ];
1961
2003
 
2004
+ const binaryQuery = [
2005
+ {
2006
+ $match: {
2007
+ $and: filter,
2008
+ },
2009
+ },
2010
+
2011
+ {
2012
+ $lookup: {
2013
+ from: 'stores',
2014
+ let: { storeId: '$storeId' },
2015
+ pipeline: [
2016
+ {
2017
+ $match: {
2018
+ $expr: {
2019
+ $eq: [ '$storeId', '$$storeId' ],
2020
+ },
2021
+ },
2022
+ },
2023
+ {
2024
+ $project: {
2025
+ _id: 0,
2026
+ storeName: 1,
2027
+ },
2028
+ },
2029
+ ], as: 'stores',
2030
+ },
2031
+ },
2032
+ {
2033
+ $unwind: {
2034
+ path: '$stores',
2035
+ preserveNullAndEmptyArrays: true,
2036
+ },
2037
+ },
2038
+ {
2039
+ $project: {
2040
+ auditId: '$_id',
2041
+ _id: 0,
2042
+ fileDate: 1,
2043
+ storeId: 1,
2044
+ storeName: '$stores.storeName',
2045
+ clientName: '',
2046
+ clientId: 1,
2047
+ moduleType: 1,
2048
+ value: {
2049
+ $replaceAll: { input: '$moduleType', find: '-', replacement: ' ' },
2050
+ },
2051
+ tempId: 1,
2052
+ streamName: 1,
2053
+ question: 1,
2054
+ questionType: 1,
2055
+ answer: 1,
2056
+ // userId: {
2057
+ // $arrayElemAt: [ '$userId', { $subtract: [ { $size: '$userId' }, 1 ] } ], //need to check if no data
2058
+ // },
2059
+ userId: 1,
2060
+ auditType: 1,
2061
+ beforeCount: 1,
2062
+ afterCount: { $ifNull: [ '$afterCount', null ] },
2063
+ accuracy: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, { $round: [
2064
+ {
2065
+ $multiply: [ { $divide: [ '$afterCount', '$beforeCount' ] }, 100 ],
2066
+ }, 1,
2067
+ ],
2068
+ }, null ] },
2069
+ timeSpent: 1,
2070
+ status: 1,
2071
+ auditStatus: 1,
2072
+ },
2073
+ },
2074
+ {
2075
+ $lookup: {
2076
+ from: 'users',
2077
+ let: { userId: '$userId' },
2078
+ pipeline: [
2079
+ {
2080
+ $match: {
2081
+ $expr: {
2082
+ $eq: [ '$_id', '$$userId' ],
2083
+ },
2084
+ },
2085
+ },
2086
+ {
2087
+ $project: {
2088
+ _id: 0,
2089
+ userName: 1,
2090
+ userEmail: '$email',
2091
+ },
2092
+ },
2093
+ ], as: 'users',
2094
+ },
2095
+ },
2096
+ {
2097
+ $unwind: {
2098
+ path: '$users',
2099
+ preserveNullAndEmptyArrays: true,
2100
+ },
2101
+ },
2102
+ {
2103
+ $lookup: {
2104
+ from: 'clients',
2105
+ let: { clientId: '$clientId' },
2106
+ pipeline: [
2107
+ {
2108
+ $match: {
2109
+ $expr: {
2110
+ $eq: [ '$clientId', '$$clientId' ],
2111
+ },
2112
+ },
2113
+ },
2114
+ {
2115
+ $project: {
2116
+ _id: 0,
2117
+ clientName: 1,
2118
+ },
2119
+ },
2120
+ ], as: 'client',
2121
+ },
2122
+ },
2123
+ {
2124
+ $unwind: {
2125
+ path: '$client',
2126
+ preserveNullAndEmptyArrays: true,
2127
+ },
2128
+ },
2129
+ {
2130
+ $project: {
2131
+ auditId: 1,
2132
+ fileDate: 1,
2133
+ storeId: 1,
2134
+ storeName: 1,
2135
+ userName: '$users.userName',
2136
+ userEmail: '$users.userEmail',
2137
+ clientId: 1,
2138
+ clientName: '$client.clientName',
2139
+ tempId: 1,
2140
+ streamName: 1,
2141
+ question: 1,
2142
+ questionType: 1,
2143
+ answer: 1,
2144
+ moduleType: 1,
2145
+ value: 1,
2146
+ auditType: 1,
2147
+ beforeCount: 1,
2148
+ afterCount: { $ifNull: [ '$afterCount', null ] },
2149
+ accuracy: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, { $round: [
2150
+ {
2151
+ $multiply: [ { $divide: [ '$afterCount', '$beforeCount' ] }, 100 ],
2152
+ }, 1,
2153
+ ],
2154
+ }, null ] },
2155
+ timeSpent: {
2156
+
2157
+ $cond: [
2158
+ { $lt: [ '$timeSpent', 60 ] }, // Case 1: If less than 60 seconds
2159
+ { $concat: [ { $toString: '$timeSpent' }, ' sec' ] },
2160
+ {
2161
+ $cond: [
2162
+ { $lt: [ '$timeSpent', 3600 ] }, // Case 2: If less than 60 minutes (3600 seconds)
2163
+ {
2164
+ $concat: [
2165
+ { $toString: { $round: [ { $divide: [ '$timeSpent', 60 ] }, 1 ] } }, // Convert to minutes
2166
+ ' min',
2167
+ ],
2168
+ },
2169
+ {
2170
+ $concat: [
2171
+ { $toString: { $round: [ { $divide: [ '$timeSpent', 3600 ] }, 1 ] } }, // Convert to hours
2172
+ ' hr',
2173
+ ],
2174
+ },
2175
+ ],
2176
+ },
2177
+ ],
2178
+
2179
+ },
2180
+ status: 1,
2181
+ auditStatus: 1,
2182
+ },
2183
+ },
2184
+
2185
+ ];
2186
+
1962
2187
  if ( inputData.searchValue && inputData.searchValue !== '' ) {
1963
2188
  query.push( {
1964
2189
  $match: {
@@ -1988,7 +2213,7 @@ export async function storeMetrics( req, res ) {
1988
2213
  },
1989
2214
  );
1990
2215
  }
1991
- const count = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
2216
+ const count = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
1992
2217
 
1993
2218
  if ( count.length == 0 ) {
1994
2219
  return res.sendError( 'No data Found', 204 );
@@ -2107,11 +2332,10 @@ export async function userMetrics( req, res ) {
2107
2332
  userId: 1,
2108
2333
  fileDate: 1,
2109
2334
  startTime: 1,
2335
+ endTime: 1,
2110
2336
  beforeCount: 1,
2111
2337
  moduleType: 1,
2112
2338
  afterCount: 1,
2113
- checkIntime: 1,
2114
- checkOutTime: 1,
2115
2339
  totalCompletedFiles: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ] },
2116
2340
  beforeCount: 1,
2117
2341
  afterCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$afterCount', 0 ] },
@@ -2524,8 +2748,6 @@ export async function pendingSummaryTable( req, res ) {
2524
2748
  result.forEach( ( element ) => {
2525
2749
  const temp = {
2526
2750
  'Store ID': element.storeId,
2527
- 'Result': element.answer,
2528
- 'userComments': element.userComments,
2529
2751
  'File Date': element.fileDate,
2530
2752
  'Product Type': element.value,
2531
2753
  'Audit Type': element.auditType,
@@ -2537,16 +2759,13 @@ export async function pendingSummaryTable( req, res ) {
2537
2759
  switch ( inputData.moduleType ) {
2538
2760
  case 'camera-angle-change':
2539
2761
  temp['stream Name'] = element.streamName;
2540
- temp['User Comments'] = element.userCommands;
2541
2762
  break;
2542
2763
  case 'unattended-customer':
2543
2764
  temp['Customer ID'] = element.tempId;
2544
2765
  temp['Question'] = element.question;
2545
- temp['User Comments'] = element.userCommands;
2546
2766
  break;
2547
2767
  case 'left-in-middle':
2548
2768
  temp['Question'] = element.question;
2549
- temp['User Comments'] = element.userCommands;
2550
2769
  break;
2551
2770
  case 'mobile-detection':
2552
2771
  temp['Before Count'] = element.beforeCount;
@@ -2669,7 +2888,57 @@ export async function overAllAuditSummary( req, res ) {
2669
2888
  },
2670
2889
  },
2671
2890
  ];
2672
- const storeAudit = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( storeAuditQuery );
2891
+
2892
+ const binaryAuditQuery =[
2893
+ {
2894
+ $match: {
2895
+ $and: filters,
2896
+ },
2897
+
2898
+ },
2899
+ {
2900
+ $project: {
2901
+ completedStores: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ] },
2902
+ auditInprogress: { $cond: [ { $and: [ { $in: [ '$auditStatus', [ 'inprogress' ] ] }, { $eq: [ '$auditType', 'Audit' ] } ] }, 1, 0 ] },
2903
+ reAuditInprogress: { $cond: [ { $and: [ { $in: [ '$auditStatus', [ 'inprogress' ] ] }, { $eq: [ '$auditType', 'ReAudit' ] } ] }, 1, 0 ] },
2904
+ draft: { $cond: [ { $eq: [ '$auditStatus', 'drafted' ] }, 1, 0 ] },
2905
+ assigned: { $cond: [ { $eq: [ '$auditStatus', 'assigned' ] }, 1, 0 ] },
2906
+ exceptNoAssigned: { $cond: { if: { $not: { $in: [ '$auditStatus', [ 'skipped', 'not_assign' ] ] } }, then: 1, else: 0 } },
2907
+ auditCompleted: { $cond: [ { $and: [ { $in: [ '$auditStatus', [ 'completed' ] ] }, { $eq: [ '$auditType', 'Audit' ] } ] }, 1, 0 ] },
2908
+ reAuditCompleted: { $cond: [ { $and: [ { $in: [ '$auditStatus', [ 'completed' ] ] }, { $eq: [ '$auditType', 'ReAudit' ] } ] }, 1, 0 ] },
2909
+
2910
+
2911
+ },
2912
+ },
2913
+ {
2914
+ $group: {
2915
+ _id: null,
2916
+ completedStores: { $sum: '$completedStores' },
2917
+ auditInprogress: { $sum: '$auditInprogress' },
2918
+ reAuditInprogress: { $sum: '$reAuditInprogress' },
2919
+ draft: { $sum: '$draft' },
2920
+ assigned: { $sum: '$assigned' },
2921
+ exceptNoAssigned: { $sum: '$exceptNoAssigned' },
2922
+ auditCompleted: { $sum: '$auditCompleted' },
2923
+ reAuditCompleted: { $sum: '$reAuditCompleted' },
2924
+ },
2925
+ },
2926
+ {
2927
+ $project: {
2928
+ completedStores: 1,
2929
+ inprogressStores: { $subtract: [ temp.auditStores, '$completedStores' ] },
2930
+ auditInprogress: 1,
2931
+ reAuditInprogress: 1,
2932
+ draft: 1,
2933
+ assigned: 1,
2934
+ exceptNoAssigned: { $subtract: [ temp.auditStores, '$exceptNoAssigned' ] },
2935
+ auditCompleted: 1,
2936
+ reAuditCompleted: 1,
2937
+ },
2938
+ },
2939
+ ];
2940
+
2941
+ const storeAudit = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( binaryAuditQuery );
2673
2942
  if ( storeAudit.length > 0 ) {
2674
2943
  temp.inprogressStores= storeAudit[0].inprogressStores;
2675
2944
  temp.completedStores = storeAudit[0].completedStores;