tango-app-api-audit 3.4.0-alpha.11 → 3.4.0-alpha.12

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.11",
3
+ "version": "3.4.0-alpha.12",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -58,6 +58,8 @@ import {
58
58
  aggregateAuditStoreData,
59
59
  findOneStoreData,
60
60
  } from '../service/auditStoreData.service.js';
61
+ import { aggregateStoreEmpDetection } from '../service/storeEmpDetection.service.js';
62
+ import { aggregateBinaryAudit } from '../service/binaryAudit.service.js';
61
63
 
62
64
  /* < -- *** Configuration *** --> */
63
65
 
@@ -2989,15 +2991,87 @@ export async function overViewCard( req, res ) {
2989
2991
  },
2990
2992
  },
2991
2993
  ];
2994
+
2995
+ const binaryQuery =[
2996
+ {
2997
+ $match: {
2998
+ $and: filters,
2999
+ },
3000
+
3001
+ },
3002
+ {
3003
+ $project: {
3004
+ auditFileCount: {
3005
+ $cond: [
3006
+ { $eq: [ '$auditType', 'Audit' ] }, 1, 0,
3007
+ ],
3008
+ },
3009
+ ReAuditFileCount: {
3010
+ $cond: [
3011
+ { $eq: [ '$auditType', 'ReAudit' ] }, 1, 0,
3012
+ ],
3013
+ },
3014
+ inprogressCount: {
3015
+ $cond: [
3016
+ { $ne: [ '$auditStatus', 'completed' ] }, 1, 0,
3017
+ ],
3018
+ },
3019
+ completedCount: {
3020
+ $cond: [
3021
+ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0,
3022
+ ],
3023
+ },
3024
+ },
3025
+ },
3026
+ {
3027
+ $group: {
3028
+ _id: { fileDate: '$fileDate', clientId: '$clientId' },
3029
+ totalCount: { $sum: 1 },
3030
+ auditFileCount: { $sum: '$auditFileCount' },
3031
+ ReAuditFileCount: { $sum: '$ReAuditFileCount' },
3032
+ inprogressCount: { $sum: '$inprogressCount' },
3033
+ completedCount: { $sum: '$completedCount' },
3034
+
3035
+ },
3036
+ },
3037
+ {
3038
+ $project: {
3039
+ _id: 0,
3040
+ totalCount: 1,
3041
+ auditFileCount: 1,
3042
+ ReAuditFileCount: 1,
3043
+ inprogressCount: 1,
3044
+ completedCount: 1,
3045
+ notAssigned: { $subtract: [ '$totalCount', { $add: [ '$inprogressCount', '$completedCount' ] } ] },
3046
+ },
3047
+ },
3048
+ ];
2992
3049
  const result = await aggregateStoreAudit( query );
2993
- logger.info( { result: result } );
2994
- return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
3050
+ const empDetection = await aggregateStoreEmpDetection( query );
3051
+ const binaryAudit = await aggregateBinaryAudit( binaryQuery );
3052
+
3053
+ // Combine all arrays into one
3054
+ const combinedArray = [ ...result, ...empDetection, ...binaryAudit ];
3055
+
3056
+ // Function to merge objects by summing their values
3057
+ const mergedResult = mergeAndSum( combinedArray );
3058
+
3059
+ return res.sendSuccess( { result: Object.keys( mergedResult ).length > 0?mergedResult: temp } );
2995
3060
  } catch ( error ) {
2996
3061
  const err = error.message || 'Internal Server Error';
2997
3062
  logger.error( { error: error, message: req.body, function: 'overViewCard' } );
2998
3063
  return res.sendError( err, 500 );
2999
3064
  }
3000
3065
  }
3066
+ export const mergeAndSum = ( arr ) => {
3067
+ return arr.reduce( ( acc, obj ) => {
3068
+ for ( const [ key, value ] of Object.entries( obj ) ) {
3069
+ // Add the value to the existing key or initialize it if it doesn't exist
3070
+ acc[key] = ( acc[key] || 0 ) + value;
3071
+ }
3072
+ return acc;
3073
+ }, {} );
3074
+ };
3001
3075
 
3002
3076
  export async function summarySplit( req, res ) {
3003
3077
  try {