tango-app-api-audit 3.4.0-alpha.12 → 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.12",
3
+ "version": "3.4.0-alpha.13",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -60,6 +60,7 @@ import {
60
60
  } from '../service/auditStoreData.service.js';
61
61
  import { aggregateStoreEmpDetection } from '../service/storeEmpDetection.service.js';
62
62
  import { aggregateBinaryAudit } from '../service/binaryAudit.service.js';
63
+ import { aggregateTraxAuditData, findOneTraxAuditData } from '../service/traxAuditData.service.js';
63
64
 
64
65
  /* < -- *** Configuration *** --> */
65
66
 
@@ -3386,6 +3387,15 @@ export async function totalNotAssignedCount( req, res ) {
3386
3387
  { createdAt: -1 },
3387
3388
  );
3388
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
+
3389
3399
  const query = [
3390
3400
  {
3391
3401
  $match: {
@@ -3421,6 +3431,52 @@ export async function totalNotAssignedCount( req, res ) {
3421
3431
  },
3422
3432
  },
3423
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
+ ];
3424
3480
  const inprogressCount=[
3425
3481
  {
3426
3482
  $match: {
@@ -3461,13 +3517,95 @@ export async function totalNotAssignedCount( req, res ) {
3461
3517
  },
3462
3518
  },
3463
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
+ // ];
3464
3600
  const getTotalcount = await aggregateAuditStoreData( query );
3465
-
3601
+ const getTotalTraxAudit = await aggregateTraxAuditData( traxQuery );
3466
3602
  const getInprogressCount = await aggregateStoreAudit( inprogressCount );
3467
- if ( getTotalcount.length == 0 ) {
3603
+ // const getBinaryInprogressCount = await aggregateBinaryAudit( binaryInprogressCount );
3604
+ // const getMappingInprogressCount = await aggregateStoreEmpDetection( mappingInprogressCount );
3605
+ if ( getTotalcount.length == 0 && getTotalTraxAudit.length == 0 ) {
3468
3606
  return res.sendError( 'No Data Found', 204 );
3469
3607
  }
3470
-
3608
+ logger.info( { getTotalTraxAudit: getTotalTraxAudit } );
3471
3609
  if ( getInprogressCount.length >0 ) {
3472
3610
  notAssignedCount.totalAuditCount = getTotalcount[0].totalAuditCount - getInprogressCount[0]?.inprogressAuditCount;
3473
3611
  notAssignedCount.totalZoneCount = getTotalcount[0].totalZoneCount - getInprogressCount[0]?.inprogressZoneCount;
@@ -3477,6 +3615,7 @@ export async function totalNotAssignedCount( req, res ) {
3477
3615
  notAssignedCount.totalZoneCount = getTotalcount[0].totalZoneCount;
3478
3616
  notAssignedCount.totalTrafficCount= getTotalcount[0].totalTrafficCount;
3479
3617
  }
3618
+ notAssignedCount.totalTraxAuditCount = getTotalTraxAudit[0]?.totalTraxAuditCount;
3480
3619
  return res.sendSuccess( { result: notAssignedCount } );
3481
3620
  } catch ( error ) {
3482
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} ` );