tango-app-api-audit 3.4.31 → 3.4.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-audit",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.33",
|
|
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.2.
|
|
27
|
+
"tango-api-schema": "^2.2.19",
|
|
28
28
|
"tango-app-api-middleware": "^3.1.48",
|
|
29
29
|
"winston": "^3.13.0",
|
|
30
30
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -63,8 +63,9 @@ 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, findOneAuditUserWallet } from '../service/auditUserWallet.service.js';
|
|
67
|
-
import {
|
|
66
|
+
import { bulkWriteAuditUserWallet, createAuditUserWallet, findOneAuditUserWallet } from '../service/auditUserWallet.service.js';
|
|
67
|
+
import { updateOneAuditUsers } from '../service/auditUsers.service.js';
|
|
68
|
+
// import { aggregateAuditUsers } from '../service/auditUsers.service.js';
|
|
68
69
|
|
|
69
70
|
/* < -- *** Configuration *** --> */
|
|
70
71
|
|
|
@@ -3938,61 +3939,161 @@ export async function getUserCredit( req, res ) {
|
|
|
3938
3939
|
|
|
3939
3940
|
export async function getUserAuditCount( req, res ) {
|
|
3940
3941
|
try {
|
|
3941
|
-
|
|
3942
|
-
|
|
3942
|
+
const userWallet = JSON.parse( process.env.USER_WALLET );
|
|
3943
|
+
const today = new Date();
|
|
3943
3944
|
|
|
3944
|
-
//
|
|
3945
|
-
|
|
3945
|
+
// Subtract one day to get the previous day
|
|
3946
|
+
const previousDay = new Date( today );
|
|
3947
|
+
previousDay.setDate( today.getDate() - 1 );
|
|
3948
|
+
const lateLogin = previousDay;
|
|
3949
|
+
lateLogin.setHours( 21, 30, 0, 0 );
|
|
3946
3950
|
|
|
3947
|
-
//
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
//
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3951
|
+
// Get yesterday's date
|
|
3952
|
+
const yesterday = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
|
|
3953
|
+
|
|
3954
|
+
// Get the first day of the current month
|
|
3955
|
+
const firstDateOfMonth = new Date( today.getFullYear(), today.getMonth(), 1 );
|
|
3956
|
+
|
|
3957
|
+
// Calculate the difference in days
|
|
3958
|
+
const differenceInDays = ( yesterday.getDate() - firstDateOfMonth.getDate() );
|
|
3959
|
+
logger.info( { differenceInDays: differenceInDays } );
|
|
3960
|
+
|
|
3961
|
+
const auditUserQuery=[
|
|
3962
|
+
{
|
|
3963
|
+
$match: {
|
|
3964
|
+
$and: [
|
|
3965
|
+
{ tangoUserType: { $eq: 'audit' } },
|
|
3966
|
+
{ isActive: { $eq: true } },
|
|
3967
|
+
],
|
|
3968
|
+
},
|
|
3969
|
+
},
|
|
3970
|
+
{
|
|
3971
|
+
$group: {
|
|
3972
|
+
_id: null,
|
|
3973
|
+
userList: { $push: '$_id' },
|
|
3974
|
+
},
|
|
3975
|
+
},
|
|
3976
|
+
{
|
|
3977
|
+
$project: {
|
|
3978
|
+
_id: 0,
|
|
3979
|
+
userList: 1,
|
|
3980
|
+
},
|
|
3981
|
+
},
|
|
3982
|
+
];
|
|
3983
|
+
const auditUserList = await aggregateUser( auditUserQuery );
|
|
3984
|
+
if ( auditUserList.length==0 ) {
|
|
3985
|
+
return res.sendError( 'No users available', 204 );
|
|
3986
|
+
}
|
|
3987
|
+
|
|
3988
|
+
const lateLoginQuery =[
|
|
3989
|
+
{
|
|
3990
|
+
$match: {
|
|
3991
|
+
$and: [
|
|
3992
|
+
{ fileDate: { $eq: dayjs( yesterday ).format( 'DD-MM-YYYY' ) } },
|
|
3993
|
+
{
|
|
3994
|
+
auditStatus: { $eq: 'completed' },
|
|
3995
|
+
},
|
|
3996
|
+
{ userId: { $in: auditUserList[0].userList } },
|
|
3997
|
+
],
|
|
3998
|
+
},
|
|
3999
|
+
},
|
|
4000
|
+
{
|
|
4001
|
+
$sort: {
|
|
4002
|
+
startTime: 1,
|
|
4003
|
+
},
|
|
4004
|
+
},
|
|
4005
|
+
{
|
|
4006
|
+
$group: {
|
|
4007
|
+
_id: '$userId',
|
|
4008
|
+
userId: { $first: '$userId' },
|
|
4009
|
+
startTime: { $first: '$startTime' },
|
|
4010
|
+
fileDate: { $first: '$fileDate' },
|
|
4011
|
+
},
|
|
4012
|
+
},
|
|
4013
|
+
{
|
|
4014
|
+
$lookup: {
|
|
4015
|
+
from: 'users',
|
|
4016
|
+
let: { userId: '$userId' }, // Assuming userId is the linking field
|
|
4017
|
+
pipeline: [
|
|
4018
|
+
{
|
|
4019
|
+
$match: {
|
|
4020
|
+
$expr: { $eq: [ '$_id', '$$userId' ] },
|
|
4021
|
+
},
|
|
4022
|
+
},
|
|
4023
|
+
{
|
|
4024
|
+
$project: {
|
|
4025
|
+
_id: 0, // Exclude _id if not needed
|
|
4026
|
+
email: 1,
|
|
4027
|
+
userName: 1,
|
|
4028
|
+
},
|
|
4029
|
+
},
|
|
4030
|
+
],
|
|
4031
|
+
as: 'users',
|
|
4032
|
+
},
|
|
4033
|
+
},
|
|
4034
|
+
{ $unwind: { path: '$users', preserveNullAndEmptyArrays: true } },
|
|
4035
|
+
|
|
4036
|
+
{
|
|
4037
|
+
$project: {
|
|
4038
|
+
startTime: 1,
|
|
4039
|
+
userId: 1,
|
|
4040
|
+
userEmail: '$users.email',
|
|
4041
|
+
fileDate: 1,
|
|
4042
|
+
parsedDate: {
|
|
4043
|
+
$dateFromString: {
|
|
4044
|
+
dateString: '$fileDate',
|
|
4045
|
+
format: '%d-%m-%Y',
|
|
4046
|
+
},
|
|
4047
|
+
},
|
|
4048
|
+
deductionByLateLogin: {
|
|
4049
|
+
$cond: [
|
|
4050
|
+
{ $gt: [ '$startTime', lateLogin ] }, true, false,
|
|
3976
4051
|
],
|
|
3977
4052
|
},
|
|
3978
4053
|
},
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
4054
|
+
}, {
|
|
4055
|
+
$group: {
|
|
4056
|
+
_id: null,
|
|
4057
|
+
updatedData: {
|
|
4058
|
+
$push: {
|
|
4059
|
+
$cond: [
|
|
4060
|
+
{ $eq: [ '$deductionByLateLogin', true ] }, { userId: '$userId', userEmail: '$userEmail', fileDate: '$fileDate', week: { $week: '$parsedDate' },
|
|
4061
|
+
month: { $month: '$parsedDate' } }, '$$REMOVE',
|
|
4062
|
+
],
|
|
4063
|
+
},
|
|
3983
4064
|
},
|
|
3984
4065
|
},
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
4066
|
+
},
|
|
4067
|
+
{
|
|
4068
|
+
$project: {
|
|
4069
|
+
_id: 0,
|
|
4070
|
+
updatedData: 1,
|
|
3990
4071
|
},
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
4072
|
+
},
|
|
4073
|
+
];
|
|
4074
|
+
const getLateLogin = await aggregateUserAuditCount( lateLoginQuery );
|
|
4075
|
+
for ( let i=0; getLateLogin[0]?.updatedData?.length>0 && i<getLateLogin[0]?.updatedData?.length; i++ ) {
|
|
4076
|
+
const query = {
|
|
4077
|
+
email: getLateLogin[0]?.updatedData[i]?.userEmail,
|
|
4078
|
+
week: getLateLogin[0]?.updatedData[i]?.week,
|
|
4079
|
+
};
|
|
4080
|
+
const record ={
|
|
4081
|
+
email: getLateLogin[0]?.updatedData[i]?.userEmail,
|
|
4082
|
+
userId: getLateLogin[0]?.updatedData[i]?.userId,
|
|
4083
|
+
month: getLateLogin[0]?.updatedData[i]?.month,
|
|
4084
|
+
week: getLateLogin[0]?.updatedData[i]?.week,
|
|
4085
|
+
fileDate: [ getLateLogin[0]?.updatedData[i]?.fileDate ],
|
|
4086
|
+
lateLogin: 1,
|
|
4087
|
+
|
|
4088
|
+
};
|
|
4089
|
+
await updateOneAuditUsers( query, record );
|
|
4090
|
+
}
|
|
4091
|
+
|
|
4092
|
+
for ( let i =1; i<=differenceInDays+1; i++ ) {
|
|
4093
|
+
const previousDate = dayjs( new Date() ).subtract( i, 'days' );
|
|
4094
|
+
const fileDate = dayjs( previousDate ).format( 'DD-MM-YYYY' );
|
|
4095
|
+
const reduce = userWallet.reductionPerc; // 0.05;
|
|
4096
|
+
|
|
3996
4097
|
const userCountQuery= [
|
|
3997
4098
|
{
|
|
3998
4099
|
$match: {
|
|
@@ -4003,93 +4104,35 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4003
4104
|
],
|
|
4004
4105
|
},
|
|
4005
4106
|
},
|
|
4006
|
-
// {
|
|
4007
|
-
// $project: {
|
|
4008
|
-
|
|
4009
|
-
// trafficUserCount: { $cond: [
|
|
4010
|
-
// { $eq: [ '$moduleType', 'traffic' ] }, '$userId', '$$REMOVE',
|
|
4011
|
-
// ] },
|
|
4012
|
-
// zoneUserCount: { $cond: [
|
|
4013
|
-
// { $eq: [ '$moduleType', 'zone' ] }, '$userId', '$$REMOVE',
|
|
4014
|
-
// ] },
|
|
4015
|
-
|
|
4016
|
-
// trafficFilesCount: { $cond: [
|
|
4017
|
-
// { $eq: [ '$moduleType', 'traffic' ] }, '$beforeCount', '$$REMOVE',
|
|
4018
|
-
// ] },
|
|
4019
|
-
// zoneFilesCount: { $cond: [
|
|
4020
|
-
// { $eq: [ '$moduleType', 'zone' ] }, '$beforeCount', '$$REMOVE',
|
|
4021
|
-
// ] },
|
|
4022
|
-
|
|
4023
|
-
// },
|
|
4024
|
-
// },
|
|
4025
4107
|
{
|
|
4026
4108
|
$group: {
|
|
4027
4109
|
_id: null,
|
|
4028
|
-
// trafficUserCount: { $addToSet: '$trafficUserCount' },
|
|
4029
|
-
// zoneUserCount: { $addToSet: '$zoneUserCount' },
|
|
4030
|
-
// trafficFilesCount: { $sum: '$trafficFilesCount' },
|
|
4031
|
-
// zoneFilesCount: { $sum: '$zoneFilesCount' },
|
|
4032
4110
|
userCount: { $addToSet: '$userId' },
|
|
4033
4111
|
filesCount: { $sum: '$beforeCount' },
|
|
4034
4112
|
},
|
|
4035
4113
|
},
|
|
4036
4114
|
];
|
|
4037
4115
|
|
|
4038
|
-
// const storeDataQuery= [
|
|
4039
|
-
// {
|
|
4040
|
-
// $match: {
|
|
4041
|
-
// fileDate: { $eq: fileDate },
|
|
4042
|
-
// },
|
|
4043
|
-
// },
|
|
4044
|
-
// {
|
|
4045
|
-
// $project: {
|
|
4046
|
-
|
|
4047
|
-
// trafficFilesCount: { $cond: [
|
|
4048
|
-
// { $eq: [ '$moduleType', 'traffic' ] }, '$totalFilesCount', '$$REMOVE',
|
|
4049
|
-
// ] },
|
|
4050
|
-
// zoneFilesCount: { $cond: [
|
|
4051
|
-
// { $eq: [ '$moduleType', 'zone' ] }, '$totalFilesCount', '$$REMOVE',
|
|
4052
|
-
// ] },
|
|
4053
|
-
|
|
4054
|
-
// },
|
|
4055
|
-
// },
|
|
4056
|
-
// {
|
|
4057
|
-
// $group: {
|
|
4058
|
-
// _id: '$moduleType',
|
|
4059
|
-
// trafficFilesCount: { $sum: '$trafficFilesCount' },
|
|
4060
|
-
// zoneFilesCount: { $sum: '$zoneFilesCount' },
|
|
4061
|
-
// },
|
|
4062
|
-
// },
|
|
4063
|
-
// {
|
|
4064
|
-
// $project: {
|
|
4065
|
-
// _id: 0,
|
|
4066
|
-
// trafficFilesCount: { $ifNull: [ '$trafficFilesCount', 0 ] },
|
|
4067
|
-
// zoneFilesCount: { $ifNull: [ '$zoneFilesCount', 0 ] },
|
|
4068
|
-
// },
|
|
4069
|
-
// },
|
|
4070
|
-
// ];
|
|
4071
4116
|
const userCount = await aggregateUserAuditCount( userCountQuery );
|
|
4072
|
-
|
|
4073
|
-
// const totalStoreData = await aggregateAuditStoreData( storeDataQuery );
|
|
4074
4117
|
if ( userCount?.length == 0 ) {
|
|
4075
4118
|
return res.sendError( 'No Data Found', 204 );
|
|
4076
4119
|
}
|
|
4077
4120
|
const minimumTarget =userCount[0]?.userCount?.length !== 0 && userCount[0]?.filesCount !==0 ? Math.floor( userCount[0].filesCount/userCount[0].userCount.length ) : 0;
|
|
4078
|
-
|
|
4079
|
-
const beforeCreditCal =
|
|
4080
|
-
|
|
4081
|
-
const
|
|
4121
|
+
logger.info( { bc: userWallet?.beforeCountCredit, ac: userWallet?.afterCountCredit } );
|
|
4122
|
+
const beforeCreditCal = userWallet?.beforeCountCredit/minimumTarget;
|
|
4123
|
+
const afterCountCredit = userWallet?.afterCountCredit;
|
|
4124
|
+
const filter = [
|
|
4125
|
+
{ fileDate: { $eq: fileDate } },
|
|
4126
|
+
{
|
|
4127
|
+
auditStatus: { $eq: 'completed' },
|
|
4128
|
+
},
|
|
4129
|
+
{ userId: { $in: auditUserList[0].userList } },
|
|
4130
|
+
];
|
|
4082
4131
|
|
|
4083
4132
|
const query = [
|
|
4084
4133
|
{
|
|
4085
4134
|
$match: {
|
|
4086
|
-
$and:
|
|
4087
|
-
{ fileDate: { $eq: fileDate } },
|
|
4088
|
-
{
|
|
4089
|
-
auditStatus: { $eq: 'completed' },
|
|
4090
|
-
},
|
|
4091
|
-
{ userId: { $in: auditUserList[0].userList } },
|
|
4092
|
-
],
|
|
4135
|
+
$and: filter,
|
|
4093
4136
|
},
|
|
4094
4137
|
},
|
|
4095
4138
|
{
|
|
@@ -4110,10 +4153,15 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4110
4153
|
singleImageAmount: { $ifNull: [ '$beforeCreditCal', 0 ] },
|
|
4111
4154
|
totalReducedAmount: { $ifNull: [ 0, 0 ] },
|
|
4112
4155
|
totalCredit: { $ifNull: [ 0, 0 ] },
|
|
4113
|
-
// deductionBytimeSpent: { $ifNull: [ 0, 0 ] },
|
|
4114
4156
|
deductionByMinimumTarget: { $ifNull: [ 0, 0 ] },
|
|
4115
4157
|
deductionByLateLogin: { $ifNull: [ 0, 0 ] },
|
|
4116
4158
|
startTime: 1,
|
|
4159
|
+
parsedDate: {
|
|
4160
|
+
$dateFromString: {
|
|
4161
|
+
dateString: '$fileDate',
|
|
4162
|
+
format: '%d-%m-%Y',
|
|
4163
|
+
},
|
|
4164
|
+
},
|
|
4117
4165
|
},
|
|
4118
4166
|
},
|
|
4119
4167
|
{
|
|
@@ -4129,6 +4177,7 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4129
4177
|
totalTimeSpent: { $sum: '$timeSpent' },
|
|
4130
4178
|
fileDate: { $first: '$fileDate' },
|
|
4131
4179
|
fileDateISO: { $first: '$fileDateISO' },
|
|
4180
|
+
week: { $first: '$parsedDate' },
|
|
4132
4181
|
userId: { $first: '$userId' },
|
|
4133
4182
|
minimumTarget: { $first: '$minimumTarget' },
|
|
4134
4183
|
afterCountCredit: { $first: '$afterCountCredit' },
|
|
@@ -4136,12 +4185,38 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4136
4185
|
totalReducedAmount: { $first: '$totalReducedAmount' },
|
|
4137
4186
|
totalCredit: { $first: '$totalCredit' },
|
|
4138
4187
|
deductionByMinimumTarget: { $first: '$deductionByMinimumTarget' },
|
|
4139
|
-
// deductionBytimeSpent: { $first: '$deductionBytimeSpent' },
|
|
4140
4188
|
singleImageAmount: { $first: '$singleImageAmount' },
|
|
4141
4189
|
startTime: { $first: '$startTime' },
|
|
4142
4190
|
deductionByLateLogin: { $first: '$deductionByLateLogin' },
|
|
4143
4191
|
},
|
|
4144
4192
|
},
|
|
4193
|
+
{
|
|
4194
|
+
$lookup: {
|
|
4195
|
+
from: 'auditUsers',
|
|
4196
|
+
let: { userId: '$userId', week: { $week: '$parsedDate' } }, // Assuming userId is the linking field
|
|
4197
|
+
pipeline: [
|
|
4198
|
+
{
|
|
4199
|
+
$match: {
|
|
4200
|
+
$expr: {
|
|
4201
|
+
$and: [
|
|
4202
|
+
{ $eq: [ '$userId', '$$userId' ] },
|
|
4203
|
+
{ $eq: [ '$week', '$$week' ] },
|
|
4204
|
+
],
|
|
4205
|
+
},
|
|
4206
|
+
},
|
|
4207
|
+
},
|
|
4208
|
+
{
|
|
4209
|
+
$project: {
|
|
4210
|
+
_id: 0, // Exclude _id if not needed
|
|
4211
|
+
fileDate: 1,
|
|
4212
|
+
lateLogin: { $size: '$fileDate' },
|
|
4213
|
+
},
|
|
4214
|
+
},
|
|
4215
|
+
],
|
|
4216
|
+
as: 'auditUsers',
|
|
4217
|
+
},
|
|
4218
|
+
},
|
|
4219
|
+
{ $unwind: { path: '$auditUsers', preserveNullAndEmptyArrays: true } },
|
|
4145
4220
|
{
|
|
4146
4221
|
$project: {
|
|
4147
4222
|
totalCount: 1,
|
|
@@ -4155,19 +4230,8 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4155
4230
|
minimumTarget: 1,
|
|
4156
4231
|
singleImageAmount: 1,
|
|
4157
4232
|
beforeCountCredit: { $multiply: [ '$totalBeforeCount', '$singleImageAmount' ] },
|
|
4158
|
-
// afterCountCredit: { $cond: [ { $and: [
|
|
4159
|
-
// { $gte: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.4 ] }, { $lte: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] },
|
|
4160
|
-
// ] }, 136,
|
|
4161
|
-
// {
|
|
4162
|
-
// $cond: [ { $gt: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] },
|
|
4163
|
-
// { $subtract: [ 136, { $multiply: [ { $subtract: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] }, 136 ] } ] },
|
|
4164
|
-
// { $subtract: [ 136, { $multiply: [ { $subtract: [ 0.4, { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] } ] }, 136 ] } ] },
|
|
4165
|
-
// ],
|
|
4166
|
-
// },
|
|
4167
|
-
// ] },
|
|
4168
4233
|
afterCountCredit: afterCountCredit,
|
|
4169
4234
|
totalEarn: { $add: [ { $multiply: [ '$totalBeforeCount', '$singleImageAmount' ] }, 136 ] },
|
|
4170
|
-
// deductionBytimeSpent: 1,
|
|
4171
4235
|
deductionByMinimumTarget: 1,
|
|
4172
4236
|
mappingperc: { $multiply: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 100 ] },
|
|
4173
4237
|
deductionByMapping: { $cond: [ { $and: [
|
|
@@ -4210,11 +4274,6 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4210
4274
|
beforeCountCredit: 1,
|
|
4211
4275
|
afterCountCredit: 1,
|
|
4212
4276
|
totalEarn: 1,
|
|
4213
|
-
// deductionBytimeSpent: { $cond: [
|
|
4214
|
-
// { $lt: [ '$totalTimeSpent', configTimeSpentSec ] },
|
|
4215
|
-
// { $multiply: [ reduce, '$totalEarn' ] }, '$deductionBytimeSpent',
|
|
4216
|
-
// ] },
|
|
4217
|
-
|
|
4218
4277
|
deductionByMinimumTarget:
|
|
4219
4278
|
{ $cond: [
|
|
4220
4279
|
{ $lt: [ '$totalBeforeCount', '$minimumTarget' ] },
|
|
@@ -4222,8 +4281,11 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4222
4281
|
] },
|
|
4223
4282
|
deductionByLateLogin: {
|
|
4224
4283
|
$cond: [
|
|
4225
|
-
{ $
|
|
4226
|
-
|
|
4284
|
+
{ $and: [
|
|
4285
|
+
{ $gt: [ '$auditUsers.lateLogin', 2 ] },
|
|
4286
|
+
{ $eq: [ '$fileDate', dayjs( yesterday ).format( 'DD-MM-YYYY' ) ] },
|
|
4287
|
+
] },
|
|
4288
|
+
{ $multiply: [ reduce, '$totalEarn' ] }, 0,
|
|
4227
4289
|
],
|
|
4228
4290
|
},
|
|
4229
4291
|
mappingperc: 1,
|
|
@@ -4269,7 +4331,6 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4269
4331
|
totalEarn: 1,
|
|
4270
4332
|
deductionByMinimumTarget: 1,
|
|
4271
4333
|
singleImageAmount: 1,
|
|
4272
|
-
// deductionBytimeSpent: 1,
|
|
4273
4334
|
mappingperc: 1,
|
|
4274
4335
|
deductionByMapping: 1,
|
|
4275
4336
|
totalCredit: { $subtract: [ '$totalEarn', '$totalReducedAmount' ] },
|
|
@@ -4324,7 +4385,6 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4324
4385
|
minimumTarget: 1,
|
|
4325
4386
|
singleImageAmount: 1,
|
|
4326
4387
|
deductionByMinimumTarget: { $round: [ '$deductionByMinimumTarget', 2 ] },
|
|
4327
|
-
// deductionBytimeSpent: { $round: [ '$deductionBytimeSpent', 2 ] },
|
|
4328
4388
|
mappingperc: 1,
|
|
4329
4389
|
deductionByMapping: 1,
|
|
4330
4390
|
totalReducedAmount: 1,
|
|
@@ -4337,15 +4397,27 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4337
4397
|
},
|
|
4338
4398
|
},
|
|
4339
4399
|
];
|
|
4400
|
+
|
|
4340
4401
|
const consolidatedData = await aggregateUserAuditCount( query );
|
|
4341
4402
|
if ( consolidatedData.length == 0 ) {
|
|
4342
4403
|
return res.sendError( 'No Data found', 204 );
|
|
4343
4404
|
}
|
|
4344
|
-
|
|
4405
|
+
|
|
4406
|
+
const operations = consolidatedData.map( ( record ) => ( {
|
|
4407
|
+
updateOne: {
|
|
4408
|
+
filter: { userEmail: record.userEmail, fileDate: record.fileDate }, // Match criteria
|
|
4409
|
+
update: {
|
|
4410
|
+
$set: record,
|
|
4411
|
+
},
|
|
4412
|
+
upsert: true, // Perform upsert
|
|
4413
|
+
},
|
|
4414
|
+
} ) );
|
|
4415
|
+
|
|
4416
|
+
const result = await bulkWriteAuditUserWallet( operations );
|
|
4345
4417
|
if ( result.length == 0 ) {
|
|
4346
4418
|
return res.sendError( 'No Record Inserted', 500 );
|
|
4347
4419
|
}
|
|
4348
|
-
if ( i ==
|
|
4420
|
+
if ( i == differenceInDays+1 ) {
|
|
4349
4421
|
return res.sendSuccess( { message: 'Inserted successfully!' } );
|
|
4350
4422
|
}
|
|
4351
4423
|
}
|
|
@@ -4955,5 +5027,3 @@ export async function convertTimestampToDateTime( timestamp ) {
|
|
|
4955
5027
|
const seconds = ( '0' + adjustedDate.getSeconds() ).slice( -2 );
|
|
4956
5028
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
4957
5029
|
}
|
|
4958
|
-
|
|
4959
|
-
|
|
@@ -52,37 +52,6 @@ export async function auditUserSummary( req, res ) {
|
|
|
52
52
|
},
|
|
53
53
|
];
|
|
54
54
|
|
|
55
|
-
if ( inputData.searchValue && inputData.searchValue !== '' ) {
|
|
56
|
-
query.push( {
|
|
57
|
-
$match: {
|
|
58
|
-
$or: [
|
|
59
|
-
{ 'userName': { $regex: inputData.searchValue, $options: 'i' } },
|
|
60
|
-
{ 'userEmail': { $regex: inputData.searchValue, $options: 'i' } },
|
|
61
|
-
{ 'fileDateFrom': { $regex: inputData.searchValue, $options: 'i' } },
|
|
62
|
-
{ 'FileDateTo': { $regex: inputData.searchValue, $options: 'i' } },
|
|
63
|
-
{ 'totalFilesCount': { $regex: inputData.searchValue, $options: 'i' } },
|
|
64
|
-
{ 'totalBeforeCount': { $regex: inputData.searchValue, $options: 'i' } },
|
|
65
|
-
{ 'totalAfterCount': { $regex: inputData.searchValue, $options: 'i' } },
|
|
66
|
-
{ 'totalEarn': { $regex: inputData.searchValue, $options: 'i' } },
|
|
67
|
-
{ 'beforeCountCredit': { $regex: inputData.searchValue, $options: 'i' } },
|
|
68
|
-
{ 'afterCountCredit': { $regex: inputData.searchValue, $options: 'i' } },
|
|
69
|
-
{ 'deductionByMinimumTarget': { $regex: inputData.searchValue, $options: 'i' } },
|
|
70
|
-
{ 'deductionByMapping': { $regex: inputData.searchValue, $options: 'i' } },
|
|
71
|
-
{ 'deductionByLateLogin': { $regex: inputData.searchValue, $options: 'i' } },
|
|
72
|
-
{ 'totalReducedAmount': { $regex: inputData.searchValue, $options: 'i' } },
|
|
73
|
-
{ 'totalCredit': { $regex: inputData.searchValue, $options: 'i' } },
|
|
74
|
-
],
|
|
75
|
-
},
|
|
76
|
-
} );
|
|
77
|
-
}
|
|
78
|
-
if ( inputData.sortColumnName ) {
|
|
79
|
-
const sortBy = inputData.sortBy || -1;
|
|
80
|
-
const sortColumn = inputData.sortColumnName;
|
|
81
|
-
query.push( {
|
|
82
|
-
$sort: { [sortColumn]: sortBy },
|
|
83
|
-
},
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
55
|
if ( inputData.isExport ) {
|
|
87
56
|
query.push( {
|
|
88
57
|
$project: {
|
|
@@ -127,6 +96,39 @@ export async function auditUserSummary( req, res ) {
|
|
|
127
96
|
} );
|
|
128
97
|
}
|
|
129
98
|
|
|
99
|
+
if ( inputData.searchValue && inputData.searchValue !== '' ) {
|
|
100
|
+
query.push( {
|
|
101
|
+
$match: {
|
|
102
|
+
$or: [
|
|
103
|
+
{ 'userName': { $regex: inputData.searchValue, $options: 'i' } },
|
|
104
|
+
{ 'userEmail': { $regex: inputData.searchValue, $options: 'i' } },
|
|
105
|
+
{ 'fileDateFrom': { $regex: inputData.searchValue, $options: 'i' } },
|
|
106
|
+
{ 'FileDateTo': { $regex: inputData.searchValue, $options: 'i' } },
|
|
107
|
+
{ 'totalFilesCount': { $regex: inputData.searchValue, $options: 'i' } },
|
|
108
|
+
{ 'totalBeforeCount': { $regex: inputData.searchValue, $options: 'i' } },
|
|
109
|
+
{ 'totalAfterCount': { $regex: inputData.searchValue, $options: 'i' } },
|
|
110
|
+
{ 'totalEarn': { $regex: inputData.searchValue, $options: 'i' } },
|
|
111
|
+
{ 'beforeCountCredit': { $regex: inputData.searchValue, $options: 'i' } },
|
|
112
|
+
{ 'afterCountCredit': { $regex: inputData.searchValue, $options: 'i' } },
|
|
113
|
+
{ 'deductionByMinimumTarget': { $regex: inputData.searchValue, $options: 'i' } },
|
|
114
|
+
{ 'deductionByMapping': { $regex: inputData.searchValue, $options: 'i' } },
|
|
115
|
+
{ 'deductionByLateLogin': { $regex: inputData.searchValue, $options: 'i' } },
|
|
116
|
+
{ 'totalReducedAmount': { $regex: inputData.searchValue, $options: 'i' } },
|
|
117
|
+
{ 'totalCredit': { $regex: inputData.searchValue, $options: 'i' } },
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
} );
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if ( inputData.sortColumnName ) {
|
|
124
|
+
const sortBy = inputData.sortBy || -1;
|
|
125
|
+
const sortColumn = inputData.sortColumnName;
|
|
126
|
+
query.push( {
|
|
127
|
+
$sort: { [sortColumn]: sortBy },
|
|
128
|
+
},
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
130
132
|
const count = await aggregateAuditUserWallet( query );
|
|
131
133
|
if ( count.length == 0 ) {
|
|
132
134
|
return res.sendError( 'No Data Found', 204 );
|
|
@@ -329,23 +331,6 @@ export async function auditWalletSummary( req, res ) {
|
|
|
329
331
|
},
|
|
330
332
|
];
|
|
331
333
|
|
|
332
|
-
if ( inputData.searchValue && inputData.searchValue !== '' ) {
|
|
333
|
-
query.push( {
|
|
334
|
-
$match: {
|
|
335
|
-
$or: [
|
|
336
|
-
{ 'fileDate': { $regex: inputData.searchValue, $options: 'i' } },
|
|
337
|
-
],
|
|
338
|
-
},
|
|
339
|
-
} );
|
|
340
|
-
}
|
|
341
|
-
if ( inputData.sortColumnName ) {
|
|
342
|
-
const sortBy = inputData.sortBy || -1;
|
|
343
|
-
const sortColumn = inputData.sortColumnName;
|
|
344
|
-
query.push( {
|
|
345
|
-
$sort: { [sortColumn]: sortBy },
|
|
346
|
-
},
|
|
347
|
-
);
|
|
348
|
-
}
|
|
349
334
|
if ( inputData.isExport ) {
|
|
350
335
|
query.push( {
|
|
351
336
|
$project: {
|
|
@@ -389,6 +374,24 @@ export async function auditWalletSummary( req, res ) {
|
|
|
389
374
|
);
|
|
390
375
|
}
|
|
391
376
|
|
|
377
|
+
if ( inputData.searchValue && inputData.searchValue !== '' ) {
|
|
378
|
+
query.push( {
|
|
379
|
+
$match: {
|
|
380
|
+
$or: [
|
|
381
|
+
{ 'fileDate': { $regex: inputData.searchValue, $options: 'i' } },
|
|
382
|
+
],
|
|
383
|
+
},
|
|
384
|
+
} );
|
|
385
|
+
}
|
|
386
|
+
if ( inputData.sortColumnName ) {
|
|
387
|
+
const sortBy = inputData.sortBy || -1;
|
|
388
|
+
const sortColumn = inputData.sortColumnName;
|
|
389
|
+
query.push( {
|
|
390
|
+
$sort: { [sortColumn]: sortBy },
|
|
391
|
+
},
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
|
|
392
395
|
const count = await aggregateAuditUserWallet( query );
|
|
393
396
|
if ( count.length == 0 ) {
|
|
394
397
|
return res.sendError( 'No Data Found', 204 );
|
|
@@ -5,6 +5,10 @@ export function createAuditUserWallet( record ) {
|
|
|
5
5
|
return auditUserWalletModel.create( record );
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
+
export function bulkWriteAuditUserWallet( record ) {
|
|
9
|
+
return auditUserWalletModel.bulkWrite( record );
|
|
10
|
+
};
|
|
11
|
+
|
|
8
12
|
export function findOneAuditUserWallet( record, fields, sort = { createdAt: -1 } ) {
|
|
9
13
|
return auditUserWalletModel.findOne( record, fields ).sort( sort );
|
|
10
14
|
};
|
|
@@ -8,8 +8,10 @@ export function findOneAuditUsers( query, fields ) {
|
|
|
8
8
|
return auditUsersModel.findOne( query, fields );
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export function updateOneAuditUsers( query,
|
|
12
|
-
return auditUsersModel.updateOne( query,
|
|
11
|
+
export function updateOneAuditUsers( query, record ) {
|
|
12
|
+
return auditUsersModel.updateOne( query,
|
|
13
|
+
{ $addToSet: record.fileDate,
|
|
14
|
+
$setOnInsert: record }, { upsert: true } );
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
export function updateManyAuditUsers( query, fields ) {
|