tango-app-api-audit 3.4.3-alpha.7 → 3.4.3-alpha.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.3-alpha.7",
3
+ "version": "3.4.3-alpha.8",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1922,6 +1922,125 @@ export async function clientMetrics( req, res ) {
1922
1922
  },
1923
1923
  ];
1924
1924
 
1925
+ const MappingQuery =[
1926
+ {
1927
+ $match: {
1928
+ $and: filter,
1929
+ },
1930
+ },
1931
+ {
1932
+ $group: {
1933
+ _id: { clientId: '$clientId', fileDate: '$fileDate', moduleType: '$moduleType' },
1934
+ fileDate: { $last: '$fileDate' },
1935
+ clientId: { $last: '$clientId' },
1936
+ clientName: { $last: '$clientName' },
1937
+ moduleType: { $last: '$moduleType' },
1938
+ installedStore: { $last: '$installedStore' },
1939
+ queueName: { $last: '$queueName' },
1940
+ totalFilesCount: { $sum: 1 },
1941
+ },
1942
+ },
1943
+ {
1944
+ $project: {
1945
+ fileDate: 1,
1946
+ clientId: 1,
1947
+ clientName: 1,
1948
+ queueName: 1,
1949
+ installedStore: 1,
1950
+ totalFilesCount: 1,
1951
+ moduleType: 1,
1952
+ notAssignedCount: { $ifNull: [ 0, 0 ] },
1953
+ clientStatus: { $ifNull: [ '', '' ] },
1954
+ },
1955
+ },
1956
+ {
1957
+ $lookup: {
1958
+ 'from': 'storeEmpDetection',
1959
+ 'let': { clientId: '$clientId', fileDate: '$fileDate', totalAuditFiles: '$totalFilesCount' },
1960
+ 'pipeline': [
1961
+
1962
+ {
1963
+ $match: {
1964
+ $expr: {
1965
+ $and: storeAuditFilter,
1966
+ },
1967
+ },
1968
+ },
1969
+ {
1970
+ $project: {
1971
+ completedStores: { $cond: [ { $eq: [ '$status', 'completed' ] }, 1, 0 ] },
1972
+ notAssignedStores: { $cond: [ { $eq: [ '$status', 'not_assign' ] }, 1, 0 ] },
1973
+ inprogressStores: { $cond: [ { $in: [ '$status', [ 'inprogress', 'drafted', 'assigned' ] ] }, 1, 0 ] },
1974
+ },
1975
+ },
1976
+ {
1977
+ $group: {
1978
+ _id: { clientId: '$clientId', fileDate: '$fileDate' },
1979
+ completedStores: { $sum: '$completedStores' },
1980
+ inprogressStores: { $sum: '$inprogressStores' },
1981
+ notAssignedStores: { $sum: '$notAssignedStores' },
1982
+ fileCount: { $sum: 1 },
1983
+ },
1984
+ },
1985
+ {
1986
+ $project: {
1987
+ _id: 0,
1988
+ completedStores: 1,
1989
+ inprogressStores: 1,
1990
+ notAssignedStores: 1,
1991
+ fileCount: { $ifNull: [ '$fileCount', 0 ] },
1992
+ completionPercentage: { $ifNull: [
1993
+ {
1994
+ $round: [ {
1995
+ $multiply: [
1996
+ 100, {
1997
+ $divide: [
1998
+ '$completedStores', '$$totalAuditFiles',
1999
+ ],
2000
+ },
2001
+ ],
2002
+ }, 1 ],
2003
+
2004
+ },
2005
+ 0,
2006
+ ],
2007
+ },
2008
+ },
2009
+ },
2010
+ ], 'as': 'binaryAudit',
2011
+ },
2012
+ },
2013
+ {
2014
+ $unwind: {
2015
+ path: '$binaryAudit',
2016
+ preserveNullAndEmptyArrays: true,
2017
+ },
2018
+ },
2019
+ {
2020
+ $project: {
2021
+ _id: 0,
2022
+ fileDate: 1,
2023
+ clientId: 1,
2024
+ clientName: 1,
2025
+ totalFilesCount: 1,
2026
+ moduleType: 1,
2027
+ value: {
2028
+ $replaceAll: { input: '$moduleType', find: '-', replacement: ' ' }, // Replacing "-" with " "
2029
+ },
2030
+ installedStore: 1,
2031
+ // notAssignedStores: '$binaryAudit.notAssignedStores',
2032
+ inprogressStoresCount: '$binaryAudit.inprogressStores',
2033
+ // fileCount: '$binaryAudit.fileCount',
2034
+ notAssignedCount: { $subtract: [ '$totalFilesCount', { $subtract: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, { $ifNull: [ '$binaryAudit.notAssignedStores', 0 ] } ] } ] },
2035
+ clientStatus: { $cond: [ { $eq: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, 0 ] }, 'not-taken', { $cond: [ { $gte: [ '$binaryAudit.completedStores', '$totalFilesCount' ] }, 'completed', 'pending' ] } ] }, // { $cond: [ { $or: [ { $gt: [ '$notAssignedCount', 0 ] }, { $gt: [ '$binaryAudit.notAssignedStores', 0 ] } ] }
2036
+ completedStores: '$binaryAudit.completedStores',
2037
+ completionPercentage: '$binaryAudit.completionPercentage',
2038
+
2039
+ },
2040
+ },
2041
+ ];
2042
+
2043
+
1925
2044
  if ( inputData?.filterByStatus?.length> 0 ) {
1926
2045
  query.push(
1927
2046
  {
@@ -1953,7 +2072,7 @@ export async function clientMetrics( req, res ) {
1953
2072
  );
1954
2073
  }
1955
2074
 
1956
- const count = await aggregateTraxAuditData( query );
2075
+ const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
1957
2076
  logger.info( { count: count } );
1958
2077
  if ( count.length == 0 ) {
1959
2078
  return res.sendError( 'No Data Found', 204 );
@@ -1986,7 +2105,7 @@ export async function clientMetrics( req, res ) {
1986
2105
  }
1987
2106
 
1988
2107
  logger.info( { query: query } );
1989
- const result = await aggregateTraxAuditData( query );
2108
+ const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
1990
2109
  if ( result.length == 0 ) {
1991
2110
  return res.sendError( 'No Data Found', 204 );
1992
2111
  }
@@ -2429,8 +2548,10 @@ export async function storeMetrics( req, res ) {
2429
2548
  },
2430
2549
  );
2431
2550
  }
2551
+ logger.info( { keyss: [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType ) } );
2432
2552
  const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
2433
2553
 
2554
+
2434
2555
  if ( count.length == 0 ) {
2435
2556
  return res.sendError( 'No data Found', 204 );
2436
2557
  }
@@ -2444,7 +2565,7 @@ export async function storeMetrics( req, res ) {
2444
2565
  } else {
2445
2566
  query.push( { $limit: 10000 } );
2446
2567
  }
2447
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
2568
+ const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
2448
2569
  if ( inputData.isExport ) {
2449
2570
  const exportdata = [];
2450
2571
  result.forEach( ( element ) => {
@@ -3280,7 +3401,7 @@ export async function summarySplit( req, res ) {
3280
3401
  },
3281
3402
  },
3282
3403
  ];
3283
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3404
+ const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
3284
3405
  const totalCount = await aggregateTraxAuditData( totalQuery );
3285
3406
  result[0].totalCount = totalCount[0]?.total;
3286
3407
  return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
@@ -4078,11 +4199,6 @@ export async function reTrigger( req, res ) {
4078
4199
  const inputData = req.body;
4079
4200
  const message = req.sqs;
4080
4201
  const sqs = JSON.parse( process.env.SQS );
4081
- const query = {
4082
- storeId: inputData.storeId,
4083
- fileDate: inputData.fileDate,
4084
- moduleType: inputData.moduleType,
4085
- };
4086
4202
  const getQueueName = await findOneClient( { clientId: req.audit.clientId }, { 'auditConfigs': 1 } );
4087
4203
  const queueName = inputData.moduleType == 'uniform-detection' ? getQueueName?.auditConfigs?.traxQueueName?.uniformDetection : getQueueName?.auditConfigs?.traxQueueName?.mobileDetection;
4088
4204
  if ( !getQueueName || queueName == '' ) {
@@ -4117,16 +4233,24 @@ export async function reTrigger( req, res ) {
4117
4233
  storeId: inputData.storeId,
4118
4234
  fileDate: inputData.fileDate,
4119
4235
  auditStatus: req.audit.status,
4236
+ moduleType: inputData.moduleType,
4120
4237
 
4121
4238
  };
4122
4239
  await updateOneUserEmpDetection( query, userRecord );
4123
4240
  }
4124
4241
 
4242
+ const storeQuery = {
4243
+ storeId: inputData.storeId,
4244
+ fileDate: inputData.fileDate,
4245
+ moduleType: inputData.moduleType,
4246
+
4247
+ };
4248
+
4125
4249
  const storeRecord = {
4126
4250
  status: 'not_assign',
4127
4251
  };
4128
4252
 
4129
- await updateOneStoreEmpDetection( query, storeRecord );
4253
+ await updateOneStoreEmpDetection( storeQuery, storeRecord );
4130
4254
  const logData = {
4131
4255
  userId: req.user._id,
4132
4256
  userName: req.user.userName,