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

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.13",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -58,6 +58,9 @@ 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';
63
+ import { aggregateTraxAuditData, findOneTraxAuditData } from '../service/traxAuditData.service.js';
61
64
 
62
65
  /* < -- *** Configuration *** --> */
63
66
 
@@ -2989,15 +2992,87 @@ export async function overViewCard( req, res ) {
2989
2992
  },
2990
2993
  },
2991
2994
  ];
2995
+
2996
+ const binaryQuery =[
2997
+ {
2998
+ $match: {
2999
+ $and: filters,
3000
+ },
3001
+
3002
+ },
3003
+ {
3004
+ $project: {
3005
+ auditFileCount: {
3006
+ $cond: [
3007
+ { $eq: [ '$auditType', 'Audit' ] }, 1, 0,
3008
+ ],
3009
+ },
3010
+ ReAuditFileCount: {
3011
+ $cond: [
3012
+ { $eq: [ '$auditType', 'ReAudit' ] }, 1, 0,
3013
+ ],
3014
+ },
3015
+ inprogressCount: {
3016
+ $cond: [
3017
+ { $ne: [ '$auditStatus', 'completed' ] }, 1, 0,
3018
+ ],
3019
+ },
3020
+ completedCount: {
3021
+ $cond: [
3022
+ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0,
3023
+ ],
3024
+ },
3025
+ },
3026
+ },
3027
+ {
3028
+ $group: {
3029
+ _id: { fileDate: '$fileDate', clientId: '$clientId' },
3030
+ totalCount: { $sum: 1 },
3031
+ auditFileCount: { $sum: '$auditFileCount' },
3032
+ ReAuditFileCount: { $sum: '$ReAuditFileCount' },
3033
+ inprogressCount: { $sum: '$inprogressCount' },
3034
+ completedCount: { $sum: '$completedCount' },
3035
+
3036
+ },
3037
+ },
3038
+ {
3039
+ $project: {
3040
+ _id: 0,
3041
+ totalCount: 1,
3042
+ auditFileCount: 1,
3043
+ ReAuditFileCount: 1,
3044
+ inprogressCount: 1,
3045
+ completedCount: 1,
3046
+ notAssigned: { $subtract: [ '$totalCount', { $add: [ '$inprogressCount', '$completedCount' ] } ] },
3047
+ },
3048
+ },
3049
+ ];
2992
3050
  const result = await aggregateStoreAudit( query );
2993
- logger.info( { result: result } );
2994
- return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
3051
+ const empDetection = await aggregateStoreEmpDetection( query );
3052
+ const binaryAudit = await aggregateBinaryAudit( binaryQuery );
3053
+
3054
+ // Combine all arrays into one
3055
+ const combinedArray = [ ...result, ...empDetection, ...binaryAudit ];
3056
+
3057
+ // Function to merge objects by summing their values
3058
+ const mergedResult = mergeAndSum( combinedArray );
3059
+
3060
+ return res.sendSuccess( { result: Object.keys( mergedResult ).length > 0?mergedResult: temp } );
2995
3061
  } catch ( error ) {
2996
3062
  const err = error.message || 'Internal Server Error';
2997
3063
  logger.error( { error: error, message: req.body, function: 'overViewCard' } );
2998
3064
  return res.sendError( err, 500 );
2999
3065
  }
3000
3066
  }
3067
+ export const mergeAndSum = ( arr ) => {
3068
+ return arr.reduce( ( acc, obj ) => {
3069
+ for ( const [ key, value ] of Object.entries( obj ) ) {
3070
+ // Add the value to the existing key or initialize it if it doesn't exist
3071
+ acc[key] = ( acc[key] || 0 ) + value;
3072
+ }
3073
+ return acc;
3074
+ }, {} );
3075
+ };
3001
3076
 
