tango-app-api-audit 3.4.3-alpha.1 → 3.4.3-alpha.11
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 +1 -1
- package/src/controllers/audit.controllers.js +160 -11
- package/src/controllers/traxAudit.controllers.js +311 -40
- package/src/docs/traxAudit.docs.js +24 -2
- package/src/dtos/audit.dtos.js +1 -1
- package/src/dtos/traxAudit.dtos.js +12 -3
- package/src/routes/audit.routes.js +4 -1
- package/src/routes/traxAudit.routes.js +4 -4
- package/src/service/auditUserWallet.service.js +4 -1
- package/src/service/auditUsers.service.js +5 -0
- package/src/service/empDetectionOutput.service.js +2 -2
- package/src/service/storeEmpDetection.service.js +5 -0
- package/src/validation/traxAuditValidation.js +47 -1
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
signedUrl,
|
|
10
10
|
getDate, getDateWithCustomizeTime,
|
|
11
11
|
getUTC,
|
|
12
|
+
getOpenSearchData,
|
|
12
13
|
} from 'tango-app-api-middleware';
|
|
13
14
|
import {
|
|
14
15
|
aggregateUserAudit,
|
|
@@ -63,6 +64,7 @@ import { aggregateStoreEmpDetection } from '../service/storeEmpDetection.service
|
|
|
63
64
|
import { aggregateBinaryAudit } from '../service/binaryAudit.service.js';
|
|
64
65
|
import { aggregateTraxAuditData, findOneTraxAuditData } from '../service/traxAuditData.service.js';
|
|
65
66
|
import { createAuditUserWallet } from '../service/auditUserWallet.service.js';
|
|
67
|
+
import { aggregateAuditUsers } from '../service/auditUsers.service.js';
|
|
66
68
|
|
|
67
69
|
/* < -- *** Configuration *** --> */
|
|
68
70
|
|
|
@@ -3567,6 +3569,43 @@ export async function totalNotAssignedCount( req, res ) {
|
|
|
3567
3569
|
},
|
|
3568
3570
|
},
|
|
3569
3571
|
];
|
|
3572
|
+
|
|
3573
|
+
const mappingInprogressCount = [
|
|
3574
|
+
{
|
|
3575
|
+
$match: {
|
|
3576
|
+
fileDate: { $eq: latestTraxDate },
|
|
3577
|
+
},
|
|
3578
|
+
},
|
|
3579
|
+
{
|
|
3580
|
+
$project: {
|
|
3581
|
+
inprogressAuditCount: {
|
|
3582
|
+
$cond: [
|
|
3583
|
+
{ $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] }, 1, 0,
|
|
3584
|
+
],
|
|
3585
|
+
},
|
|
3586
|
+
inprogressTraxCount: {
|
|
3587
|
+
$cond: [
|
|
3588
|
+
{ $and: [ { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] } ] }, 1, 0,
|
|
3589
|
+
],
|
|
3590
|
+
},
|
|
3591
|
+
|
|
3592
|
+
},
|
|
3593
|
+
},
|
|
3594
|
+
{
|
|
3595
|
+
$group: {
|
|
3596
|
+
_id: null,
|
|
3597
|
+
inprogressAuditCount: { $sum: '$inprogressAuditCount' },
|
|
3598
|
+
inprogressTraxCount: { $sum: '$inprogressTraxCount' },
|
|
3599
|
+
},
|
|
3600
|
+
},
|
|
3601
|
+
{
|
|
3602
|
+
$project: {
|
|
3603
|
+
_id: 0,
|
|
3604
|
+
inprogressAuditCount: { $ifNull: [ '$inprogressAuditCount', 0 ] },
|
|
3605
|
+
inprogressTraxCount: { $ifNull: [ '$inprogressTraxCount', 0 ] },
|
|
3606
|
+
},
|
|
3607
|
+
},
|
|
3608
|
+
];
|
|
3570
3609
|
// const binaryInprogressCount=[
|
|
3571
3610
|
// {
|
|
3572
3611
|
// $match: {
|
|
@@ -3651,6 +3690,8 @@ export async function totalNotAssignedCount( req, res ) {
|
|
|
3651
3690
|
const getTotalTraxAudit = await aggregateTraxAuditData( traxQuery );
|
|
3652
3691
|
const getInprogressCount = await aggregateStoreAudit( inprogressCount );
|
|
3653
3692
|
const getBinaryInprogressCount = await aggregateBinaryAudit( binaryInprogressCount );
|
|
3693
|
+
const getMappingInprogressCount = await aggregateStoreEmpDetection( mappingInprogressCount );
|
|
3694
|
+
logger.info( { getMappingInprogressCount: getMappingInprogressCount } );
|
|
3654
3695
|
// const getMappingInprogressCount = await aggregateStoreEmpDetection( mappingInprogressCount );
|
|
3655
3696
|
if ( getTotalcount.length == 0 && getTotalTraxAudit.length == 0 ) {
|
|
3656
3697
|
return res.sendError( 'No Data Found', 204 );
|
|
@@ -3671,6 +3712,12 @@ export async function totalNotAssignedCount( req, res ) {
|
|
|
3671
3712
|
} else {
|
|
3672
3713
|
notAssignedCount.totalTraxAuditCount = getTotalTraxAudit[0]?.totalTraxAuditCount;
|
|
3673
3714
|
}
|
|
3715
|
+
|
|
3716
|
+
if ( getMappingInprogressCount.length > 0 ) {
|
|
3717
|
+
notAssignedCount.totalTraxAuditCount = getTotalTraxAudit[0].totalTraxAuditCount > getMappingInprogressCount[0].inprogressTraxCount ? getTotalTraxAudit[0].totalTraxAuditCount - getMappingInprogressCount[0].inprogressTraxCount : 0;
|
|
3718
|
+
} else {
|
|
3719
|
+
notAssignedCount.totalTraxAuditCount = getTotalTraxAudit[0]?.totalTraxAuditCount;
|
|
3720
|
+
}
|
|
3674
3721
|
return res.sendSuccess( { result: notAssignedCount } );
|
|
3675
3722
|
} catch ( error ) {
|
|
3676
3723
|
const err = error.message || 'Internal Server Error';
|
|
@@ -3759,12 +3806,39 @@ export async function getUserAuditCount( req, res ) {
|
|
|
3759
3806
|
const beforeCountX = userWallet.beforeCountCreditPerc; // 0.0335;
|
|
3760
3807
|
const afterCountY = userWallet.afterCountCreditPerc; // 0.0035;
|
|
3761
3808
|
const reduce = userWallet.reductionPerc; // 0.05;
|
|
3809
|
+
const auditUserQuery=[
|
|
3810
|
+
{
|
|
3811
|
+
$match: {
|
|
3812
|
+
$and: [
|
|
3813
|
+
{ type: { $eq: 'consultant' } },
|
|
3814
|
+
{ isActive: { $eq: true } },
|
|
3815
|
+
],
|
|
3816
|
+
},
|
|
3817
|
+
},
|
|
3818
|
+
{
|
|
3819
|
+
$group: {
|
|
3820
|
+
_id: null,
|
|
3821
|
+
userList: { $push: '$userId' },
|
|
3822
|
+
},
|
|
3823
|
+
},
|
|
3824
|
+
{
|
|
3825
|
+
$project: {
|
|
3826
|
+
_id: 0,
|
|
3827
|
+
userList: 1,
|
|
3828
|
+
},
|
|
3829
|
+
},
|
|
3830
|
+
];
|
|
3831
|
+
const auditUserList = await aggregateAuditUsers( auditUserQuery );
|
|
3832
|
+
if ( auditUserList.length==0 ) {
|
|
3833
|
+
return res.sendError( 'No users available', 204 );
|
|
3834
|
+
}
|
|
3762
3835
|
const userCountQuery= [
|
|
3763
3836
|
{
|
|
3764
3837
|
$match: {
|
|
3765
3838
|
$and: [
|
|
3766
3839
|
{ fileDate: { $eq: fileDate } },
|
|
3767
3840
|
{ auditStatus: { $eq: 'completed' } },
|
|
3841
|
+
{ userId: { $in: auditUserList[0].userList } },
|
|
3768
3842
|
],
|
|
3769
3843
|
},
|
|
3770
3844
|
},
|
|
@@ -3847,6 +3921,7 @@ export async function getUserAuditCount( req, res ) {
|
|
|
3847
3921
|
{
|
|
3848
3922
|
auditStatus: { $eq: 'completed' },
|
|
3849
3923
|
},
|
|
3924
|
+
{ userId: { $in: auditUserList[0].userList } },
|
|
3850
3925
|
],
|
|
3851
3926
|
},
|
|
3852
3927
|
},
|
|
@@ -3866,6 +3941,8 @@ export async function getUserAuditCount( req, res ) {
|
|
|
3866
3941
|
totalEarn: { $ifNull: [ 0, 0 ] },
|
|
3867
3942
|
totalReducedAmount: { $ifNull: [ 0, 0 ] },
|
|
3868
3943
|
totalCredit: { $ifNull: [ 0, 0 ] },
|
|
3944
|
+
deductionBytimeSpent: { $ifNull: [ 0, 0 ] },
|
|
3945
|
+
deductionByMinimumTarget: { $ifNull: [ 0, 0 ] },
|
|
3869
3946
|
},
|
|
3870
3947
|
},
|
|
3871
3948
|
{
|
|
@@ -3883,6 +3960,8 @@ export async function getUserAuditCount( req, res ) {
|
|
|
3883
3960
|
totalEarn: { $first: '$totalEarn' },
|
|
3884
3961
|
totalReducedAmount: { $first: '$totalReducedAmount' },
|
|
3885
3962
|
totalCredit: { $first: '$totalCredit' },
|
|
3963
|
+
deductionByMinimumTarget: { $first: '$deductionByMinimumTarget' },
|
|
3964
|
+
deductionBytimeSpent: { $first: '$deductionBytimeSpent' },
|
|
3886
3965
|
},
|
|
3887
3966
|
},
|
|
3888
3967
|
{
|
|
@@ -3899,6 +3978,9 @@ export async function getUserAuditCount( req, res ) {
|
|
|
3899
3978
|
totalEarn: { $add: [ { $multiply: [ '$totalBeforeCount', beforeCountX ] }, { $multiply: [ '$totalAfterCount', afterCountY ] } ] },
|
|
3900
3979
|
totalReducedAmount: 1,
|
|
3901
3980
|
totalCredit: 1,
|
|
3981
|
+
deductionBytimeSpent: 1,
|
|
3982
|
+
deductionByMinimumTarget: 1,
|
|
3983
|
+
|
|
3902
3984
|
|
|
3903
3985
|
},
|
|
3904
3986
|
},
|
|
@@ -3910,13 +3992,27 @@ export async function getUserAuditCount( req, res ) {
|
|
|
3910
3992
|
totalBeforeCount: 1,
|
|
3911
3993
|
totalAfterCount: 1,
|
|
3912
3994
|
totalTimeSpent: 1,
|
|
3995
|
+
hours: { $floor: { $divide: [ '$totalTimeSpent', 3600 ] } },
|
|
3996
|
+
minutes: {
|
|
3997
|
+
$floor: {
|
|
3998
|
+
$divide: [
|
|
3999
|
+
{ $mod: [ '$totalTimeSpent', 3600 ] }, // Get remaining minutes after hours
|
|
4000
|
+
60,
|
|
4001
|
+
] },
|
|
4002
|
+
},
|
|
3913
4003
|
fileDate: 1,
|
|
3914
4004
|
fileDateISO: 1,
|
|
3915
4005
|
minimumTarget: 1,
|
|
3916
4006
|
totalEarn: 1,
|
|
3917
|
-
|
|
4007
|
+
deductionBytimeSpent: { $cond: [
|
|
3918
4008
|
{ $lt: [ '$totalTimeSpent', configTimeSpentSec ] },
|
|
3919
|
-
{ $
|
|
4009
|
+
{ $multiply: [ reduce, '$totalEarn' ] }, '$deductionBytimeSpent',
|
|
4010
|
+
] },
|
|
4011
|
+
|
|
4012
|
+
deductionByMinimumTarget:
|
|
4013
|
+
{ $cond: [
|
|
4014
|
+
{ $lt: [ '$totalBeforeCount', '$minimumTarget' ] },
|
|
4015
|
+
{ $multiply: [ reduce, '$totalEarn' ] }, '$deductionByMinimumTarget',
|
|
3920
4016
|
] },
|
|
3921
4017
|
totalCredit: { $subtract: [ '$totalEarn', '$totalReducedAmount' ] },
|
|
3922
4018
|
|
|
@@ -3930,18 +4026,33 @@ export async function getUserAuditCount( req, res ) {
|
|
|
3930
4026
|
moduleType: 1,
|
|
3931
4027
|
totalBeforeCount: 1,
|
|
3932
4028
|
totalAfterCount: 1,
|
|
3933
|
-
totalTimeSpent:
|
|
4029
|
+
totalTimeSpent: {
|
|
4030
|
+
$cond: [ { $eq: [ '$hours', 0 ] },
|
|
4031
|
+
{ $concat: [
|
|
4032
|
+
{ $toString: '$minutes' }, ' minutes',
|
|
4033
|
+
] },
|
|
4034
|
+
{ $cond: [ { $eq: [ '$minutes', 0 ] },
|
|
4035
|
+
{ $concat: [
|
|
4036
|
+
{ $toString: '$hours' }, ' hours',
|
|
4037
|
+
] },
|
|
4038
|
+
{
|
|
4039
|
+
$concat: [
|
|
4040
|
+
{ $toString: '$hours' }, ' hours and ',
|
|
4041
|
+
{ $toString: '$minutes' }, ' minutes',
|
|
4042
|
+
],
|
|
4043
|
+
},
|
|
4044
|
+
] },
|
|
4045
|
+
],
|
|
4046
|
+
|
|
4047
|
+
},
|
|
3934
4048
|
fileDate: 1,
|
|
3935
4049
|
fileDateISO: 1,
|
|
3936
4050
|
minimumTarget: 1,
|
|
3937
4051
|
totalEarn: { $add: [ { $multiply: [ '$totalBeforeCount', beforeCountX ] }, { $multiply: [ '$totalAfterCount', afterCountY ] } ] },
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
{ $lt: [ '$totalBeforeCount', '$minimumTarget' ] },
|
|
3941
|
-
{ $add: [ '$totalReducedAmount', { $multiply: [ reduce, '$totalEarn' ] } ] }, '$totalReducedAmount',
|
|
3942
|
-
] },
|
|
3943
|
-
|
|
4052
|
+
deductionByMinimumTarget: 1,
|
|
4053
|
+
deductionBytimeSpent: 1,
|
|
3944
4054
|
totalCredit: { $subtract: [ '$totalEarn', '$totalReducedAmount' ] },
|
|
4055
|
+
totalReducedAmount: { $round: [ { $add: [ '$deductionBytimeSpent', '$deductionByMinimumTarget' ] }, 2 ] },
|
|
3945
4056
|
},
|
|
3946
4057
|
},
|
|
3947
4058
|
{
|
|
@@ -3973,10 +4084,12 @@ export async function getUserAuditCount( req, res ) {
|
|
|
3973
4084
|
moduleType: 1,
|
|
3974
4085
|
totalAfterCount: { $round: [ '$totalAfterCount', 2 ] },
|
|
3975
4086
|
totalBeforeCount: { $round: [ '$totalBeforeCount', 2 ] },
|
|
3976
|
-
timeSpent:
|
|
4087
|
+
timeSpent: '$totalTimeSpent',
|
|
3977
4088
|
fileDate: 1,
|
|
3978
4089
|
fileDateISO: 1,
|
|
3979
|
-
|
|
4090
|
+
deductionByMinimumTarget: { $round: [ '$deductionByMinimumTarget', 2 ] },
|
|
4091
|
+
deductionBytimeSpent: { $round: [ '$deductionBytimeSpent', 2 ] },
|
|
4092
|
+
totalReducedAmount: 1,
|
|
3980
4093
|
totalCredit: { $round: [ { $subtract: [ '$totalEarn', '$totalReducedAmount' ] }, 2 ] },
|
|
3981
4094
|
totalEarn: { $round: [ '$totalEarn', 2 ] },
|
|
3982
4095
|
minimumTarget: 1,
|
|
@@ -4302,3 +4415,39 @@ export async function getUserAuditCountMTD( req, res ) {
|
|
|
4302
4415
|
}
|
|
4303
4416
|
}
|
|
4304
4417
|
|
|
4418
|
+
export async function auditViewLogs( req, res ) {
|
|
4419
|
+
try {
|
|
4420
|
+
const inputData = req.query;
|
|
4421
|
+
const parsedOpenSearch = JSON.parse( process.env.OPENSEARCH );
|
|
4422
|
+
let downTimeQuery = {
|
|
4423
|
+
'size': 100,
|
|
4424
|
+
'query': {
|
|
4425
|
+
'bool': {
|
|
4426
|
+
'must': [
|
|
4427
|
+
{
|
|
4428
|
+
'term': {
|
|
4429
|
+
'doc.logData.fileDate.keyword': dayjs( inputData.fileDate ).format( 'DD-MM-YYYY' ),
|
|
4430
|
+
},
|
|
4431
|
+
},
|
|
4432
|
+
{
|
|
4433
|
+
'term': {
|
|
4434
|
+
'doc.logData.storeId.keyword': inputData.storeId,
|
|
4435
|
+
},
|
|
4436
|
+
},
|
|
4437
|
+
{
|
|
4438
|
+
'term': {
|
|
4439
|
+
'doc.logData.moduleType.keyword': inputData.moduleType,
|
|
4440
|
+
},
|
|
4441
|
+
},
|
|
4442
|
+
],
|
|
4443
|
+
|
|
4444
|
+
},
|
|
4445
|
+
},
|
|
4446
|
+
};
|
|
4447
|
+
const downtime = await getOpenSearchData( parsedOpenSearch.auditLog, downTimeQuery );
|
|
4448
|
+
return res.sendSuccess( downtime );
|
|
4449
|
+
} catch ( err ) {
|
|
4450
|
+
|
|
4451
|
+
}
|
|
4452
|
+
}
|
|
4453
|
+
|
|
@@ -4,16 +4,19 @@ import { countDocumentsStore, findOneStore } from '../service/store.service.js';
|
|
|
4
4
|
import { findOneUser } from '../service/user.service.js';
|
|
5
5
|
import { aggregateUserEmpDetection, createUserEmpDetection, updateOneUserEmpDetection } from '../service/userEmpDetection.service.js';
|
|
6
6
|
import { aggregateTraxAuditData, findOneTraxAuditData } from '../service/traxAuditData.service.js';
|
|
7
|
-
import { aggregateClient } from '../service/client.service.js';
|
|
7
|
+
import { aggregateClient, findOneClient } from '../service/client.service.js';
|
|
8
8
|
import dayjs from 'dayjs';
|
|
9
9
|
import { aggregateAssignAudit } from '../service/assignAudit.service.js';
|
|
10
|
-
import { aggregateStoreEmpDetection, updateManyStoreEmpDetection } from '../service/storeEmpDetection.service.js';
|
|
11
|
-
import { listQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
|
|
10
|
+
import { aggregateStoreEmpDetection, updateManyStoreEmpDetection, updateOneStoreEmpDetection } from '../service/storeEmpDetection.service.js';
|
|
11
|
+
import { listQueue, sendMessageToQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
|
|
12
12
|
import _ from 'lodash';
|
|
13
13
|
import mongoose from 'mongoose';
|
|
14
|
-
import { findOneAuditLog
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
import { findOneAuditLog, createAuditLog,
|
|
15
|
+
} from '../service/auditLog.service.js';
|
|
16
|
+
import {
|
|
17
|
+
findOneUserEmpDetection,
|
|
18
|
+
} from '../service/userEmpDetection.service.js';
|
|
19
|
+
import { updateOneEmpDetectionOutput } from '../service/empDetectionOutput.service.js';
|
|
17
20
|
// export async function getDetectionAuditFile( req, res ) {
|
|
18
21
|
// try {
|
|
19
22
|
// const bucket = JSON.parse( process.env.BUCKET );
|
|
@@ -334,13 +337,13 @@ import { findOneAuditLog } from '../service/auditLog.service.js';
|
|
|
334
337
|
// const data = await signedUrl( fetchData );
|
|
335
338
|
// const mapimg = {
|
|
336
339
|
// img_path: data,
|
|
337
|
-
// img_name: image[0],
|
|
338
|
-
// img_id:
|
|
340
|
+
// img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
|
|
341
|
+
// img_id: img[3],
|
|
339
342
|
// };
|
|
340
343
|
// files.push( {
|
|
341
344
|
// img_path: data,
|
|
342
|
-
// img_name: image[0],
|
|
343
|
-
// img_id:
|
|
345
|
+
// img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
|
|
346
|
+
// img_id: img[3],
|
|
344
347
|
// selected: false,
|
|
345
348
|
// dropped: false,
|
|
346
349
|
// count: 1,
|
|
@@ -742,7 +745,7 @@ export async function workSpace( req, res ) {
|
|
|
742
745
|
},
|
|
743
746
|
];
|
|
744
747
|
|
|
745
|
-
logger.info( { moduleType: inputData.moduleType, key:
|
|
748
|
+
logger.info( { moduleType: inputData.moduleType, key: [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType ), dateStart: new Date( dayjs( fileDate ).format( 'YYYY-MM-DD' ) ), end: dateRange.end, user: req.user._id, client: clientList } );
|
|
746
749
|
|
|
747
750
|
const userAsignAudit = [
|
|
748
751
|
{
|
|
@@ -796,11 +799,11 @@ export async function workSpace( req, res ) {
|
|
|
796
799
|
},
|
|
797
800
|
];
|
|
798
801
|
|
|
799
|
-
const auditUserCount =
|
|
800
|
-
const userIncompleteFilesCount =
|
|
802
|
+
const auditUserCount = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( auditFiles ) : await aggregateBinaryAudit( auditFiles );
|
|
803
|
+
const userIncompleteFilesCount = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( userIncompleteFiles ) : await aggregateBinaryAudit( userIncompleteFiles );
|
|
801
804
|
logger.info( { moduleType: inputData.moduleType, userIncompleteFiles: userIncompleteFilesCount } );
|
|
802
805
|
const userAsignAuditCount = await aggregateAssignAudit( userAsignAudit );
|
|
803
|
-
const completedStoresCount =
|
|
806
|
+
const completedStoresCount = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( completedStores ) : await aggregateBinaryAudit( binarCompletedStores );
|
|
804
807
|
const clientAssignedCount = await aggregateAssignAudit( clientAssign );
|
|
805
808
|
const auditStoreData = await aggregateTraxAuditData(
|
|
806
809
|
auditStoreDataQuery,
|
|
@@ -1697,7 +1700,7 @@ export async function userAuditHistory( req, res ) {
|
|
|
1697
1700
|
},
|
|
1698
1701
|
);
|
|
1699
1702
|
}
|
|
1700
|
-
const count =
|
|
1703
|
+
const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
1701
1704
|
if ( count.length == 0 ) {
|
|
1702
1705
|
return res.sendError( 'No Data Found', 204 );
|
|
1703
1706
|
}
|
|
@@ -1767,7 +1770,7 @@ export async function userAuditHistory( req, res ) {
|
|
|
1767
1770
|
{
|
|
1768
1771
|
$limit: limit,
|
|
1769
1772
|
} );
|
|
1770
|
-
const result =
|
|
1773
|
+
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
1771
1774
|
|
|
1772
1775
|
return res.sendSuccess( { result: result, count: count.length } );
|
|
1773
1776
|
} catch ( error ) {
|
|
@@ -1919,6 +1922,125 @@ export async function clientMetrics( req, res ) {
|
|
|
1919
1922
|
},
|
|
1920
1923
|
];
|
|
1921
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
|
+
|
|
1922
2044
|
if ( inputData?.filterByStatus?.length> 0 ) {
|
|
1923
2045
|
query.push(
|
|
1924
2046
|
{
|
|
@@ -1950,7 +2072,7 @@ export async function clientMetrics( req, res ) {
|
|
|
1950
2072
|
);
|
|
1951
2073
|
}
|
|
1952
2074
|
|
|
1953
|
-
const count = await aggregateTraxAuditData( query );
|
|
2075
|
+
const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
|
|
1954
2076
|
logger.info( { count: count } );
|
|
1955
2077
|
if ( count.length == 0 ) {
|
|
1956
2078
|
return res.sendError( 'No Data Found', 204 );
|
|
@@ -1983,7 +2105,7 @@ export async function clientMetrics( req, res ) {
|
|
|
1983
2105
|
}
|
|
1984
2106
|
|
|
1985
2107
|
logger.info( { query: query } );
|
|
1986
|
-
const result = await aggregateTraxAuditData( query );
|
|
2108
|
+
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
|
|
1987
2109
|
if ( result.length == 0 ) {
|
|
1988
2110
|
return res.sendError( 'No Data Found', 204 );
|
|
1989
2111
|
}
|
|
@@ -2426,7 +2548,9 @@ export async function storeMetrics( req, res ) {
|
|
|
2426
2548
|
},
|
|
2427
2549
|
);
|
|
2428
2550
|
}
|
|
2429
|
-
|
|
2551
|
+
logger.info( { keyss: [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType ) } );
|
|
2552
|
+
const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2553
|
+
|
|
2430
2554
|
|
|
2431
2555
|
if ( count.length == 0 ) {
|
|
2432
2556
|
return res.sendError( 'No data Found', 204 );
|
|
@@ -2441,7 +2565,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2441
2565
|
} else {
|
|
2442
2566
|
query.push( { $limit: 10000 } );
|
|
2443
2567
|
}
|
|
2444
|
-
const result =
|
|
2568
|
+
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2445
2569
|
if ( inputData.isExport ) {
|
|
2446
2570
|
const exportdata = [];
|
|
2447
2571
|
result.forEach( ( element ) => {
|
|
@@ -2744,7 +2868,7 @@ export async function userMetrics( req, res ) {
|
|
|
2744
2868
|
);
|
|
2745
2869
|
}
|
|
2746
2870
|
|
|
2747
|
-
const count =
|
|
2871
|
+
const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2748
2872
|
if ( count.length == 0 ) {
|
|
2749
2873
|
return res.sendError( 'No Data Found', 204 );
|
|
2750
2874
|
}
|
|
@@ -2778,7 +2902,7 @@ export async function userMetrics( req, res ) {
|
|
|
2778
2902
|
'Product Type': '$value',
|
|
2779
2903
|
// 'Mapping Percentage': '$mappingPerc',
|
|
2780
2904
|
};
|
|
2781
|
-
|
|
2905
|
+
[ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?
|
|
2782
2906
|
query.push(
|
|
2783
2907
|
{
|
|
2784
2908
|
$project: detection,
|
|
@@ -2792,7 +2916,7 @@ export async function userMetrics( req, res ) {
|
|
|
2792
2916
|
}
|
|
2793
2917
|
|
|
2794
2918
|
|
|
2795
|
-
const result =
|
|
2919
|
+
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2796
2920
|
if ( inputData.isExport ) {
|
|
2797
2921
|
await download( result, res );
|
|
2798
2922
|
return;
|
|
@@ -2936,7 +3060,7 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
2936
3060
|
},
|
|
2937
3061
|
);
|
|
2938
3062
|
}
|
|
2939
|
-
const count =
|
|
3063
|
+
const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2940
3064
|
if ( count.length == 0 ) {
|
|
2941
3065
|
return res.sendError( 'No Data Found', 204 );
|
|
2942
3066
|
}
|
|
@@ -2952,7 +3076,7 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
2952
3076
|
} );
|
|
2953
3077
|
}
|
|
2954
3078
|
|
|
2955
|
-
const result =
|
|
3079
|
+
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2956
3080
|
if ( inputData.isExport ) {
|
|
2957
3081
|
const exportdata = [];
|
|
2958
3082
|
result.forEach( ( element ) => {
|
|
@@ -3146,7 +3270,7 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
3146
3270
|
},
|
|
3147
3271
|
];
|
|
3148
3272
|
|
|
3149
|
-
const storeAudit =
|
|
3273
|
+
const storeAudit = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3150
3274
|
if ( storeAudit.length > 0 ) {
|
|
3151
3275
|
temp.inprogressStores= storeAudit[0].inprogressStores;
|
|
3152
3276
|
temp.completedStores = storeAudit[0].completedStores;
|
|
@@ -3188,6 +3312,63 @@ export async function summarySplit( req, res ) {
|
|
|
3188
3312
|
{ clientId: { $in: inputData.clientId } },
|
|
3189
3313
|
];
|
|
3190
3314
|
|
|
3315
|
+
|
|
3316
|
+
const binaryAuditQuery =[
|
|
3317
|
+
{
|
|
3318
|
+
$match: {
|
|
3319
|
+
$and: filters,
|
|
3320
|
+
},
|
|
3321
|
+
|
|
3322
|
+
},
|
|
3323
|
+
{
|
|
3324
|
+
$project: {
|
|
3325
|
+
auditInprogress: {
|
|
3326
|
+
$cond: [
|
|
3327
|
+
{ $and: [ { $eq: [ '$auditType', 'Audit' ] }, { $eq: [ '$auditStatus', 'inprogress' ] } ] }, 1, 0,
|
|
3328
|
+
],
|
|
3329
|
+
},
|
|
3330
|
+
reAuditInprogress: {
|
|
3331
|
+
$cond: [
|
|
3332
|
+
{ $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$auditStatus', 'inprogress' ] } ] }, 1, 0,
|
|
3333
|
+
],
|
|
3334
|
+
},
|
|
3335
|
+
|
|
3336
|
+
reAuditCompleted: {
|
|
3337
|
+
$cond: [
|
|
3338
|
+
{ $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$auditStatus', 'completed' ] } ] }, 1, 0,
|
|
3339
|
+
],
|
|
3340
|
+
},
|
|
3341
|
+
auditCompleted: {
|
|
3342
|
+
$cond: [
|
|
3343
|
+
{ $and: [ { $eq: [ '$auditType', 'Audit' ] }, { $eq: [ '$auditStatus', 'completed' ] } ] }, 1, 0,
|
|
3344
|
+
],
|
|
3345
|
+
},
|
|
3346
|
+
},
|
|
3347
|
+
},
|
|
3348
|
+
{
|
|
3349
|
+
$group: {
|
|
3350
|
+
_id: null,
|
|
3351
|
+
auditInprogress: { $sum: '$auditInprogress' },
|
|
3352
|
+
reAuditInprogress: { $sum: '$reAuditInprogress' },
|
|
3353
|
+
reAuditCompleted: { $sum: '$reAuditCompleted' },
|
|
3354
|
+
auditCompleted: { $sum: '$auditCompleted' },
|
|
3355
|
+
|
|
3356
|
+
},
|
|
3357
|
+
},
|
|
3358
|
+
{
|
|
3359
|
+
$project: {
|
|
3360
|
+
_id: 0,
|
|
3361
|
+
totalInprogress: 1,
|
|
3362
|
+
auditInprogress: 1,
|
|
3363
|
+
reAuditInprogress: 1,
|
|
3364
|
+
reAuditCompleted: 1,
|
|
3365
|
+
auditCompleted: 1,
|
|
3366
|
+
totalCount: { $ifNull: [ 0, 0 ] },
|
|
3367
|
+
|
|
3368
|
+
},
|
|
3369
|
+
},
|
|
3370
|
+
];
|
|
3371
|
+
|
|
3191
3372
|
const query =[
|
|
3192
3373
|
{
|
|
3193
3374
|
$match: {
|
|
@@ -3277,7 +3458,7 @@ export async function summarySplit( req, res ) {
|
|
|
3277
3458
|
},
|
|
3278
3459
|
},
|
|
3279
3460
|
];
|
|
3280
|
-
const result =
|
|
3461
|
+
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3281
3462
|
const totalCount = await aggregateTraxAuditData( totalQuery );
|
|
3282
3463
|
result[0].totalCount = totalCount[0]?.total;
|
|
3283
3464
|
return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
|
|
@@ -3424,7 +3605,7 @@ export async function overviewTable( req, res ) {
|
|
|
3424
3605
|
},
|
|
3425
3606
|
);
|
|
3426
3607
|
}
|
|
3427
|
-
const count =
|
|
3608
|
+
const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3428
3609
|
if ( count.length == 0 ) {
|
|
3429
3610
|
return res.sendError( 'No Data Found', 204 );
|
|
3430
3611
|
}
|
|
@@ -3439,7 +3620,7 @@ export async function overviewTable( req, res ) {
|
|
|
3439
3620
|
$limit: limit,
|
|
3440
3621
|
} );
|
|
3441
3622
|
}
|
|
3442
|
-
const result =
|
|
3623
|
+
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3443
3624
|
if ( inputData.isExport ) {
|
|
3444
3625
|
const exportdata = [];
|
|
3445
3626
|
result.forEach( ( element ) => {
|
|
@@ -3812,13 +3993,13 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
3812
3993
|
const data = await signedUrl( fetchData );
|
|
3813
3994
|
const mapimg = {
|
|
3814
3995
|
img_path: data,
|
|
3815
|
-
img_name: image[0],
|
|
3816
|
-
img_id:
|
|
3996
|
+
img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
|
|
3997
|
+
img_id: img[3],
|
|
3817
3998
|
};
|
|
3818
3999
|
files.push( {
|
|
3819
4000
|
img_path: data,
|
|
3820
|
-
img_name: image[0],
|
|
3821
|
-
img_id:
|
|
4001
|
+
img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
|
|
4002
|
+
img_id: img[3],
|
|
3822
4003
|
selected: false,
|
|
3823
4004
|
dropped: false,
|
|
3824
4005
|
count: 1,
|
|
@@ -3837,7 +4018,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
3837
4018
|
userId: req.user._id,
|
|
3838
4019
|
storeId: msg.storeId,
|
|
3839
4020
|
clientId: msg.storeId.split( '-' )[0],
|
|
3840
|
-
auditType: 'Audit',
|
|
4021
|
+
auditType: msg.auditType || 'Audit',
|
|
3841
4022
|
fileDate: msg.fileDate,
|
|
3842
4023
|
inputBucketName: msg.inputBucketName,
|
|
3843
4024
|
folderPath: msg.folderPath,
|
|
@@ -3858,7 +4039,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
3858
4039
|
userId: req.user._id,
|
|
3859
4040
|
storeId: msg.storeId,
|
|
3860
4041
|
clientId: msg.storeId.split( '-' )[0],
|
|
3861
|
-
auditType: 'Audit',
|
|
4042
|
+
auditType: msg.auditType || 'Audit',
|
|
3862
4043
|
fileDate: msg.fileDate,
|
|
3863
4044
|
folderPath: msg.folderPath,
|
|
3864
4045
|
inputBucketName: msg.inputBucketName,
|
|
@@ -3921,7 +4102,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
3921
4102
|
queueName: inputData.queueName,
|
|
3922
4103
|
storeId: storeId,
|
|
3923
4104
|
fileDate: fileDate,
|
|
3924
|
-
auditType: 'Audit',
|
|
4105
|
+
auditType: msg.auditType || 'Audit',
|
|
3925
4106
|
auditId: insertData._id,
|
|
3926
4107
|
userId: insertData.userId,
|
|
3927
4108
|
moduleType: inputData.moduleType,
|
|
@@ -3945,7 +4126,7 @@ export async function saveDraft( req, res ) {
|
|
|
3945
4126
|
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
3946
4127
|
const inputData = req.body;
|
|
3947
4128
|
inputData.userId = req.user._id;
|
|
3948
|
-
const getUserAuditData = await
|
|
4129
|
+
const getUserAuditData = await findOneUserEmpDetection( { _id: inputData.auditId } );
|
|
3949
4130
|
if ( !getUserAuditData ) {
|
|
3950
4131
|
return res.sendError( 'No Data Found', 204 );
|
|
3951
4132
|
}
|
|
@@ -3963,7 +4144,6 @@ export async function saveDraft( req, res ) {
|
|
|
3963
4144
|
const storeQuery = {
|
|
3964
4145
|
storeId: inputData.storeId,
|
|
3965
4146
|
fileDate: inputData.fileDate,
|
|
3966
|
-
zoneName: inputData.zoneName,
|
|
3967
4147
|
};
|
|
3968
4148
|
|
|
3969
4149
|
let storeRecord = {
|
|
@@ -4004,7 +4184,7 @@ export async function saveDraft( req, res ) {
|
|
|
4004
4184
|
}
|
|
4005
4185
|
await createAuditLog( inputData );
|
|
4006
4186
|
await updateOneUserEmpDetection( userQuery, userRecord );
|
|
4007
|
-
await
|
|
4187
|
+
await updateOneStoreEmpDetection( storeQuery, storeRecord );
|
|
4008
4188
|
return res.sendSuccess( {
|
|
4009
4189
|
result: 'The file has been drafted successfully',
|
|
4010
4190
|
} );
|
|
@@ -4048,8 +4228,13 @@ export async function getDraftedData( req, res ) {
|
|
|
4048
4228
|
export async function save( req, res ) {
|
|
4049
4229
|
try {
|
|
4050
4230
|
const inputData = req.body;
|
|
4051
|
-
const
|
|
4231
|
+
const getUserAuditData = await findOneUserEmpDetection( { _id: inputData.auditId } );
|
|
4232
|
+
inputData.clientId = getUserAuditData.clientId;
|
|
4233
|
+
const query ={ storeId: inputData.storeId, moduleType: inputData.moduleType, fileDate: inputData.fileDate };
|
|
4234
|
+
const data = await updateOneEmpDetectionOutput( query, { $set: inputData }, { upsert: true } );
|
|
4052
4235
|
if ( data ) {
|
|
4236
|
+
await updateOneUserEmpDetection( { _id: inputData.auditId }, { auditStatus: 'completed', afterCount: inputData.employeeCount } );
|
|
4237
|
+
await updateOneStoreEmpDetection( query, { status: 'completed', afterCount: inputData.employeeCount } );
|
|
4053
4238
|
return res.sendSuccess( { result: 'Updated Successfully' } );
|
|
4054
4239
|
} else {
|
|
4055
4240
|
return res.sendError( 'something went wrong', 403 );
|
|
@@ -4064,3 +4249,89 @@ export async function save( req, res ) {
|
|
|
4064
4249
|
return res.sendError( err, 500 );
|
|
4065
4250
|
}
|
|
4066
4251
|
}
|
|
4252
|
+
|
|
4253
|
+
export async function reTrigger( req, res ) {
|
|
4254
|
+
try {
|
|
4255
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
4256
|
+
const inputData = req.body;
|
|
4257
|
+
const message = req.sqs;
|
|
4258
|
+
const sqs = JSON.parse( process.env.SQS );
|
|
4259
|
+
const getQueueName = await findOneClient( { clientId: req.audit.clientId }, { 'auditConfigs': 1 } );
|
|
4260
|
+
const queueName = inputData.moduleType == 'uniform-detection' ? getQueueName?.auditConfigs?.traxQueueName?.uniformDetection : getQueueName?.auditConfigs?.traxQueueName?.mobileDetection;
|
|
4261
|
+
if ( !getQueueName || queueName == '' ) {
|
|
4262
|
+
return res.sendError( 'queueName does not create', 400 );
|
|
4263
|
+
}
|
|
4264
|
+
const msg = {
|
|
4265
|
+
storeId: message.storeId,
|
|
4266
|
+
fileDate: message.fileDate,
|
|
4267
|
+
moduleType: message.moduleType,
|
|
4268
|
+
inputBucketName: message.inputBucketName,
|
|
4269
|
+
questionType: message.questionType,
|
|
4270
|
+
question: message.question,
|
|
4271
|
+
folderPath: message.folderPath,
|
|
4272
|
+
fileCount: message.fileCount,
|
|
4273
|
+
};
|
|
4274
|
+
const sqsProduceQueue = {
|
|
4275
|
+
QueueUrl: `${sqs.url}${queueName}`,
|
|
4276
|
+
MessageBody: JSON.stringify( msg ),
|
|
4277
|
+
};
|
|
4278
|
+
const sqsQueue = await sendMessageToQueue( sqsProduceQueue.QueueUrl, sqsProduceQueue.MessageBody );
|
|
4279
|
+
if ( sqsQueue?.errorCode ) {
|
|
4280
|
+
const error = sqsQueue?.errorMsg;
|
|
4281
|
+
const code = sqsQueue?.errorCode;
|
|
4282
|
+
return res.sendError( error, code );
|
|
4283
|
+
} else {
|
|
4284
|
+
if ( req.audit.status !== 'completed' ) {
|
|
4285
|
+
const userRecord = {
|
|
4286
|
+
auditStatus: 'skipped',
|
|
4287
|
+
isDraft: false,
|
|
4288
|
+
};
|
|
4289
|
+
const query = {
|
|
4290
|
+
storeId: inputData.storeId,
|
|
4291
|
+
fileDate: inputData.fileDate,
|
|
4292
|
+
auditStatus: req.audit.status,
|
|
4293
|
+
moduleType: inputData.moduleType,
|
|
4294
|
+
|
|
4295
|
+
};
|
|
4296
|
+
await updateOneUserEmpDetection( query, userRecord );
|
|
4297
|
+
}
|
|
4298
|
+
|
|
4299
|
+
const storeQuery = {
|
|
4300
|
+
storeId: inputData.storeId,
|
|
4301
|
+
fileDate: inputData.fileDate,
|
|
4302
|
+
moduleType: inputData.moduleType,
|
|
4303
|
+
|
|
4304
|
+
};
|
|
4305
|
+
|
|
4306
|
+
const storeRecord = {
|
|
4307
|
+
status: 'not_assign',
|
|
4308
|
+
};
|
|
4309
|
+
|
|
4310
|
+
await updateOneStoreEmpDetection( storeQuery, storeRecord );
|
|
4311
|
+
const logData = {
|
|
4312
|
+
userId: req.user._id,
|
|
4313
|
+
userName: req.user.userName,
|
|
4314
|
+
logType: 'traxAudit',
|
|
4315
|
+
logSubType: 'reTrigger',
|
|
4316
|
+
logData: {
|
|
4317
|
+
beforeCount: message.fileCount,
|
|
4318
|
+
afterCount: '',
|
|
4319
|
+
fileDate: inputData.fileDate,
|
|
4320
|
+
auditType: req.audit.auditType,
|
|
4321
|
+
storeId: inputData.storeId,
|
|
4322
|
+
moduleType: inputData.moduleType,
|
|
4323
|
+
queueName: queueName,
|
|
4324
|
+
triggerBy: req.user.userName,
|
|
4325
|
+
triggerId: req.user._id,
|
|
4326
|
+
},
|
|
4327
|
+
createdAt: new Date(),
|
|
4328
|
+
};
|
|
4329
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
4330
|
+
}
|
|
4331
|
+
return res.sendSuccess( { result: 'The File has been Re-Triggered Succesfully' } );
|
|
4332
|
+
} catch ( error ) {
|
|
4333
|
+
const err = error.message;
|
|
4334
|
+
logger.error( { error: error, message: req.body, function: 'reTrigger' } );
|
|
4335
|
+
return res.sendError( err, 500 );
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import j2s from 'joi-to-swagger';
|
|
2
|
-
import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema, pendingSummaryTableSchema, overAllAuditSummarySchema, overviewTableSchema, summarySplitSchema, getUpdatedFileSchema, getDetectionFileValid, saveBinarySchema, saveDraftSchema, getDraftedDataSchema } from '../dtos/traxAudit.dtos.js';
|
|
2
|
+
import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema, pendingSummaryTableSchema, overAllAuditSummarySchema, overviewTableSchema, summarySplitSchema, getUpdatedFileSchema, getDetectionFileValid, saveBinarySchema, saveDraftSchema, getDraftedDataSchema, reTriggerValidSchema } from '../dtos/traxAudit.dtos.js';
|
|
3
3
|
|
|
4
4
|
export const traxAuditDocs = {
|
|
5
5
|
|
|
@@ -363,7 +363,7 @@ export const traxAuditDocs = {
|
|
|
363
363
|
},
|
|
364
364
|
},
|
|
365
365
|
|
|
366
|
-
'/v3/
|
|
366
|
+
'/v3/trax-audit/get-drafted-data': {
|
|
367
367
|
get: {
|
|
368
368
|
tags: [ 'Trax Audit' ],
|
|
369
369
|
description: 'Get a saved file via DB',
|
|
@@ -403,4 +403,26 @@ export const traxAuditDocs = {
|
|
|
403
403
|
},
|
|
404
404
|
},
|
|
405
405
|
},
|
|
406
|
+
'/v3/trax-audit/metrics/re-trigger': {
|
|
407
|
+
post: {
|
|
408
|
+
tags: [ 'Trax Audit' ],
|
|
409
|
+
description: `Manual re trigger a file`,
|
|
410
|
+
operationId: 'metrics/re-trigger',
|
|
411
|
+
parameters: {},
|
|
412
|
+
requestBody: {
|
|
413
|
+
content: {
|
|
414
|
+
'application/json': {
|
|
415
|
+
schema: j2s( reTriggerValidSchema ).swagger,
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
responses: {
|
|
420
|
+
200: { description: 'Successful' },
|
|
421
|
+
401: { description: 'Unauthorized User' },
|
|
422
|
+
422: { description: 'Field Error' },
|
|
423
|
+
500: { description: 'Server Error' },
|
|
424
|
+
204: { description: 'Not Found' },
|
|
425
|
+
},
|
|
426
|
+
},
|
|
427
|
+
},
|
|
406
428
|
};
|
package/src/dtos/audit.dtos.js
CHANGED
|
@@ -266,7 +266,7 @@ export const reTriggerValid = {
|
|
|
266
266
|
export const overViewCardSchema = joi.object( {
|
|
267
267
|
fromDate: joi.string().required(),
|
|
268
268
|
toDate: joi.string().required(),
|
|
269
|
-
clientId: joi.array().items( joi.string().required() ).required(),
|
|
269
|
+
clientId: joi.array().items( joi.string().required().allow( '' ) ).required(),
|
|
270
270
|
} );
|
|
271
271
|
|
|
272
272
|
export const overViewCardValid = {
|
|
@@ -45,7 +45,6 @@ export const saveDraftSchema = joi.object(
|
|
|
45
45
|
storeId: joi.string().required(),
|
|
46
46
|
auditId: joi.string().required(),
|
|
47
47
|
moduleType: joi.string().required(),
|
|
48
|
-
zoneName: joi.string().required(),
|
|
49
48
|
auditType: joi.string().required(),
|
|
50
49
|
fileDate: joi.string().required(),
|
|
51
50
|
queueName: joi.string().required(),
|
|
@@ -273,8 +272,6 @@ export const saveSchema = joi.object( {
|
|
|
273
272
|
auditType: joi.string().required(),
|
|
274
273
|
moduleType: joi.string().required(),
|
|
275
274
|
beforeCount: joi.number().required(),
|
|
276
|
-
junkCount: joi.number().required(),
|
|
277
|
-
junk: joi.array().required(),
|
|
278
275
|
employeeCount: joi.number().required(),
|
|
279
276
|
employee: joi.array().required(),
|
|
280
277
|
} );
|
|
@@ -282,3 +279,15 @@ export const saveSchema = joi.object( {
|
|
|
282
279
|
export const saveValid = {
|
|
283
280
|
body: saveSchema,
|
|
284
281
|
};
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
export const reTriggerValidSchema = joi.object( {
|
|
285
|
+
fileDate: joi.string().required(),
|
|
286
|
+
storeId: joi.string().required(),
|
|
287
|
+
moduleType: joi.string().required(),
|
|
288
|
+
|
|
289
|
+
} );
|
|
290
|
+
|
|
291
|
+
export const reTriggerValid = {
|
|
292
|
+
body: reTriggerValidSchema,
|
|
293
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import { isAuditDocumentExist, isAuditInputFolderExist, isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
|
|
3
3
|
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
4
|
-
import { auditImages, auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, totalNotAssignedCount, userAuditHistory, userMetrics, workSpace, getUserAuditCount, getUserAuditCountMTD } from '../controllers/audit.controllers.js';
|
|
4
|
+
import { auditImages, auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, totalNotAssignedCount, userAuditHistory, userMetrics, workSpace, getUserAuditCount, getUserAuditCountMTD, auditViewLogs } from '../controllers/audit.controllers.js';
|
|
5
5
|
import { auditStoreValid, clientMetricsValid, clientValid, getDraftedDataValid, getFileValid, overAllAuditSummaryValid, overViewCardValid, pendingSummaryTableValid, reTriggerValid, saveDraftValid, saveValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid, workSpaceValid, auditImageValid, overviewTableValid } from '../dtos/audit.dtos.js';
|
|
6
6
|
|
|
7
7
|
export const auditRouter = express.Router();
|
|
@@ -39,4 +39,7 @@ auditRouter.get( '/total-not-assigned-count', isAllowedSessionHandler, totalNotA
|
|
|
39
39
|
// audit user wallet
|
|
40
40
|
auditRouter.get( '/get-user-audit-count', isAllowedSessionHandler, getUserAuditCount );
|
|
41
41
|
auditRouter.get( '/get-user-audit-count-mtd', isAllowedSessionHandler, getUserAuditCountMTD );
|
|
42
|
+
|
|
43
|
+
// audit log
|
|
44
|
+
auditRouter.get( '/audit-view-logs', isAllowedSessionHandler, auditViewLogs );
|
|
42
45
|
export default auditRouter;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
3
|
-
import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid, summarySplitValid, overviewTableValid, getUpdatedFileValid, saveBinaryValid, getDraftedDataValid } from '../dtos/traxAudit.dtos.js';
|
|
3
|
+
import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid, summarySplitValid, overviewTableValid, getUpdatedFileValid, saveBinaryValid, getDraftedDataValid, saveDraftValid, reTriggerValidSchema } from '../dtos/traxAudit.dtos.js';
|
|
4
4
|
import { isExistsQueue } from '../validation/audit.validation.js';
|
|
5
|
-
import { clientMetrics, getAuditFile, getDetectionAuditFile, getUpdatedFile, overAllAuditSummary, overviewTable, pendingSummaryTable, saveBinary, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace, saveDraft, getDraftedData, save } from '../controllers/traxAudit.controllers.js';
|
|
6
|
-
import { isTraxAuditDocumentExist, validateBinaryAudit } from '../validation/traxAuditValidation.js';
|
|
7
|
-
import { saveDraftValid } from '../dtos/audit.dtos.js';
|
|
5
|
+
import { clientMetrics, getAuditFile, getDetectionAuditFile, getUpdatedFile, overAllAuditSummary, overviewTable, pendingSummaryTable, saveBinary, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace, saveDraft, getDraftedData, save, reTrigger } from '../controllers/traxAudit.controllers.js';
|
|
6
|
+
import { isMappingAuditInputFolderExist, isTraxAuditDocumentExist, isuserEmpDocumentExist, validateBinaryAudit } from '../validation/traxAuditValidation.js';
|
|
8
7
|
|
|
9
8
|
export const traxAuditRouter = Router();
|
|
10
9
|
|
|
@@ -29,6 +28,7 @@ traxAuditRouter.post( '/metrics/store-metrics', isAllowedSessionHandler, validat
|
|
|
29
28
|
traxAuditRouter.post( '/metrics/user-metrics', isAllowedSessionHandler, validate( userMetricsValid ), userMetrics );
|
|
30
29
|
traxAuditRouter.post( '/metrics/pending-summary-table', isAllowedSessionHandler, validate( pendingSummaryTableValid ), pendingSummaryTable );
|
|
31
30
|
traxAuditRouter.post( '/metrics/overall-audit-summary', isAllowedSessionHandler, validate( overAllAuditSummaryValid ), overAllAuditSummary );
|
|
31
|
+
traxAuditRouter.post( '/metrics/re-trigger', isAllowedSessionHandler, validate( reTriggerValidSchema ), isuserEmpDocumentExist, isMappingAuditInputFolderExist, reTrigger );
|
|
32
32
|
|
|
33
33
|
// summary
|
|
34
34
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import auditUserWalletModel from 'tango-api-schema/schema/auditUserWallet.model.js';
|
|
2
|
-
|
|
2
|
+
import empDetectionOutputModel from 'tango-api-schema/schema/empDetectionOutput.model.js';
|
|
3
3
|
|
|
4
4
|
export function createAuditUserWallet( record ) {
|
|
5
5
|
return auditUserWalletModel.create( record );
|
|
@@ -8,3 +8,6 @@ export function createAuditUserWallet( record ) {
|
|
|
8
8
|
export function updateManyAuditUserWallet( query, record ) {
|
|
9
9
|
return auditUserWalletModel.updateMany( query, record, { upsert: true } );
|
|
10
10
|
};
|
|
11
|
+
export function createempDetectionOutput( query, field, option ) {
|
|
12
|
+
return empDetectionOutputModel.updateOne( query, field, option );
|
|
13
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
2
|
import empDetectionOutputModel from 'tango-api-schema/schema/empDetectionOutput.model.js';
|
|
3
|
-
export function
|
|
4
|
-
return empDetectionOutputModel.
|
|
3
|
+
export function updateOneEmpDetectionOutput( query, record, upsert ) {
|
|
4
|
+
return empDetectionOutputModel.updateOne( query, record, upsert );
|
|
5
5
|
}
|
|
@@ -5,9 +5,14 @@ export function aggregateStoreEmpDetection( query ) {
|
|
|
5
5
|
return storeEmpDetectionModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
export function findOneStoreEmpDetection( query ) {
|
|
9
|
+
return storeEmpDetectionModel.findOne( query );
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
export function updateOneStoreEmpDetection( query, record ) {
|
|
9
13
|
return storeEmpDetectionModel.updateOne( query, { $set: record } );
|
|
10
14
|
}
|
|
15
|
+
|
|
11
16
|
export function updateManyStoreEmpDetection( query, record ) {
|
|
12
17
|
return storeEmpDetectionModel.updateMany( query, { $set: record }, { upsert: true } );
|
|
13
18
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { logger } from 'tango-app-api-middleware';
|
|
1
|
+
import { checkFileExist, logger } from 'tango-app-api-middleware';
|
|
2
2
|
import { findOneBinaryAudit, updateOneBinaryAuditModel } from '../service/binaryAudit.service.js';
|
|
3
3
|
import { findOneUserEmpDetection } from '../service/userEmpDetection.service.js';
|
|
4
4
|
import { findOneTraxAuditData } from '../service/traxAuditData.service.js';
|
|
5
|
+
import { findOneStoreEmpDetection } from '../service/storeEmpDetection.service.js';
|
|
5
6
|
|
|
6
7
|
export async function validateUserEmpDetection( req, res, next ) {
|
|
7
8
|
try {
|
|
@@ -116,3 +117,48 @@ export async function isTraxAuditDocumentExist( req, res, next ) {
|
|
|
116
117
|
return res.sendError( err, 500 );
|
|
117
118
|
}
|
|
118
119
|
}
|
|
120
|
+
|
|
121
|
+
export async function isuserEmpDocumentExist( req, res, next ) {
|
|
122
|
+
try {
|
|
123
|
+
const inputData = req.body;
|
|
124
|
+
const query={
|
|
125
|
+
storeId: inputData.storeId,
|
|
126
|
+
fileDate: inputData.fileDate,
|
|
127
|
+
moduleType: inputData.moduleType,
|
|
128
|
+
};
|
|
129
|
+
const auditInfo = await findOneStoreEmpDetection( query );
|
|
130
|
+
if ( auditInfo ) {
|
|
131
|
+
const sqs = await findOneTraxAuditData( query, { sqs: 1 } );
|
|
132
|
+
req.sqs = sqs.sqs.Body;
|
|
133
|
+
req.audit = auditInfo;
|
|
134
|
+
return next();
|
|
135
|
+
} else {
|
|
136
|
+
return res.sendError( 'No audited Record', 400 );
|
|
137
|
+
}
|
|
138
|
+
} catch ( error ) {
|
|
139
|
+
const err = error.message || 'Internal Server Error';
|
|
140
|
+
logger.error( { error: error, message: req.body, function: 'isAuditFileExist' } );
|
|
141
|
+
return res.sendError( err, 500 );
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
export async function isMappingAuditInputFolderExist( req, res, next ) {
|
|
147
|
+
try {
|
|
148
|
+
// const inputData = req.method === 'POST' ? req.body : req.query;
|
|
149
|
+
const params={
|
|
150
|
+
Bucket: req.sqs.inputBucketName,
|
|
151
|
+
Key: req.sqs.folderPath.replace( /\/$/, '' ),
|
|
152
|
+
};
|
|
153
|
+
const isExist = await checkFileExist( params );
|
|
154
|
+
if ( isExist ) {
|
|
155
|
+
next();
|
|
156
|
+
} else {
|
|
157
|
+
return res.sendError( `Audit Input folder not available : ${req.sqs.folderPath}`, 400 );
|
|
158
|
+
}
|
|
159
|
+
} catch ( error ) {
|
|
160
|
+
const err = error.message || 'Internal Server Error';
|
|
161
|
+
logger.error( { error: error, message: req.query, function: 'isAuidtInputFolderExist' } );
|
|
162
|
+
return res.sendError( err, 500 );
|
|
163
|
+
}
|
|
164
|
+
}
|