tango-app-api-audit 3.4.11-alpha.16 → 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 +365 -323
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"
|
|
@@ -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
|
} );
|
|
@@ -3909,365 +3911,405 @@ export async function getUserCredit( req, res ) {
|
|
|
3909
3911
|
|
|
3910
3912
|
export async function getUserAuditCount( req, res ) {
|
|
3911
3913
|
try {
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
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
|
+
},
|
|
3926
3939
|
},
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3940
|
+
{
|
|
3941
|
+
$group: {
|
|
3942
|
+
_id: null,
|
|
3943
|
+
userList: { $push: '$userId' },
|
|
3944
|
+
},
|
|
3932
3945
|
},
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3946
|
+
{
|
|
3947
|
+
$project: {
|
|
3948
|
+
_id: 0,
|
|
3949
|
+
userList: 1,
|
|
3950
|
+
},
|
|
3938
3951
|
},
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
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
|
+
},
|
|
3953
3966
|
},
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
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
|
+
},
|
|
3983
3996
|
},
|
|
3984
|
-
|
|
3985
|
-
];
|
|
3997
|
+
];
|
|
3986
3998
|
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3999
|
+
// const storeDataQuery= [
|
|
4000
|
+
// {
|
|
4001
|
+
// $match: {
|
|
4002
|
+
// fileDate: { $eq: fileDate },
|
|
4003
|
+
// },
|
|
4004
|
+
// },
|
|
4005
|
+
// {
|
|
4006
|
+
// $project: {
|
|
3995
4007
|
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4008
|
+
// trafficFilesCount: { $cond: [
|
|
4009
|
+
// { $eq: [ '$moduleType', 'traffic' ] }, '$totalFilesCount', '$$REMOVE',
|
|
4010
|
+
// ] },
|
|
4011
|
+
// zoneFilesCount: { $cond: [
|
|
4012
|
+
// { $eq: [ '$moduleType', 'zone' ] }, '$totalFilesCount', '$$REMOVE',
|
|
4013
|
+
// ] },
|
|
4002
4014
|
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
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 );
|
|
4021
4033
|
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
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;
|
|
4031
4043
|
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
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
|
+
},
|
|
4042
4055
|
},
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
$set: { minimumTarget: minimumTarget, afterCountCredit: afterCountCredit, beforeCreditCal: beforeCreditCal },
|
|
4046
|
-
},
|
|
4047
|
-
{
|
|
4048
|
-
$project: {
|
|
4049
|
-
userId: 1,
|
|
4050
|
-
moduleType: 1,
|
|
4051
|
-
beforeCount: 1,
|
|
4052
|
-
afterCount: 1,
|
|
4053
|
-
timeSpent: 1,
|
|
4054
|
-
fileDate: 1,
|
|
4055
|
-
fileDateISO: 1,
|
|
4056
|
-
minimumTarget: 1,
|
|
4057
|
-
afterCountCredit: 1,
|
|
4058
|
-
totalEarn: { $ifNull: [ 0, 0 ] },
|
|
4059
|
-
singleImageAmount: { $ifNull: [ '$beforeCreditCal', 0 ] },
|
|
4060
|
-
totalReducedAmount: { $ifNull: [ 0, 0 ] },
|
|
4061
|
-
totalCredit: { $ifNull: [ 0, 0 ] },
|
|
4062
|
-
deductionBytimeSpent: { $ifNull: [ 0, 0 ] },
|
|
4063
|
-
deductionByMinimumTarget: { $ifNull: [ 0, 0 ] },
|
|
4056
|
+
{
|
|
4057
|
+
$set: { minimumTarget: minimumTarget, afterCountCredit: afterCountCredit, beforeCreditCal: beforeCreditCal },
|
|
4064
4058
|
},
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
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
|
+
},
|
|
4085
4079
|
},
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
afterCountCredit: afterCountCredit,
|
|
4111
|
-
totalEarn: { $add: [ { $multiply: [ '$totalBeforeCount', '$singleImageAmount' ] }, 136 ] },
|
|
4112
|
-
deductionBytimeSpent: 1,
|
|
4113
|
-
deductionByMinimumTarget: 1,
|
|
4114
|
-
mappingperc: { $multiply: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 100 ] },
|
|
4115
|
-
deductionByMapping: { $cond: [ { $and: [
|
|
4116
|
-
{ $gte: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.4 ] }, { $lte: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] },
|
|
4117
|
-
] }, 0,
|
|
4118
|
-
{
|
|
4119
|
-
$cond: [ { $gt: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] },
|
|
4120
|
-
{ $multiply: [ { $subtract: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] }, 136 ] },
|
|
4121
|
-
{ $multiply: [ { $subtract: [ 0.4, { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] } ] }, 136 ] },
|
|
4122
|
-
],
|
|
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' },
|
|
4123
4104
|
},
|
|
4124
|
-
] },
|
|
4125
|
-
totalReducedAmount: 1,
|
|
4126
|
-
totalCredit: 1,
|
|
4127
|
-
|
|
4128
4105
|
},
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
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
|
+
|
|
4145
4149
|
},
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
{ $
|
|
4156
|
-
|
|
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
|
+
] },
|
|
4157
4178
|
|
|
4158
|
-
|
|
4179
|
+
deductionByMinimumTarget:
|
|
4159
4180
|
{ $cond: [
|
|
4160
4181
|
{ $lt: [ '$totalBeforeCount', '$minimumTarget' ] },
|
|
4161
4182
|
{ $multiply: [ reduce, '$totalEarn' ] }, '$deductionByMinimumTarget',
|
|
4162
4183
|
] },
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
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,
|
|
4166
4194
|
|
|
4167
4195
|
|
|
4196
|
+
},
|
|
4168
4197
|
},
|
|
4169
|
-
},
|
|
4170
4198
|
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
{ $concat: [
|
|
4181
|
-
'00:', { $toString: '$minutes' }, ':00',
|
|
4182
|
-
] },
|
|
4183
|
-
{ $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 ] },
|
|
4184
4208
|
{ $concat: [
|
|
4185
|
-
{ $toString: '$
|
|
4209
|
+
'00:', { $toString: '$minutes' }, ':00',
|
|
4186
4210
|
] },
|
|
4187
|
-
{
|
|
4188
|
-
$concat: [
|
|
4189
|
-
{ $toString: '$hours' }, ':',
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
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
|
+
],
|
|
4195
4223
|
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
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
|
+
},
|
|
4210
4245
|
|
|
4246
|
+
},
|
|
4247
|
+
|
|
4248
|
+
},
|
|
4211
4249
|
},
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
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
|
+
},
|
|
4221
4259
|
},
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4260
|
+
{
|
|
4261
|
+
$project: {
|
|
4262
|
+
_id: 0, // Exclude _id if not needed
|
|
4263
|
+
email: 1,
|
|
4264
|
+
userName: 1,
|
|
4265
|
+
},
|
|
4228
4266
|
},
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4267
|
+
],
|
|
4268
|
+
as: 'users',
|
|
4269
|
+
},
|
|
4232
4270
|
},
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
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,
|
|
4258
4297
|
|
|
4298
|
+
},
|
|
4259
4299
|
},
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
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
|
+
}
|
|
4269
4312
|
}
|
|
4270
|
-
return res.sendSuccess( { message: 'Inserted successfully!' } );
|
|
4271
4313
|
} catch ( error ) {
|
|
4272
4314
|
const err = error.message || 'Internal Server Error';
|
|
4273
4315
|
logger.info( { error: error, message: req.body, function: 'getUserAuditCount' } );
|