tango-app-api-audit 3.4.11-alpha.15 → 3.4.11-alpha.17
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 -2
- package/src/controllers/audit.controllers.js +385 -324
- package/src/docs/audit.docs.js +14 -0
- package/src/routes/audit.routes.js +3 -2
- package/src/service/auditUserWallet.service.js +4 -0
- package/src/service/auditUsers.service.js +4 -0
- package/src/validation/audit.validation.js +15 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-audit",
|
|
3
|
-
"version": "3.4.11-alpha.
|
|
3
|
+
"version": "3.4.11-alpha.17",
|
|
4
4
|
"description": "audit & audit metrics apis",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"mongodb": "^6.7.0",
|
|
25
25
|
"nodemon": "^3.1.3",
|
|
26
26
|
"swagger-ui-express": "^5.0.1",
|
|
27
|
-
"tango-api-schema": "^2.1.
|
|
27
|
+
"tango-api-schema": "^2.1.40",
|
|
28
28
|
"tango-app-api-middleware": "^3.1.33",
|
|
29
29
|
"winston": "^3.13.0",
|
|
30
30
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -63,7 +63,7 @@ import {
|
|
|
63
63
|
import { aggregateStoreEmpDetection } from '../service/storeEmpDetection.service.js';
|
|
64
64
|
import { aggregateBinaryAudit } from '../service/binaryAudit.service.js';
|
|
65
65
|
import { aggregateTraxAuditData, findOneTraxAuditData } from '../service/traxAuditData.service.js';
|
|
66
|
-
import { createAuditUserWallet } from '../service/auditUserWallet.service.js';
|
|
66
|
+
import { createAuditUserWallet, findOneAuditUserWallet } from '../service/auditUserWallet.service.js';
|
|
67
67
|
import { aggregateAuditUsers } from '../service/auditUsers.service.js';
|
|
68
68
|
|
|
69
69
|
/* < -- *** Configuration *** --> */
|
|
@@ -324,6 +324,7 @@ export async function getAuditFile( req, res ) {
|
|
|
324
324
|
userId: log.userId,
|
|
325
325
|
moduleType: userDetails[0].moduleType,
|
|
326
326
|
zoneName: userDetails[0].zoneName,
|
|
327
|
+
timeSpent: log.timeSpent,
|
|
327
328
|
};
|
|
328
329
|
const result = {
|
|
329
330
|
junk: log.junk,
|
|
@@ -378,6 +379,7 @@ export async function getAuditFile( req, res ) {
|
|
|
378
379
|
storeName: storeDetails?.storeName,
|
|
379
380
|
address: storeDetails?.address || '',
|
|
380
381
|
count: log.totalCount,
|
|
382
|
+
timeSpent: log.timeSpent,
|
|
381
383
|
file: file,
|
|
382
384
|
isDraft: userDetails[0].isDraft,
|
|
383
385
|
} );
|
|
@@ -3888,367 +3890,426 @@ export async function auditImages( req, res ) {
|
|
|
3888
3890
|
}
|
|
3889
3891
|
}
|
|
3890
3892
|
|
|
3893
|
+
export async function getUserCredit( req, res ) {
|
|
3894
|
+
try {
|
|
3895
|
+
const userId=req.user.email;
|
|
3896
|
+
const getLastDate = await findOneAuditUserWallet( {}, {}, { fileData: -1 } );
|
|
3897
|
+
if ( !getLastDate ) {
|
|
3898
|
+
return res.sendError( 'No records found', 204 );
|
|
3899
|
+
}
|
|
3900
|
+
const getWallet = await findOneAuditUserWallet( { fileDate: getLastDate.fileDate, userEmail: userId }, { totalCredit: 1, fileDate: 1 } );
|
|
3901
|
+
if ( !getWallet ) {
|
|
3902
|
+
return res.sendSuccess( { result: 0 } );
|
|
3903
|
+
}
|
|
3904
|
+
return res.sendSuccess( { result: getWallet, isAuditUser: true } );
|
|
3905
|
+
} catch ( error ) {
|
|
3906
|
+
const err = error.message || 'Internal Server Error';
|
|
3907
|
+
logger.info( { error: error, function: 'getUserCredit' } );
|
|
3908
|
+
return res.sendError( err, 500 );
|
|
3909
|
+
}
|
|
3910
|
+
}
|
|
3911
|
+
|
|
3891
3912
|
export async function getUserAuditCount( req, res ) {
|
|
3892
3913
|
try {
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3914
|
+
for ( let i =4; i<15; i++ ) {
|
|
3915
|
+
const userWallet = JSON.parse( process.env.USER_WALLET );
|
|
3916
|
+
const previousDate = dayjs( new Date() ).subtract( i, 'days' );
|
|
3917
|
+
const fileDate = dayjs( previousDate ).format( 'DD-MM-YYYY' );
|
|
3918
|
+
const configTimeSpentSec = userWallet.minTimeSpentSec; // 18000;
|
|
3919
|
+
// const beforeCountX = userWallet.beforeCountCreditPerc; // 0.0335;
|
|
3920
|
+
// const afterCountY = userWallet.afterCountCreditPerc; // 0.0035;
|
|
3921
|
+
const reduce = userWallet.reductionPerc; // 0.05;
|
|
3922
|
+
const today = new Date();
|
|
3923
|
+
|
|
3924
|
+
// Subtract one day to get the previous day
|
|
3925
|
+
const previousDay = new Date( today );
|
|
3926
|
+
previousDay.setDate( today.getDate() - i );
|
|
3927
|
+
const lateLogin = previousDay;
|
|
3928
|
+
logger.info( { lateLogin1: lateLogin } );
|
|
3929
|
+
lateLogin.setHours( 21, 30, 0, 0 );
|
|
3930
|
+
logger.info( { lateLogin: lateLogin } );
|
|
3931
|
+
const auditUserQuery=[
|
|
3932
|
+
{
|
|
3933
|
+
$match: {
|
|
3934
|
+
$and: [
|
|
3935
|
+
{ type: { $eq: 'consultant' } },
|
|
3936
|
+
{ isActive: { $eq: true } },
|
|
3937
|
+
],
|
|
3938
|
+
},
|
|
3907
3939
|
},
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3940
|
+
{
|
|
3941
|
+
$group: {
|
|
3942
|
+
_id: null,
|
|
3943
|
+
userList: { $push: '$userId' },
|
|
3944
|
+
},
|
|
3913
3945
|
},
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3946
|
+
{
|
|
3947
|
+
$project: {
|
|
3948
|
+
_id: 0,
|
|
3949
|
+
userList: 1,
|
|
3950
|
+
},
|
|
3919
3951
|
},
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3952
|
+
];
|
|
3953
|
+
const auditUserList = await aggregateAuditUsers( auditUserQuery );
|
|
3954
|
+
if ( auditUserList.length==0 ) {
|
|
3955
|
+
return res.sendError( 'No users available', 204 );
|
|
3956
|
+
}
|
|
3957
|
+
const userCountQuery= [
|
|
3958
|
+
{
|
|
3959
|
+
$match: {
|
|
3960
|
+
$and: [
|
|
3961
|
+
{ fileDate: { $eq: fileDate } },
|
|
3962
|
+
{ auditStatus: { $eq: 'completed' } },
|
|
3963
|
+
{ userId: { $in: auditUserList[0].userList } },
|
|
3964
|
+
],
|
|
3965
|
+
},
|
|
3934
3966
|
},
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3967
|
+
// {
|
|
3968
|
+
// $project: {
|
|
3969
|
+
|
|
3970
|
+
// trafficUserCount: { $cond: [
|
|
3971
|
+
// { $eq: [ '$moduleType', 'traffic' ] }, '$userId', '$$REMOVE',
|
|
3972
|
+
// ] },
|
|
3973
|
+
// zoneUserCount: { $cond: [
|
|
3974
|
+
// { $eq: [ '$moduleType', 'zone' ] }, '$userId', '$$REMOVE',
|
|
3975
|
+
// ] },
|
|
3976
|
+
|
|
3977
|
+
// trafficFilesCount: { $cond: [
|
|
3978
|
+
// { $eq: [ '$moduleType', 'traffic' ] }, '$beforeCount', '$$REMOVE',
|
|
3979
|
+
// ] },
|
|
3980
|
+
// zoneFilesCount: { $cond: [
|
|
3981
|
+
// { $eq: [ '$moduleType', 'zone' ] }, '$beforeCount', '$$REMOVE',
|
|
3982
|
+
// ] },
|
|
3983
|
+
|
|
3984
|
+
// },
|
|
3985
|
+
// },
|
|
3986
|
+
{
|
|
3987
|
+
$group: {
|
|
3988
|
+
_id: null,
|
|
3989
|
+
// trafficUserCount: { $addToSet: '$trafficUserCount' },
|
|
3990
|
+
// zoneUserCount: { $addToSet: '$zoneUserCount' },
|
|
3991
|
+
// trafficFilesCount: { $sum: '$trafficFilesCount' },
|
|
3992
|
+
// zoneFilesCount: { $sum: '$zoneFilesCount' },
|
|
3993
|
+
userCount: { $addToSet: '$userId' },
|
|
3994
|
+
filesCount: { $sum: '$beforeCount' },
|
|
3995
|
+
},
|
|
3964
3996
|
},
|
|
3965
|
-
|
|
3966
|
-
];
|
|
3997
|
+
];
|
|
3967
3998
|
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3999
|
+
// const storeDataQuery= [
|
|
4000
|
+
// {
|
|
4001
|
+
// $match: {
|
|
4002
|
+
// fileDate: { $eq: fileDate },
|
|
4003
|
+
// },
|
|
4004
|
+
// },
|
|
4005
|
+
// {
|
|
4006
|
+
// $project: {
|
|
3976
4007
|
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
4008
|
+
// trafficFilesCount: { $cond: [
|
|
4009
|
+
// { $eq: [ '$moduleType', 'traffic' ] }, '$totalFilesCount', '$$REMOVE',
|
|
4010
|
+
// ] },
|
|
4011
|
+
// zoneFilesCount: { $cond: [
|
|
4012
|
+
// { $eq: [ '$moduleType', 'zone' ] }, '$totalFilesCount', '$$REMOVE',
|
|
4013
|
+
// ] },
|
|
3983
4014
|
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4015
|
+
// },
|
|
4016
|
+
// },
|
|
4017
|
+
// {
|
|
4018
|
+
// $group: {
|
|
4019
|
+
// _id: '$moduleType',
|
|
4020
|
+
// trafficFilesCount: { $sum: '$trafficFilesCount' },
|
|
4021
|
+
// zoneFilesCount: { $sum: '$zoneFilesCount' },
|
|
4022
|
+
// },
|
|
4023
|
+
// },
|
|
4024
|
+
// {
|
|
4025
|
+
// $project: {
|
|
4026
|
+
// _id: 0,
|
|
4027
|
+
// trafficFilesCount: { $ifNull: [ '$trafficFilesCount', 0 ] },
|
|
4028
|
+
// zoneFilesCount: { $ifNull: [ '$zoneFilesCount', 0 ] },
|
|
4029
|
+
// },
|
|
4030
|
+
// },
|
|
4031
|
+
// ];
|
|
4032
|
+
const userCount = await aggregateUserAuditCount( userCountQuery );
|
|
4002
4033
|
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4034
|
+
// const totalStoreData = await aggregateAuditStoreData( storeDataQuery );
|
|
4035
|
+
if ( userCount?.length == 0 ) {
|
|
4036
|
+
return res.sendError( 'No Data Found', 204 );
|
|
4037
|
+
}
|
|
4038
|
+
const minimumTarget =userCount[0]?.userCount?.length !== 0 && userCount[0]?.filesCount !==0 ? Math.floor( userCount[0].filesCount/userCount[0].userCount.length ) : 0;
|
|
4039
|
+
// const trafficMinimumTarget =userCount[0]?.trafficUserCount?.length !== 0 && userCount[0]?.trafficFilesCount !==0 ? Math.floor( userCount[0].trafficFilesCount/userCount[0].trafficUserCount.length ) : 0;
|
|
4040
|
+
const beforeCreditCal = 544/minimumTarget;
|
|
4041
|
+
// const beforeCountZone = 544/zoneMinimumTarget; // 0.0035;
|
|
4042
|
+
const afterCountCredit = 136;
|
|
4012
4043
|
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4044
|
+
const query = [
|
|
4045
|
+
{
|
|
4046
|
+
$match: {
|
|
4047
|
+
$and: [
|
|
4048
|
+
{ fileDate: { $eq: fileDate } },
|
|
4049
|
+
{
|
|
4050
|
+
auditStatus: { $eq: 'completed' },
|
|
4051
|
+
},
|
|
4052
|
+
{ userId: { $in: auditUserList[0].userList } },
|
|
4053
|
+
],
|
|
4054
|
+
},
|
|
4023
4055
|
},
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
$set: { minimumTarget: minimumTarget, afterCountCredit: afterCountCredit, beforeCreditCal: beforeCreditCal },
|
|
4027
|
-
},
|
|
4028
|
-
{
|
|
4029
|
-
$project: {
|
|
4030
|
-
userId: 1,
|
|
4031
|
-
moduleType: 1,
|
|
4032
|
-
beforeCount: 1,
|
|
4033
|
-
afterCount: 1,
|
|
4034
|
-
timeSpent: 1,
|
|
4035
|
-
fileDate: 1,
|
|
4036
|
-
fileDateISO: 1,
|
|
4037
|
-
minimumTarget: 1,
|
|
4038
|
-
afterCountCredit: 1,
|
|
4039
|
-
totalEarn: { $ifNull: [ 0, 0 ] },
|
|
4040
|
-
singleImageAmount: { $ifNull: [ '$beforeCreditCal', 0 ] },
|
|
4041
|
-
totalReducedAmount: { $ifNull: [ 0, 0 ] },
|
|
4042
|
-
totalCredit: { $ifNull: [ 0, 0 ] },
|
|
4043
|
-
deductionBytimeSpent: { $ifNull: [ 0, 0 ] },
|
|
4044
|
-
deductionByMinimumTarget: { $ifNull: [ 0, 0 ] },
|
|
4056
|
+
{
|
|
4057
|
+
$set: { minimumTarget: minimumTarget, afterCountCredit: afterCountCredit, beforeCreditCal: beforeCreditCal },
|
|
4045
4058
|
},
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4059
|
+
{
|
|
4060
|
+
$project: {
|
|
4061
|
+
userId: 1,
|
|
4062
|
+
moduleType: 1,
|
|
4063
|
+
beforeCount: 1,
|
|
4064
|
+
afterCount: 1,
|
|
4065
|
+
timeSpent: 1,
|
|
4066
|
+
fileDate: 1,
|
|
4067
|
+
fileDateISO: 1,
|
|
4068
|
+
minimumTarget: 1,
|
|
4069
|
+
afterCountCredit: 1,
|
|
4070
|
+
totalEarn: { $ifNull: [ 0, 0 ] },
|
|
4071
|
+
singleImageAmount: { $ifNull: [ '$beforeCreditCal', 0 ] },
|
|
4072
|
+
totalReducedAmount: { $ifNull: [ 0, 0 ] },
|
|
4073
|
+
totalCredit: { $ifNull: [ 0, 0 ] },
|
|
4074
|
+
deductionBytimeSpent: { $ifNull: [ 0, 0 ] },
|
|
4075
|
+
deductionByMinimumTarget: { $ifNull: [ 0, 0 ] },
|
|
4076
|
+
deductionByLateLogin: { $ifNull: [ 0, 0 ] },
|
|
4077
|
+
startTime: 1,
|
|
4078
|
+
},
|
|
4066
4079
|
},
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
afterCountCredit: afterCountCredit,
|
|
4092
|
-
totalEarn: { $add: [ { $multiply: [ '$totalBeforeCount', '$singleImageAmount' ] }, 136 ] },
|
|
4093
|
-
deductionBytimeSpent: 1,
|
|
4094
|
-
deductionByMinimumTarget: 1,
|
|
4095
|
-
mappingperc: { $multiply: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 100 ] },
|
|
4096
|
-
deductionByMapping: { $cond: [ { $and: [
|
|
4097
|
-
{ $gte: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.4 ] }, { $lte: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] },
|
|
4098
|
-
] }, 0,
|
|
4099
|
-
{
|
|
4100
|
-
$cond: [ { $gt: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] },
|
|
4101
|
-
{ $multiply: [ { $subtract: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] }, 136 ] },
|
|
4102
|
-
{ $multiply: [ { $subtract: [ 0.4, { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] } ] }, 136 ] },
|
|
4103
|
-
],
|
|
4080
|
+
{
|
|
4081
|
+
$sort: { startTime: 1 },
|
|
4082
|
+
},
|
|
4083
|
+
{
|
|
4084
|
+
$group: {
|
|
4085
|
+
_id: { user: '$userId' },
|
|
4086
|
+
totalCount: { $sum: 1 },
|
|
4087
|
+
moduleType: { $first: '$moduleType' },
|
|
4088
|
+
totalBeforeCount: { $sum: '$beforeCount' },
|
|
4089
|
+
totalAfterCount: { $sum: '$afterCount' },
|
|
4090
|
+
totalTimeSpent: { $sum: '$timeSpent' },
|
|
4091
|
+
fileDate: { $first: '$fileDate' },
|
|
4092
|
+
fileDateISO: { $first: '$fileDateISO' },
|
|
4093
|
+
userId: { $first: '$userId' },
|
|
4094
|
+
minimumTarget: { $first: '$minimumTarget' },
|
|
4095
|
+
afterCountCredit: { $first: '$afterCountCredit' },
|
|
4096
|
+
totalEarn: { $first: '$totalEarn' },
|
|
4097
|
+
totalReducedAmount: { $first: '$totalReducedAmount' },
|
|
4098
|
+
totalCredit: { $first: '$totalCredit' },
|
|
4099
|
+
deductionByMinimumTarget: { $first: '$deductionByMinimumTarget' },
|
|
4100
|
+
deductionBytimeSpent: { $first: '$deductionBytimeSpent' },
|
|
4101
|
+
singleImageAmount: { $first: '$singleImageAmount' },
|
|
4102
|
+
startTime: { $first: '$startTime' },
|
|
4103
|
+
deductionByLateLogin: { $first: '$deductionByLateLogin' },
|
|
4104
4104
|
},
|
|
4105
|
-
] },
|
|
4106
|
-
totalReducedAmount: 1,
|
|
4107
|
-
totalCredit: 1,
|
|
4108
|
-
|
|
4109
4105
|
},
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4106
|
+
{
|
|
4107
|
+
$project: {
|
|
4108
|
+
totalCount: 1,
|
|
4109
|
+
userId: 1,
|
|
4110
|
+
moduleType: 1,
|
|
4111
|
+
totalBeforeCount: 1,
|
|
4112
|
+
totalAfterCount: 1,
|
|
4113
|
+
totalTimeSpent: 1,
|
|
4114
|
+
fileDate: 1,
|
|
4115
|
+
fileDateISO: 1,
|
|
4116
|
+
minimumTarget: 1,
|
|
4117
|
+
singleImageAmount: 1,
|
|
4118
|
+
beforeCountCredit: { $multiply: [ '$totalBeforeCount', '$singleImageAmount' ] },
|
|
4119
|
+
// afterCountCredit: { $cond: [ { $and: [
|
|
4120
|
+
// { $gte: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.4 ] }, { $lte: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] },
|
|
4121
|
+
// ] }, 136,
|
|
4122
|
+
// {
|
|
4123
|
+
// $cond: [ { $gt: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] },
|
|
4124
|
+
// { $subtract: [ 136, { $multiply: [ { $subtract: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] }, 136 ] } ] },
|
|
4125
|
+
// { $subtract: [ 136, { $multiply: [ { $subtract: [ 0.4, { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] } ] }, 136 ] } ] },
|
|
4126
|
+
// ],
|
|
4127
|
+
// },
|
|
4128
|
+
// ] },
|
|
4129
|
+
afterCountCredit: afterCountCredit,
|
|
4130
|
+
totalEarn: { $add: [ { $multiply: [ '$totalBeforeCount', '$singleImageAmount' ] }, 136 ] },
|
|
4131
|
+
deductionBytimeSpent: 1,
|
|
4132
|
+
deductionByMinimumTarget: 1,
|
|
4133
|
+
mappingperc: { $multiply: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 100 ] },
|
|
4134
|
+
deductionByMapping: { $cond: [ { $and: [
|
|
4135
|
+
{ $gte: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.4 ] }, { $lte: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] },
|
|
4136
|
+
] }, 0,
|
|
4137
|
+
{
|
|
4138
|
+
$cond: [ { $gt: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] },
|
|
4139
|
+
{ $multiply: [ { $subtract: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] }, 136 ] },
|
|
4140
|
+
{ $multiply: [ { $subtract: [ 0.4, { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] } ] }, 136 ] },
|
|
4141
|
+
],
|
|
4142
|
+
},
|
|
4143
|
+
] },
|
|
4144
|
+
deductionByLateLogin: 1,
|
|
4145
|
+
totalReducedAmount: 1,
|
|
4146
|
+
totalCredit: 1,
|
|
4147
|
+
startTime: 1,
|
|
4148
|
+
|
|
4126
4149
|
},
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
{ $
|
|
4137
|
-
|
|
4150
|
+
},
|
|
4151
|
+
{
|
|
4152
|
+
$project: {
|
|
4153
|
+
totalCount: 1,
|
|
4154
|
+
userId: 1,
|
|
4155
|
+
moduleType: 1,
|
|
4156
|
+
totalBeforeCount: 1,
|
|
4157
|
+
totalAfterCount: 1,
|
|
4158
|
+
totalTimeSpent: 1,
|
|
4159
|
+
hours: { $floor: { $divide: [ '$totalTimeSpent', 3600 ] } },
|
|
4160
|
+
minutes: {
|
|
4161
|
+
$floor: {
|
|
4162
|
+
$divide: [
|
|
4163
|
+
{ $mod: [ '$totalTimeSpent', 3600 ] }, // Get remaining minutes after hours
|
|
4164
|
+
60,
|
|
4165
|
+
] },
|
|
4166
|
+
},
|
|
4167
|
+
fileDate: 1,
|
|
4168
|
+
fileDateISO: 1,
|
|
4169
|
+
minimumTarget: 1,
|
|
4170
|
+
singleImageAmount: 1,
|
|
4171
|
+
beforeCountCredit: 1,
|
|
4172
|
+
afterCountCredit: 1,
|
|
4173
|
+
totalEarn: 1,
|
|
4174
|
+
deductionBytimeSpent: { $cond: [
|
|
4175
|
+
{ $lt: [ '$totalTimeSpent', configTimeSpentSec ] },
|
|
4176
|
+
{ $multiply: [ reduce, '$totalEarn' ] }, '$deductionBytimeSpent',
|
|
4177
|
+
] },
|
|
4138
4178
|
|
|
4139
|
-
|
|
4179
|
+
deductionByMinimumTarget:
|
|
4140
4180
|
{ $cond: [
|
|
4141
4181
|
{ $lt: [ '$totalBeforeCount', '$minimumTarget' ] },
|
|
4142
4182
|
{ $multiply: [ reduce, '$totalEarn' ] }, '$deductionByMinimumTarget',
|
|
4143
4183
|
] },
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4184
|
+
deductionByLateLogin: {
|
|
4185
|
+
$cond: [
|
|
4186
|
+
{ $gt: [ '$startTime', lateLogin ] },
|
|
4187
|
+
{ $multiply: [ reduce, '$totalEarn' ] }, '$deductionByLateLogin',
|
|
4188
|
+
],
|
|
4189
|
+
},
|
|
4190
|
+
mappingperc: 1,
|
|
4191
|
+
deductionByMapping: 1,
|
|
4192
|
+
totalCredit: { $subtract: [ '$totalEarn', '$totalReducedAmount' ] },
|
|
4193
|
+
startTime: 1,
|
|
4147
4194
|
|
|
4148
4195
|
|
|
4196
|
+
},
|
|
4149
4197
|
},
|
|
4150
|
-
},
|
|
4151
4198
|
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
{ $concat: [
|
|
4162
|
-
'00:', { $toString: '$minutes' }, ':00',
|
|
4163
|
-
] },
|
|
4164
|
-
{ $cond: [ { $eq: [ '$minutes', 0 ] },
|
|
4199
|
+
{
|
|
4200
|
+
$project: {
|
|
4201
|
+
totalCount: 1,
|
|
4202
|
+
userId: 1,
|
|
4203
|
+
moduleType: 1,
|
|
4204
|
+
totalBeforeCount: 1,
|
|
4205
|
+
totalAfterCount: 1,
|
|
4206
|
+
totalTimeSpent: {
|
|
4207
|
+
$cond: [ { $eq: [ '$hours', 0 ] },
|
|
4165
4208
|
{ $concat: [
|
|
4166
|
-
{ $toString: '$
|
|
4209
|
+
'00:', { $toString: '$minutes' }, ':00',
|
|
4167
4210
|
] },
|
|
4168
|
-
{
|
|
4169
|
-
$concat: [
|
|
4170
|
-
{ $toString: '$hours' }, ':',
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4211
|
+
{ $cond: [ { $eq: [ '$minutes', 0 ] },
|
|
4212
|
+
{ $concat: [
|
|
4213
|
+
{ $toString: '$hours' }, ':00:00',
|
|
4214
|
+
] },
|
|
4215
|
+
{
|
|
4216
|
+
$concat: [
|
|
4217
|
+
{ $toString: '$hours' }, ':',
|
|
4218
|
+
{ $toString: '$minutes' }, ':00',
|
|
4219
|
+
],
|
|
4220
|
+
},
|
|
4221
|
+
] },
|
|
4222
|
+
],
|
|
4176
4223
|
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4224
|
+
},
|
|
4225
|
+
fileDate: 1,
|
|
4226
|
+
fileDateISO: 1,
|
|
4227
|
+
minimumTarget: 1,
|
|
4228
|
+
beforeCountCredit: 1,
|
|
4229
|
+
afterCountCredit: 1,
|
|
4230
|
+
totalEarn: 1,
|
|
4231
|
+
deductionByMinimumTarget: 1,
|
|
4232
|
+
singleImageAmount: 1,
|
|
4233
|
+
deductionBytimeSpent: 1,
|
|
4234
|
+
mappingperc: 1,
|
|
4235
|
+
deductionByMapping: 1,
|
|
4236
|
+
totalCredit: { $subtract: [ '$totalEarn', '$totalReducedAmount' ] },
|
|
4237
|
+
totalReducedAmount: { $round: [ { $add: [ '$deductionBytimeSpent', '$deductionByMinimumTarget', '$deductionByMapping', '$deductionByLateLogin' ] }, 2 ] },
|
|
4238
|
+
deductionByLateLogin: 1,
|
|
4239
|
+
startTime: {
|
|
4240
|
+
$dateToString: {
|
|
4241
|
+
format: '%H:%M:%S',
|
|
4242
|
+
date: '$startTime',
|
|
4243
|
+
timezone: 'Asia/Kolkata',
|
|
4244
|
+
},
|
|
4191
4245
|
|
|
4246
|
+
},
|
|
4247
|
+
|
|
4248
|
+
},
|
|
4192
4249
|
},
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4250
|
+
{
|
|
4251
|
+
$lookup: {
|
|
4252
|
+
from: 'users',
|
|
4253
|
+
let: { userId: '$userId' }, // Assuming userId is the linking field
|
|
4254
|
+
pipeline: [
|
|
4255
|
+
{
|
|
4256
|
+
$match: {
|
|
4257
|
+
$expr: { $eq: [ '$_id', '$$userId' ] },
|
|
4258
|
+
},
|
|
4202
4259
|
},
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4260
|
+
{
|
|
4261
|
+
$project: {
|
|
4262
|
+
_id: 0, // Exclude _id if not needed
|
|
4263
|
+
email: 1,
|
|
4264
|
+
userName: 1,
|
|
4265
|
+
},
|
|
4209
4266
|
},
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4267
|
+
],
|
|
4268
|
+
as: 'users',
|
|
4269
|
+
},
|
|
4213
4270
|
},
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4271
|
+
{ $unwind: { path: '$users', preserveNullAndEmptyArrays: true } },
|
|
4272
|
+
{
|
|
4273
|
+
$project: {
|
|
4274
|
+
_id: 0,
|
|
4275
|
+
totalFilesCount: { $round: [ '$totalCount', 2 ] },
|
|
4276
|
+
moduleType: 1,
|
|
4277
|
+
totalAfterCount: { $round: [ '$totalAfterCount', 2 ] },
|
|
4278
|
+
totalBeforeCount: { $round: [ '$totalBeforeCount', 2 ] },
|
|
4279
|
+
timeSpent: '$totalTimeSpent',
|
|
4280
|
+
fileDate: 1,
|
|
4281
|
+
fileDateISO: 1,
|
|
4282
|
+
beforeCountCredit: 1,
|
|
4283
|
+
afterCountCredit: 1,
|
|
4284
|
+
totalEarn: { $round: [ '$totalEarn', 2 ] },
|
|
4285
|
+
minimumTarget: 1,
|
|
4286
|
+
singleImageAmount: 1,
|
|
4287
|
+
deductionByMinimumTarget: { $round: [ '$deductionByMinimumTarget', 2 ] },
|
|
4288
|
+
deductionBytimeSpent: { $round: [ '$deductionBytimeSpent', 2 ] },
|
|
4289
|
+
mappingperc: 1,
|
|
4290
|
+
deductionByMapping: 1,
|
|
4291
|
+
totalReducedAmount: 1,
|
|
4292
|
+
totalCredit: { $round: [ { $subtract: [ '$totalEarn', '$totalReducedAmount' ] }, 2 ] },
|
|
4293
|
+
userEmail: '$users.email', // Access first element from array
|
|
4294
|
+
userName: '$users.userName', // Access first element from array,
|
|
4295
|
+
startTime: 1,
|
|
4296
|
+
deductionByLateLogin: 1,
|
|
4239
4297
|
|
|
4298
|
+
},
|
|
4240
4299
|
},
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4300
|
+
];
|
|
4301
|
+
const consolidatedData = await aggregateUserAuditCount( query );
|
|
4302
|
+
if ( consolidatedData.length == 0 ) {
|
|
4303
|
+
return res.sendError( 'No Data found', 204 );
|
|
4304
|
+
}
|
|
4305
|
+
const result = await createAuditUserWallet( consolidatedData );
|
|
4306
|
+
if ( result.length == 0 ) {
|
|
4307
|
+
return res.sendError( 'No Record Inserted', 500 );
|
|
4308
|
+
}
|
|
4309
|
+
if ( i == 14 ) {
|
|
4310
|
+
return res.sendSuccess( { message: 'Inserted successfully!' } );
|
|
4311
|
+
}
|
|
4250
4312
|
}
|
|
4251
|
-
return res.sendSuccess( { message: 'Inserted successfully!' } );
|
|
4252
4313
|
} catch ( error ) {
|
|
4253
4314
|
const err = error.message || 'Internal Server Error';
|
|
4254
4315
|
logger.info( { error: error, message: req.body, function: 'getUserAuditCount' } );
|
package/src/docs/audit.docs.js
CHANGED
|
@@ -544,6 +544,20 @@ export const auditDocs = {
|
|
|
544
544
|
},
|
|
545
545
|
},
|
|
546
546
|
},
|
|
547
|
+
'/v3/audit/get-user-credit': {
|
|
548
|
+
get: {
|
|
549
|
+
tags: [ 'Audit User Wallet' ],
|
|
550
|
+
description: 'Get single past date credit',
|
|
551
|
+
operationId: 'get-user-credit',
|
|
552
|
+
responses: {
|
|
553
|
+
200: { description: 'Successful' },
|
|
554
|
+
401: { description: 'Unauthorized User' },
|
|
555
|
+
422: { description: 'Field Error' },
|
|
556
|
+
500: { description: 'Server Error' },
|
|
557
|
+
204: { description: 'Not Found' },
|
|
558
|
+
},
|
|
559
|
+
},
|
|
560
|
+
},
|
|
547
561
|
'/v3/audit/get-user-audit-count': {
|
|
548
562
|
get: {
|
|
549
563
|
tags: [ 'Audit User Wallet' ],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
|
-
import { isAuditDocumentExist, isAuditInputFolderExist, isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
|
|
2
|
+
import { isAuditDocumentExist, isAuditInputFolderExist, isAuditUser, 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, auditViewLogs } 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, getUserCredit } 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();
|
|
@@ -37,6 +37,7 @@ auditRouter.post( '/metrics/overview-table', isAllowedSessionHandler, validate(
|
|
|
37
37
|
auditRouter.get( '/total-not-assigned-count', isAllowedSessionHandler, totalNotAssignedCount );
|
|
38
38
|
|
|
39
39
|
// audit user wallet
|
|
40
|
+
auditRouter.get( '/get-user-credit', isAllowedSessionHandler, isAuditUser, getUserCredit );
|
|
40
41
|
auditRouter.get( '/get-user-audit-count', isAllowedSessionHandler, getUserAuditCount );
|
|
41
42
|
auditRouter.get( '/get-user-audit-count-mtd', isAllowedSessionHandler, getUserAuditCountMTD );
|
|
42
43
|
|
|
@@ -5,6 +5,10 @@ export function createAuditUserWallet( record ) {
|
|
|
5
5
|
return auditUserWalletModel.create( record );
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
+
export function findOneAuditUserWallet( record, fields, sort = { createdAt: -1 } ) {
|
|
9
|
+
return auditUserWalletModel.findOne( record, fields ).sort( sort );
|
|
10
|
+
};
|
|
11
|
+
|
|
8
12
|
export function updateManyAuditUserWallet( query, record ) {
|
|
9
13
|
return auditUserWalletModel.updateMany( query, record, { upsert: true } );
|
|
10
14
|
};
|
|
@@ -3,3 +3,7 @@ import auditUsersModel from 'tango-api-schema/schema/auditUsers.model.js';
|
|
|
3
3
|
export function aggregateAuditUsers( query ) {
|
|
4
4
|
return auditUsersModel.aggregate( query );
|
|
5
5
|
};
|
|
6
|
+
|
|
7
|
+
export function findOneAuditUsers( query, fields ) {
|
|
8
|
+
return auditUsersModel.findOne( query, fields );
|
|
9
|
+
};
|
|
@@ -2,6 +2,7 @@ import { checkFileExist, chunkArray, getJsonFileData, getObject, getQueueUrl, li
|
|
|
2
2
|
import { findOneUserAudit } from '../service/userAudit.service.js';
|
|
3
3
|
import { findOneStoreAudit } from '../service/storeAudit.service.js';
|
|
4
4
|
import AdmZip from 'adm-zip';
|
|
5
|
+
import { findOneAuditUsers } from '../service/auditUsers.service.js';
|
|
5
6
|
|
|
6
7
|
export async function isExistsQueue( req, res, next ) {
|
|
7
8
|
try {
|
|
@@ -333,4 +334,18 @@ export async function getAuditFilterData( data ) {
|
|
|
333
334
|
}
|
|
334
335
|
}
|
|
335
336
|
|
|
337
|
+
export async function isAuditUser( req, res, next ) {
|
|
338
|
+
try {
|
|
339
|
+
const userEmail = req.user?.email;
|
|
340
|
+
const getAuditUser = await findOneAuditUsers( { email: userEmail, isActive: true } );
|
|
341
|
+
if ( !getAuditUser ) {
|
|
342
|
+
return res.sendSuccess( { result: 0, isAuditUser: false } );
|
|
343
|
+
}
|
|
344
|
+
return next();
|
|
345
|
+
} catch ( error ) {
|
|
346
|
+
const err = error.message || 'Internal Server Error';
|
|
347
|
+
logger.error( { error: error, function: 'isAuditUser' } );
|
|
348
|
+
return res.sendError( err, 500 );
|
|
349
|
+
}
|
|
350
|
+
}
|
|
336
351
|
|