3002
3077
  export async function summarySplit( req, res ) {
3003
3078
  try {
@@ -3312,6 +3387,15 @@ export async function totalNotAssignedCount( req, res ) {
3312
3387
  { createdAt: -1 },
3313
3388
  );
3314
3389
  const latestDate = getStoreData?.fileDate || dayjs( fileDate ).format( 'DD-MM-YYYY' );
3390
+
3391
+ const geTraxData = await findOneTraxAuditData(
3392
+ {},
3393
+ { fileDate: 1 },
3394
+ { createdAt: -1 },
3395
+ );
3396
+ const latestTraxDate = geTraxData?.fileDate || dayjs( fileDate ).format( 'DD-MM-YYYY' );
3397
+ logger.info( { geTraxData: geTraxData } );
3398
+
3315
3399
  const query = [
3316
3400
  {
3317
3401
  $match: {
@@ -3347,6 +3431,52 @@ export async function totalNotAssignedCount( req, res ) {
3347
3431
  },
3348
3432
  },
3349
3433
  ];
3434
+ const traxQuery = [
3435
+ {
3436
+ $match: {
3437
+ fileDate: { $eq: latestTraxDate },
3438
+ },
3439
+ },
3440
+ {
3441
+ $project: {
3442
+ totalUnattendedCustomerCount: { $cond: [
3443
+ { $eq: [ '$moduleType', 'unattended-customer' ] }, 1, 0,
3444
+ ] },
3445
+ totalLeftInMiddleCount: { $cond: [
3446
+ { $eq: [ '$moduleType', 'left-in-middle' ] }, 1, 0,
3447
+ ] },
3448
+ totalUniformDetectionCount: { $cond: [
3449
+ { $eq: [ '$moduleType', 'uniform-detection' ] }, 1, 0,
3450
+ ] },
3451
+ totalMobileDetectionCount: { $cond: [
3452
+ { $eq: [ '$moduleType', 'mobile-detection' ] }, 1, 0,
3453
+ ] },
3454
+
3455
+ },
3456
+ },
3457
+ {
3458
+ $group: {
3459
+ _id: null,
3460
+ totalTraxAuditCount: { $sum: 1 },
3461
+ totalUnattendedCustomerCount: { $sum: '$totalUnattendedCustomerCount' },
3462
+ totalLeftInMiddleCount: { $sum: '$totalLeftInMiddleCount' },
3463
+ totalUniformDetectionCount: { $sum: '$totalUniformDetectionCount' },
3464
+ totalMobileDetectionCount: { $sum: '$totalMobileDetectionCount' },
3465
+
3466
+
3467
+ },
3468
+ },
3469
+ {
3470
+ $project: {
3471
+ _id: 0,
3472
+ totalTraxAuditCount: 1,
3473
+ totalUnattendedCustomerCount: 1,
3474
+ totalLeftInMiddleCount: 1,
3475
+ totalUniformDetectionCount: 1,
3476
+ totalMobileDetectionCount: 1,
3477
+ },
3478
+ },
3479
+ ];
3350
3480
  const inprogressCount=[
3351
3481
  {
3352
3482
  $match: {
@@ -3387,13 +3517,95 @@ export async function totalNotAssignedCount( req, res ) {
3387
3517
  },
3388
3518
  },
3389
3519
  ];
3520
+ // const binaryInprogressCount=[
3521
+ // {
3522
+ // $match: {
3523
+ // fileDate: { $eq: latestDate },
3524
+ // },
3525
+ // },
3526
+ // {
3527
+ // $project: {
3528
+ // inprogressAuditCount: {
3529
+ // $cond: [
3530
+ // { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] }, 1, 0,
3531
+ // ],
3532
+ // },
3533
+ // inprogressZoneCount: { $cond: [
3534
+ // { $and: [ { $eq: [ '$moduleType', 'zone' ] }, { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] } ] }, 1, 0,
3535
+ // ] },
3536
+ // inprogressTrafficCount: { $cond: [
3537
+ // { $and: [ { $eq: [ '$moduleType', 'traffic' ] }, { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] } ] }, 1, 0,
3538
+ // ] },
3539
+
3540
+ // },
3541
+ // },
3542
+ // {
3543
+ // $group: {
3544
+ // _id: null,
3545
+ // inprogressAuditCount: { $sum: '$inprogressAuditCount' },
3546
+ // inprogressZoneCount: { $sum: '$inprogressZoneCount' },
3547
+ // inprogressTrafficCount: { $sum: '$inprogressTrafficCount' },
3548
+
3549
+ // },
3550
+ // },
3551
+ // {
3552
+ // $project: {
3553
+ // _id: 0,
3554
+ // inprogressAuditCount: { $ifNull: [ '$inprogressAuditCount', 0 ] },
3555
+ // inprogressZoneCount: { $ifNull: [ '$inprogressZoneCount', 0 ] },
3556
+ // inprogressTrafficCount: { $ifNull: [ '$inprogressTrafficCount', 0 ] },
3557
+ // },
3558
+ // },
3559
+ // ];
3560
+ // const mappingInprogressCount=[
3561
+ // {
3562
+ // $match: {
3563
+ // fileDate: { $eq: latestDate },
3564
+ // },
3565
+ // },
3566
+ // {
3567
+ // $project: {
3568
+ // inprogressAuditCount: {
3569
+ // $cond: [
3570
+ // { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] }, 1, 0,
3571
+ // ],
3572
+ // },
3573
+ // inprogressZoneCount: { $cond: [
3574
+ // { $and: [ { $eq: [ '$moduleType', 'zone' ] }, { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] } ] }, 1, 0,
3575
+ // ] },
3576
+ // inprogressTrafficCount: { $cond: [
3577
+ // { $and: [ { $eq: [ '$moduleType', 'traffic' ] }, { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] } ] }, 1, 0,
3578
+ // ] },
3579
+
3580
+ // },
3581
+ // },
3582
+ // {
3583
+ // $group: {
3584
+ // _id: null,
3585
+ // inprogressAuditCount: { $sum: '$inprogressAuditCount' },
3586
+ // inprogressZoneCount: { $sum: '$inprogressZoneCount' },
3587
+ // inprogressTrafficCount: { $sum: '$inprogressTrafficCount' },
3588
+
3589
+ // },
3590
+ // },
3591
+ // {
3592
+ // $project: {
3593
+ // _id: 0,
3594
+ // inprogressAuditCount: { $ifNull: [ '$inprogressAuditCount', 0 ] },
3595
+ // inprogressZoneCount: { $ifNull: [ '$inprogressZoneCount', 0 ] },
3596
+ // inprogressTrafficCount: { $ifNull: [ '$inprogressTrafficCount', 0 ] },
3597
+ // },
3598
+ // },
3599
+ // ];
3390
3600
  const getTotalcount = await aggregateAuditStoreData( query );
3391
-
3601
+ const getTotalTraxAudit = await aggregateTraxAuditData( traxQuery );
3392
3602
  const getInprogressCount = await aggregateStoreAudit( inprogressCount );
3393
- if ( getTotalcount.length == 0 ) {
3603
+ // const getBinaryInprogressCount = await aggregateBinaryAudit( binaryInprogressCount );
3604
+ // const getMappingInprogressCount = await aggregateStoreEmpDetection( mappingInprogressCount );
3605
+ if ( getTotalcount.length == 0 && getTotalTraxAudit.length == 0 ) {
3394
3606
  return res.sendError( 'No Data Found', 204 );
3395
3607
  }
3396
-
3608
+ logger.info( { getTotalTraxAudit: getTotalTraxAudit } );
3397
3609
  if ( getInprogressCount.length >0 ) {
3398
3610
  notAssignedCount.totalAuditCount = getTotalcount[0].totalAuditCount - getInprogressCount[0]?.inprogressAuditCount;
3399
3611
  notAssignedCount.totalZoneCount = getTotalcount[0].totalZoneCount - getInprogressCount[0]?.inprogressZoneCount;
@@ -3403,6 +3615,7 @@ export async function totalNotAssignedCount( req, res ) {
3403
3615
  notAssignedCount.totalZoneCount = getTotalcount[0].totalZoneCount;
3404
3616
  notAssignedCount.totalTrafficCount= getTotalcount[0].totalTrafficCount;
3405
3617
  }
3618
+ notAssignedCount.totalTraxAuditCount = getTotalTraxAudit[0]?.totalTraxAuditCount;
3406
3619
  return res.sendSuccess( { result: notAssignedCount } );
3407
3620
  } catch ( error ) {
3408
3621
  const err = error.message || 'Internal Server Error';
@@ -1,4 +1,4 @@
1
- import { checkFileExist, download, getDate, getDateWithCustomizeTime, getUTC, insertOpenSearchData, listFileByPath, logger, signedUrl, sqsReceive } from 'tango-app-api-middleware';
1
+ import { checkFileExist, chunkArray, 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
3
  import { countDocumentsStore, findOneStore } from '../service/store.service.js';
4
4
  import { findOneUser } from '../service/user.service.js';
@@ -1170,7 +1170,7 @@ export async function saveBinary( req, res ) {
1170
1170
  };
1171
1171
  let updatDataunattended= await updateOneBinaryAuditModel( unattendedquery, update );
1172
1172
  if ( updatDataunattended.modifiedCount==0 ) {
1173
- return res.sendError( updatDataunattended, 204 );
1173
+ return res.sendError( 'Update failed, it may be invalid request', 400 );
1174
1174
  }
1175
1175
  logger.info( 'update in binary data', { query: unattendedquery, update: update } );
1176
1176
  res.sendSuccess( `Successfully update in ${inputData.moduleType} ` );
@@ -1194,7 +1194,7 @@ export async function saveBinary( req, res ) {
1194
1194
  };
1195
1195
  let updatDataleft= await updateOneBinaryAuditModel( leftquery, leftupdate );
1196
1196
  if ( updatDataleft.modifiedCount==0 ) {
1197
- return res.sendError( updatDataleft, 204 );
1197
+ return res.sendError( 'Update failed, it may be invalid request', 400 );
1198
1198
  }
1199
1199
  logger.info( 'update in binary data', { query: leftquery, update: leftupdate } );
1200
1200
  res.sendSuccess( `Successfully update in ${inputData.moduleType} ` );
@@ -1218,7 +1218,7 @@ export async function saveBinary( req, res ) {
1218
1218
  };
1219
1219
  let updatDatacamera= await updateOneBinaryAuditModel( cameraquery, cameraupdate );
1220
1220
  if ( updatDatacamera.modifiedCount==0 ) {
1221
- return res.sendError( updatDatacamera, 204 );
1221
+ return res.sendError( 'Update failed, it may be invalid request', 400 );
1222
1222
  }
1223
1223
  logger.info( 'update in binary data', { query: cameraquery, update: cameraupdate } );
1224
1224
  res.sendSuccess( `Successfully update in ${inputData.moduleType} ` );