tango-app-api-audit 3.4.0-alpha.9 → 3.4.1
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 +2 -1
- package/src/controllers/audit.controllers.js +275 -40
- package/src/controllers/traxAudit.controllers.js +536 -67
- package/src/docs/traxAudit.docs.js +22 -1
- package/src/dtos/audit.dtos.js +197 -241
- package/src/dtos/traxAudit.dtos.js +24 -8
- package/src/routes/traxAudit.routes.js +4 -3
- package/src/validation/traxAuditValidation.js +87 -8
package/package.json
CHANGED
|
@@ -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
|
|
|
@@ -195,8 +198,9 @@ export async function getAuditFile( req, res ) {
|
|
|
195
198
|
const bucket = JSON.parse( process.env.BUCKET );
|
|
196
199
|
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
197
200
|
const inputData = req.query;
|
|
198
|
-
const
|
|
199
|
-
|
|
201
|
+
const previousDate = dayjs( dateRange.start ).subtract( 1, 'days' );
|
|
202
|
+
const data = await getDate( new Date( dayjs( previousDate ).format( 'YYYY-MM-DD' ) ), new Date() );
|
|
203
|
+
logger.info( { data: data, previousDate: previousDate, function: 'data', newDate: new Date() } );
|
|
200
204
|
logger.info( { userId: req.user._id, queueName: inputData.queueName, moduleType: inputData.moduleType } );
|
|
201
205
|
const start = data.start;
|
|
202
206
|
const end = data.end;
|
|
@@ -750,10 +754,9 @@ export async function workSpace( req, res ) {
|
|
|
750
754
|
const filter =[
|
|
751
755
|
{ status: { $in: [ 'active', 'hold' ] } },
|
|
752
756
|
{ 'auditConfigs.audit': { $eq: true } },
|
|
757
|
+
{ clientId: { $in: inputData.clientId } },
|
|
753
758
|
];
|
|
754
|
-
|
|
755
|
-
filter.push( { clientId: { $in: inputData.clientId } } );
|
|
756
|
-
}
|
|
759
|
+
|
|
757
760
|
const temp = [];
|
|
758
761
|
const clientQuery = [
|
|
759
762
|
{
|
|
@@ -805,7 +808,7 @@ export async function workSpace( req, res ) {
|
|
|
805
808
|
|
|
806
809
|
const clientDetails = await aggregateClient( clientQuery );
|
|
807
810
|
const clientList = clientDetails.map( ( i ) => i.clientId );
|
|
808
|
-
const fileDate = dayjs( dateRange.start ).subtract( 1, 'days' );
|
|
811
|
+
const fileDate = dayjs( dateRange.start ).subtract( 1, 'days' ); // dayjs( dateRange.start );
|
|
809
812
|
const getStoreData = await findOneStoreData(
|
|
810
813
|
{},
|
|
811
814
|
{ fileDate: 1 },
|
|
@@ -924,6 +927,7 @@ export async function workSpace( req, res ) {
|
|
|
924
927
|
},
|
|
925
928
|
},
|
|
926
929
|
];
|
|
930
|
+
logger.info( { daterange: new Date( dayjs( fileDate ).format( 'YYYY-MM-DD' ) ) } );
|
|
927
931
|
const userIncompleteFiles = [
|
|
928
932
|
{
|
|
929
933
|
$match: {
|
|
@@ -931,7 +935,7 @@ export async function workSpace( req, res ) {
|
|
|
931
935
|
{ clientId: { $in: clientList } },
|
|
932
936
|
{ userId: { $eq: req.user._id } },
|
|
933
937
|
{ moduleType: { $eq: inputData.moduleType } },
|
|
934
|
-
{ createdAt: { $gte:
|
|
938
|
+
{ createdAt: { $gte: new Date( dayjs( fileDate ).format( 'YYYY-MM-DD' ) ) } },
|
|
935
939
|
{ createdAt: { $lte: dateRange.end } },
|
|
936
940
|
],
|
|
937
941
|
},
|
|
@@ -1453,6 +1457,7 @@ export async function userAuditHistory( req, res ) {
|
|
|
1453
1457
|
{
|
|
1454
1458
|
moduleType: { $eq: inputData.moduleType },
|
|
1455
1459
|
},
|
|
1460
|
+
{ clientId: { $in: inputData.clientId } },
|
|
1456
1461
|
];
|
|
1457
1462
|
|
|
1458
1463
|
if ( inputData.dateType == 'fileDate' ) {
|
|
@@ -1484,9 +1489,6 @@ export async function userAuditHistory( req, res ) {
|
|
|
1484
1489
|
auditStatus: { $in: inputData.filterByStatus },
|
|
1485
1490
|
} );
|
|
1486
1491
|
}
|
|
1487
|
-
if ( inputData?.clientId?.length > 0 ) {
|
|
1488
|
-
filter.push( { clientId: { $in: inputData.clientId } } );
|
|
1489
|
-
}
|
|
1490
1492
|
const query = [
|
|
1491
1493
|
{
|
|
1492
1494
|
$match: {
|
|
@@ -1923,11 +1925,9 @@ export async function storeMetrics( req, res ) {
|
|
|
1923
1925
|
{ fileDateISO: { $gte: dateRange.start } },
|
|
1924
1926
|
{ fileDateISO: { $lte: dateRange.end } },
|
|
1925
1927
|
{ moduleType: { $eq: inputData.moduleType } },
|
|
1928
|
+
{ clientId: { $in: inputData.filterByClientId } },
|
|
1926
1929
|
|
|
1927
1930
|
];
|
|
1928
|
-
if ( inputData.filterByClientId && inputData.filterByClientId?.length > 0 ) {
|
|
1929
|
-
filter.push( { clientId: { $in: inputData.filterByClientId } } );
|
|
1930
|
-
}
|
|
1931
1931
|
|
|
1932
1932
|
if ( inputData.filterByStoreId && inputData.filterByStoreId?.length > 0 ) {
|
|
1933
1933
|
filter.push( { storeId: { $in: inputData.filterByStoreId } } );
|
|
@@ -2479,13 +2479,10 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
2479
2479
|
{ fileDateISO: { $lte: dateRange.end } },
|
|
2480
2480
|
{ auditStatus: { $ne: 'completed' } },
|
|
2481
2481
|
{ moduleType: { $eq: inputData.moduleType } },
|
|
2482
|
+
{ clientId: { $in: inputData.clientId } },
|
|
2482
2483
|
|
|
2483
2484
|
];
|
|
2484
2485
|
|
|
2485
|
-
if ( inputData.clientId.length > 0 ) {
|
|
2486
|
-
filters.push( { clientId: { $in: inputData.clientId } } );
|
|
2487
|
-
}
|
|
2488
|
-
|
|
2489
2486
|
if ( inputData.filterByAuditType.length > 0 ) {
|
|
2490
2487
|
filters.push( { auditType: { $in: inputData.filterByAuditType } } );
|
|
2491
2488
|
}
|
|
@@ -2666,12 +2663,10 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
2666
2663
|
let filters =[
|
|
2667
2664
|
{ fileDateISO: { $gte: dateRange.start } },
|
|
2668
2665
|
{ fileDateISO: { $lte: dateRange.end } },
|
|
2669
|
-
{ moduleType: { $eq: inputData.moduleType },
|
|
2670
|
-
},
|
|
2666
|
+
{ moduleType: { $eq: inputData.moduleType } },
|
|
2667
|
+
{ clientId: { $in: inputData.clientId } },
|
|
2671
2668
|
];
|
|
2672
|
-
|
|
2673
|
-
filters.push( { clientId: { $in: inputData.clientId } } );
|
|
2674
|
-
}
|
|
2669
|
+
|
|
2675
2670
|
const storeQuery = inputData.clientId.length? { 'edge.firstFile': true, 'clientId': { $in: inputData. clientId } } : { 'edge.firstFile': true };
|
|
2676
2671
|
temp.installedStores = await countDocumentsStore( storeQuery );
|
|
2677
2672
|
const auditClientDataQuery =[
|
|
@@ -2931,10 +2926,9 @@ export async function overViewCard( req, res ) {
|
|
|
2931
2926
|
let filters =[
|
|
2932
2927
|
{ fileDateISO: { $gte: dateRange.start } },
|
|
2933
2928
|
{ fileDateISO: { $lte: dateRange.end } },
|
|
2929
|
+
{ clientId: { $in: inputData.clientId } },
|
|
2934
2930
|
];
|
|
2935
|
-
|
|
2936
|
-
filters.push( { clientId: { $in: inputData.clientId } } );
|
|
2937
|
-
}
|
|
2931
|
+
|
|
2938
2932
|
const query =[
|
|
2939
2933
|
{
|
|
2940
2934
|
$match: {
|
|
@@ -2989,15 +2983,87 @@ export async function overViewCard( req, res ) {
|
|
|
2989
2983
|
},
|
|
2990
2984
|
},
|
|
2991
2985
|
];
|
|
2986
|
+
|
|
2987
|
+
const binaryQuery =[
|
|
2988
|
+
{
|
|
2989
|
+
$match: {
|
|
2990
|
+
$and: filters,
|
|
2991
|
+
},
|
|
2992
|
+
|
|
2993
|
+
},
|
|
2994
|
+
{
|
|
2995
|
+
$project: {
|
|
2996
|
+
auditFileCount: {
|
|
2997
|
+
$cond: [
|
|
2998
|
+
{ $eq: [ '$auditType', 'Audit' ] }, 1, 0,
|
|
2999
|
+
],
|
|
3000
|
+
},
|
|
3001
|
+
ReAuditFileCount: {
|
|
3002
|
+
$cond: [
|
|
3003
|
+
{ $eq: [ '$auditType', 'ReAudit' ] }, 1, 0,
|
|
3004
|
+
],
|
|
3005
|
+
},
|
|
3006
|
+
inprogressCount: {
|
|
3007
|
+
$cond: [
|
|
3008
|
+
{ $ne: [ '$auditStatus', 'completed' ] }, 1, 0,
|
|
3009
|
+
],
|
|
3010
|
+
},
|
|
3011
|
+
completedCount: {
|
|
3012
|
+
$cond: [
|
|
3013
|
+
{ $eq: [ '$auditStatus', 'completed' ] }, 1, 0,
|
|
3014
|
+
],
|
|
3015
|
+
},
|
|
3016
|
+
},
|
|
3017
|
+
},
|
|
3018
|
+
{
|
|
3019
|
+
$group: {
|
|
3020
|
+
_id: { fileDate: '$fileDate', clientId: '$clientId' },
|
|
3021
|
+
totalCount: { $sum: 1 },
|
|
3022
|
+
auditFileCount: { $sum: '$auditFileCount' },
|
|
3023
|
+
ReAuditFileCount: { $sum: '$ReAuditFileCount' },
|
|
3024
|
+
inprogressCount: { $sum: '$inprogressCount' },
|
|
3025
|
+
completedCount: { $sum: '$completedCount' },
|
|
3026
|
+
|
|
3027
|
+
},
|
|
3028
|
+
},
|
|
3029
|
+
{
|
|
3030
|
+
$project: {
|
|
3031
|
+
_id: 0,
|
|
3032
|
+
totalCount: 1,
|
|
3033
|
+
auditFileCount: 1,
|
|
3034
|
+
ReAuditFileCount: 1,
|
|
3035
|
+
inprogressCount: 1,
|
|
3036
|
+
completedCount: 1,
|
|
3037
|
+
notAssigned: { $subtract: [ '$totalCount', { $add: [ '$inprogressCount', '$completedCount' ] } ] },
|
|
3038
|
+
},
|
|
3039
|
+
},
|
|
3040
|
+
];
|
|
2992
3041
|
const result = await aggregateStoreAudit( query );
|
|
2993
|
-
|
|
2994
|
-
|
|
3042
|
+
const empDetection = await aggregateStoreEmpDetection( query );
|
|
3043
|
+
const binaryAudit = await aggregateBinaryAudit( binaryQuery );
|
|
3044
|
+
|
|
3045
|
+
// Combine all arrays into one
|
|
3046
|
+
const combinedArray = [ ...result, ...empDetection, ...binaryAudit ];
|
|
3047
|
+
|
|
3048
|
+
// Function to merge objects by summing their values
|
|
3049
|
+
const mergedResult = mergeAndSum( combinedArray );
|
|
3050
|
+
|
|
3051
|
+
return res.sendSuccess( { result: Object.keys( mergedResult ).length > 0?mergedResult: temp } );
|
|
2995
3052
|
} catch ( error ) {
|
|
2996
3053
|
const err = error.message || 'Internal Server Error';
|
|
2997
3054
|
logger.error( { error: error, message: req.body, function: 'overViewCard' } );
|
|
2998
3055
|
return res.sendError( err, 500 );
|
|
2999
3056
|
}
|
|
3000
3057
|
}
|
|
3058
|
+
export const mergeAndSum = ( arr ) => {
|
|
3059
|
+
return arr.reduce( ( acc, obj ) => {
|
|
3060
|
+
for ( const [ key, value ] of Object.entries( obj ) ) {
|
|
3061
|
+
// Add the value to the existing key or initialize it if it doesn't exist
|
|
3062
|
+
acc[key] = ( acc[key] || 0 ) + value;
|
|
3063
|
+
}
|
|
3064
|
+
return acc;
|
|
3065
|
+
}, {} );
|
|
3066
|
+
};
|
|
3001
3067
|
|
|
3002
3068
|
export async function summarySplit( req, res ) {
|
|
3003
3069
|
try {
|
|
@@ -3017,10 +3083,9 @@ export async function summarySplit( req, res ) {
|
|
|
3017
3083
|
{ fileDateISO: { $gte: dateRange.start } },
|
|
3018
3084
|
{ fileDateISO: { $lte: dateRange.end } },
|
|
3019
3085
|
{ moduleType: { $eq: inputData.moduleType } },
|
|
3086
|
+
{ clientId: { $in: inputData.clientId } },
|
|
3020
3087
|
];
|
|
3021
|
-
|
|
3022
|
-
filters.push( { clientId: { $in: inputData.clientId } } );
|
|
3023
|
-
}
|
|
3088
|
+
|
|
3024
3089
|
const query =[
|
|
3025
3090
|
{
|
|
3026
3091
|
$match: {
|
|
@@ -3131,13 +3196,10 @@ export async function overviewTable( req, res ) {
|
|
|
3131
3196
|
{ fileDateISO: { $gte: dateRange.start } },
|
|
3132
3197
|
{ fileDateISO: { $lte: dateRange.end } },
|
|
3133
3198
|
{ moduleType: { $eq: inputData.moduleType } },
|
|
3199
|
+
{ clientId: { $in: inputData.clientId } },
|
|
3134
3200
|
|
|
3135
3201
|
];
|
|
3136
3202
|
|
|
3137
|
-
if ( inputData.clientId.length > 0 ) {
|
|
3138
|
-
filters.push( { clientId: { $in: inputData.clientId } } );
|
|
3139
|
-
}
|
|
3140
|
-
|
|
3141
3203
|
if ( inputData.filterByAuditType.length > 0 ) {
|
|
3142
3204
|
filters.push( { auditType: { $in: inputData.filterByAuditType } } );
|
|
3143
3205
|
}
|
|
@@ -3312,6 +3374,15 @@ export async function totalNotAssignedCount( req, res ) {
|
|
|
3312
3374
|
{ createdAt: -1 },
|
|
3313
3375
|
);
|
|
3314
3376
|
const latestDate = getStoreData?.fileDate || dayjs( fileDate ).format( 'DD-MM-YYYY' );
|
|
3377
|
+
|
|
3378
|
+
const geTraxData = await findOneTraxAuditData(
|
|
3379
|
+
{},
|
|
3380
|
+
{ fileDate: 1 },
|
|
3381
|
+
{ createdAt: -1 },
|
|
3382
|
+
);
|
|
3383
|
+
const latestTraxDate = geTraxData?.fileDate || dayjs( fileDate ).format( 'DD-MM-YYYY' );
|
|
3384
|
+
logger.info( { geTraxData: geTraxData } );
|
|
3385
|
+
|
|
3315
3386
|
const query = [
|
|
3316
3387
|
{
|
|
3317
3388
|
$match: {
|
|
@@ -3347,6 +3418,52 @@ export async function totalNotAssignedCount( req, res ) {
|
|
|
3347
3418
|
},
|
|
3348
3419
|
},
|
|
3349
3420
|
];
|
|
3421
|
+
const traxQuery = [
|
|
3422
|
+
{
|
|
3423
|
+
$match: {
|
|
3424
|
+
fileDate: { $eq: latestTraxDate },
|
|
3425
|
+
},
|
|
3426
|
+
},
|
|
3427
|
+
{
|
|
3428
|
+
$project: {
|
|
3429
|
+
totalUnattendedCustomerCount: { $cond: [
|
|
3430
|
+
{ $eq: [ '$moduleType', 'unattended-customer' ] }, 1, 0,
|
|
3431
|
+
] },
|
|
3432
|
+
totalLeftInMiddleCount: { $cond: [
|
|
3433
|
+
{ $eq: [ '$moduleType', 'left-in-middle' ] }, 1, 0,
|
|
3434
|
+
] },
|
|
3435
|
+
totalUniformDetectionCount: { $cond: [
|
|
3436
|
+
{ $eq: [ '$moduleType', 'uniform-detection' ] }, 1, 0,
|
|
3437
|
+
] },
|
|
3438
|
+
totalMobileDetectionCount: { $cond: [
|
|
3439
|
+
{ $eq: [ '$moduleType', 'mobile-detection' ] }, 1, 0,
|
|
3440
|
+
] },
|
|
3441
|
+
|
|
3442
|
+
},
|
|
3443
|
+
},
|
|
3444
|
+
{
|
|
3445
|
+
$group: {
|
|
3446
|
+
_id: null,
|
|
3447
|
+
totalTraxAuditCount: { $sum: 1 },
|
|
3448
|
+
totalUnattendedCustomerCount: { $sum: '$totalUnattendedCustomerCount' },
|
|
3449
|
+
totalLeftInMiddleCount: { $sum: '$totalLeftInMiddleCount' },
|
|
3450
|
+
totalUniformDetectionCount: { $sum: '$totalUniformDetectionCount' },
|
|
3451
|
+
totalMobileDetectionCount: { $sum: '$totalMobileDetectionCount' },
|
|
3452
|
+
|
|
3453
|
+
|
|
3454
|
+
},
|
|
3455
|
+
},
|
|
3456
|
+
{
|
|
3457
|
+
$project: {
|
|
3458
|
+
_id: 0,
|
|
3459
|
+
totalTraxAuditCount: 1,
|
|
3460
|
+
totalUnattendedCustomerCount: 1,
|
|
3461
|
+
totalLeftInMiddleCount: 1,
|
|
3462
|
+
totalUniformDetectionCount: 1,
|
|
3463
|
+
totalMobileDetectionCount: 1,
|
|
3464
|
+
},
|
|
3465
|
+
},
|
|
3466
|
+
];
|
|
3350
3467
|
const inprogressCount=[
|
|
3351
3468
|
{
|
|
3352
3469
|
$match: {
|
|
@@ -3387,22 +3504,140 @@ export async function totalNotAssignedCount( req, res ) {
|
|
|
3387
3504
|
},
|
|
3388
3505
|
},
|
|
3389
3506
|
];
|
|
3390
|
-
const
|
|
3507
|
+
const binaryInprogressCount = [
|
|
3508
|
+
{
|
|
3509
|
+
$match: {
|
|
3510
|
+
fileDate: { $eq: latestTraxDate },
|
|
3511
|
+
},
|
|
3512
|
+
},
|
|
3513
|
+
{
|
|
3514
|
+
$project: {
|
|
3515
|
+
inprogressTraxCount: {
|
|
3516
|
+
$cond: [
|
|
3517
|
+
{ $in: [ '$auditStatus', [ 'completed' ] ] }, 1, 0,
|
|
3518
|
+
],
|
|
3519
|
+
},
|
|
3520
|
+
},
|
|
3521
|
+
},
|
|
3522
|
+
{
|
|
3523
|
+
$group: {
|
|
3524
|
+
_id: null,
|
|
3525
|
+
inprogressTraxCount: { $sum: '$inprogressTraxCount' },
|
|
3526
|
+
|
|
3527
|
+
},
|
|
3528
|
+
},
|
|
3529
|
+
{
|
|
3530
|
+
$project: {
|
|
3531
|
+
_id: 0,
|
|
3532
|
+
inprogressTraxCount: { $ifNull: [ '$inprogressTraxCount', 0 ] },
|
|
3391
3533
|
|
|
3534
|
+
},
|
|
3535
|
+
},
|
|
3536
|
+
];
|
|
3537
|
+
// const binaryInprogressCount=[
|
|
3538
|
+
// {
|
|
3539
|
+
// $match: {
|
|
3540
|
+
// fileDate: { $eq: latestDate },
|
|
3541
|
+
// },
|
|
3542
|
+
// },
|
|
3543
|
+
// {
|
|
3544
|
+
// $project: {
|
|
3545
|
+
// inprogressAuditCount: {
|
|
3546
|
+
// $cond: [
|
|
3547
|
+
// { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] }, 1, 0,
|
|
3548
|
+
// ],
|
|
3549
|
+
// },
|
|
3550
|
+
// inprogressZoneCount: { $cond: [
|
|
3551
|
+
// { $and: [ { $eq: [ '$moduleType', 'zone' ] }, { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] } ] }, 1, 0,
|
|
3552
|
+
// ] },
|
|
3553
|
+
// inprogressTrafficCount: { $cond: [
|
|
3554
|
+
// { $and: [ { $eq: [ '$moduleType', 'traffic' ] }, { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] } ] }, 1, 0,
|
|
3555
|
+
// ] },
|
|
3556
|
+
|
|
3557
|
+
// },
|
|
3558
|
+
// },
|
|
3559
|
+
// {
|
|
3560
|
+
// $group: {
|
|
3561
|
+
// _id: null,
|
|
3562
|
+
// inprogressAuditCount: { $sum: '$inprogressAuditCount' },
|
|
3563
|
+
// inprogressZoneCount: { $sum: '$inprogressZoneCount' },
|
|
3564
|
+
// inprogressTrafficCount: { $sum: '$inprogressTrafficCount' },
|
|
3565
|
+
|
|
3566
|
+
// },
|
|
3567
|
+
// },
|
|
3568
|
+
// {
|
|
3569
|
+
// $project: {
|
|
3570
|
+
// _id: 0,
|
|
3571
|
+
// inprogressAuditCount: { $ifNull: [ '$inprogressAuditCount', 0 ] },
|
|
3572
|
+
// inprogressZoneCount: { $ifNull: [ '$inprogressZoneCount', 0 ] },
|
|
3573
|
+
// inprogressTrafficCount: { $ifNull: [ '$inprogressTrafficCount', 0 ] },
|
|
3574
|
+
// },
|
|
3575
|
+
// },
|
|
3576
|
+
// ];
|
|
3577
|
+
// const mappingInprogressCount=[
|
|
3578
|
+
// {
|
|
3579
|
+
// $match: {
|
|
3580
|
+
// fileDate: { $eq: latestDate },
|
|
3581
|
+
// },
|
|
3582
|
+
// },
|
|
3583
|
+
// {
|
|
3584
|
+
// $project: {
|
|
3585
|
+
// inprogressAuditCount: {
|
|
3586
|
+
// $cond: [
|
|
3587
|
+
// { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] }, 1, 0,
|
|
3588
|
+
// ],
|
|
3589
|
+
// },
|
|
3590
|
+
// inprogressZoneCount: { $cond: [
|
|
3591
|
+
// { $and: [ { $eq: [ '$moduleType', 'zone' ] }, { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] } ] }, 1, 0,
|
|
3592
|
+
// ] },
|
|
3593
|
+
// inprogressTrafficCount: { $cond: [
|
|
3594
|
+
// { $and: [ { $eq: [ '$moduleType', 'traffic' ] }, { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] } ] }, 1, 0,
|
|
3595
|
+
// ] },
|
|
3596
|
+
|
|
3597
|
+
// },
|
|
3598
|
+
// },
|
|
3599
|
+
// {
|
|
3600
|
+
// $group: {
|
|
3601
|
+
// _id: null,
|
|
3602
|
+
// inprogressAuditCount: { $sum: '$inprogressAuditCount' },
|
|
3603
|
+
// inprogressZoneCount: { $sum: '$inprogressZoneCount' },
|
|
3604
|
+
// inprogressTrafficCount: { $sum: '$inprogressTrafficCount' },
|
|
3605
|
+
|
|
3606
|
+
// },
|
|
3607
|
+
// },
|
|
3608
|
+
// {
|
|
3609
|
+
// $project: {
|
|
3610
|
+
// _id: 0,
|
|
3611
|
+
// inprogressAuditCount: { $ifNull: [ '$inprogressAuditCount', 0 ] },
|
|
3612
|
+
// inprogressZoneCount: { $ifNull: [ '$inprogressZoneCount', 0 ] },
|
|
3613
|
+
// inprogressTrafficCount: { $ifNull: [ '$inprogressTrafficCount', 0 ] },
|
|
3614
|
+
// },
|
|
3615
|
+
// },
|
|
3616
|
+
// ];
|
|
3617
|
+
const getTotalcount = await aggregateAuditStoreData( query );
|
|
3618
|
+
const getTotalTraxAudit = await aggregateTraxAuditData( traxQuery );
|
|
3392
3619
|
const getInprogressCount = await aggregateStoreAudit( inprogressCount );
|
|
3393
|
-
|
|
3620
|
+
const getBinaryInprogressCount = await aggregateBinaryAudit( binaryInprogressCount );
|
|
3621
|
+
// const getMappingInprogressCount = await aggregateStoreEmpDetection( mappingInprogressCount );
|
|
3622
|
+
if ( getTotalcount.length == 0 && getTotalTraxAudit.length == 0 ) {
|
|
3394
3623
|
return res.sendError( 'No Data Found', 204 );
|
|
3395
3624
|
}
|
|
3396
|
-
|
|
3625
|
+
logger.info( { getTotalTraxAudit: getTotalTraxAudit } );
|
|
3397
3626
|
if ( getInprogressCount.length >0 ) {
|
|
3398
|
-
notAssignedCount.totalAuditCount = getTotalcount[0].totalAuditCount - getInprogressCount[0]?.inprogressAuditCount;
|
|
3399
|
-
notAssignedCount.totalZoneCount = getTotalcount[0].totalZoneCount - getInprogressCount[0]?.inprogressZoneCount;
|
|
3400
|
-
notAssignedCount.totalTrafficCount = getTotalcount[0].totalTrafficCount - getInprogressCount[0]?.inprogressTrafficCount;
|
|
3627
|
+
notAssignedCount.totalAuditCount =getTotalcount[0].totalAuditCount > getInprogressCount[0]?.inprogressAuditCount? getTotalcount[0].totalAuditCount - getInprogressCount[0]?.inprogressAuditCount : 0;
|
|
3628
|
+
notAssignedCount.totalZoneCount = getTotalcount[0].totalZoneCount > getInprogressCount[0]?.inprogressZoneCount? getTotalcount[0].totalZoneCount - getInprogressCount[0]?.inprogressZoneCount: 0;
|
|
3629
|
+
notAssignedCount.totalTrafficCount = getTotalcount[0].totalTrafficCount > getInprogressCount[0]?.inprogressTrafficCount? getTotalcount[0].totalTrafficCount - getInprogressCount[0]?.inprogressTrafficCount: 0;
|
|
3401
3630
|
} else {
|
|
3402
3631
|
notAssignedCount.totalAuditCount = getTotalcount[0].totalAuditCount;
|
|
3403
3632
|
notAssignedCount.totalZoneCount = getTotalcount[0].totalZoneCount;
|
|
3404
3633
|
notAssignedCount.totalTrafficCount= getTotalcount[0].totalTrafficCount;
|
|
3405
3634
|
}
|
|
3635
|
+
|
|
3636
|
+
if ( getBinaryInprogressCount.length > 0 ) {
|
|
3637
|
+
notAssignedCount.totalTraxAuditCount = getTotalTraxAudit[0].totalTraxAuditCount > getBinaryInprogressCount[0].inprogressTraxCount? getTotalTraxAudit[0].totalTraxAuditCount - getBinaryInprogressCount[0].inprogressTraxCount: 0;
|
|
3638
|
+
} else {
|
|
3639
|
+
notAssignedCount.totalTraxAuditCount = getTotalTraxAudit[0]?.totalTraxAuditCount;
|
|
3640
|
+
}
|
|
3406
3641
|
return res.sendSuccess( { result: notAssignedCount } );
|
|
3407
3642
|
} catch ( error ) {
|
|
3408
3643
|
const err = error.message || 'Internal Server Error';
|