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

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.14",
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 );
@@ -2669,7 +2894,57 @@ export async function overAllAuditSummary( req, res ) {
2669
2894
  },
2670
2895
  },
2671
2896
  ];
2672
- const storeAudit = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( storeAuditQuery );
2897
+
2898
+ const binaryAuditQuery =[
2899
+ {
2900
+ $match: {
2901
+ $and: filters,
2902
+ },
2903
+
2904
+ },
2905
+ {
2906
+ $project: {
2907
+ completedStores: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ] },
2908
+ auditInprogress: { $cond: [ { $and: [ { $in: [ '$auditStatus', [ 'inprogress' ] ] }, { $eq: [ '$auditType', 'Audit' ] } ] }, 1, 0 ] },
2909
+ reAuditInprogress: { $cond: [ { $and: [ { $in: [ '$auditStatus', [ 'inprogress' ] ] }, { $eq: [ '$auditType', 'ReAudit' ] } ] }, 1, 0 ] },
2910
+ draft: { $cond: [ { $eq: [ '$auditStatus', 'drafted' ] }, 1, 0 ] },
2911
+ assigned: { $cond: [ { $eq: [ '$auditStatus', 'assigned' ] }, 1, 0 ] },
2912
+ exceptNoAssigned: { $cond: { if: { $not: { $in: [ '$auditStatus', [ 'skipped', 'not_assign' ] ] } }, then: 1, else: 0 } },
2913
+ auditCompleted: { $cond: [ { $and: [ { $in: [ '$auditStatus', [ 'completed' ] ] }, { $eq: [ '$auditType', 'Audit' ] } ] }, 1, 0 ] },
2914
+ reAuditCompleted: { $cond: [ { $and: [ { $in: [ '$auditStatus', [ 'completed' ] ] }, { $eq: [ '$auditType', 'ReAudit' ] } ] }, 1, 0 ] },
2915
+
2916
+
2917
+ },
2918
+ },
2919
+ {
2920
+ $group: {
2921
+ _id: null,
2922
+ completedStores: { $sum: '$completedStores' },
2923
+ auditInprogress: { $sum: '$auditInprogress' },
2924
+ reAuditInprogress: { $sum: '$reAuditInprogress' },
2925
+ draft: { $sum: '$draft' },
2926
+ assigned: { $sum: '$assigned' },
2927
+ exceptNoAssigned: { $sum: '$exceptNoAssigned' },
2928
+ auditCompleted: { $sum: '$auditCompleted' },
2929
+ reAuditCompleted: { $sum: '$reAuditCompleted' },
2930
+ },
2931
+ },
2932
+ {
2933
+ $project: {
2934
+ completedStores: 1,
2935
+ inprogressStores: { $subtract: [ temp.auditStores, '$completedStores' ] },
2936
+ auditInprogress: 1,
2937
+ reAuditInprogress: 1,
2938
+ draft: 1,
2939
+ assigned: 1,
2940
+ exceptNoAssigned: { $subtract: [ temp.auditStores, '$exceptNoAssigned' ] },
2941
+ auditCompleted: 1,
2942
+ reAuditCompleted: 1,
2943
+ },
2944
+ },
2945
+ ];
2946
+
2947
+ const storeAudit = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( binaryAuditQuery );
2673
2948
  if ( storeAudit.length > 0 ) {
2674
2949
  temp.inprogressStores= storeAudit[0].inprogressStores;
2675
2950
  temp.completedStores = storeAudit[0].completedStores;