tango-app-api-audit 3.4.30 → 3.4.32
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 +109 -107
- package/src/controllers/auditWallet.controllers.js +65 -50
- package/src/docs/auditWallet.docs.js +28 -0
- package/src/dtos/auditWallet.dtos.js +10 -0
- package/src/routes/auditWallet.routes.js +3 -2
- package/src/service/auditUsers.service.js +4 -2
package/package.json
CHANGED
|
@@ -64,7 +64,8 @@ import { aggregateStoreEmpDetection } from '../service/storeEmpDetection.service
|
|
|
64
64
|
import { aggregateBinaryAudit } from '../service/binaryAudit.service.js';
|
|
65
65
|
import { aggregateTraxAuditData, findOneTraxAuditData } from '../service/traxAuditData.service.js';
|
|
66
66
|
import { createAuditUserWallet, findOneAuditUserWallet } from '../service/auditUserWallet.service.js';
|
|
67
|
-
import {
|
|
67
|
+
import { updateOneAuditUsers } from '../service/auditUsers.service.js';
|
|
68
|
+
// import { aggregateAuditUsers } from '../service/auditUsers.service.js';
|
|
68
69
|
|
|
69
70
|
/* < -- *** Configuration *** --> */
|
|
70
71
|
|
|
@@ -3938,27 +3939,22 @@ 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
|
+
// Get yesterday's date
|
|
3946
|
+
const yesterday = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 1 );
|
|
3946
3947
|
|
|
3947
|
-
//
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
//
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
for ( let i =
|
|
3954
|
-
const userWallet = JSON.parse( process.env.USER_WALLET );
|
|
3948
|
+
// Get the first day of the current month
|
|
3949
|
+
const firstDateOfMonth = new Date( today.getFullYear(), today.getMonth(), 1 );
|
|
3950
|
+
|
|
3951
|
+
// Calculate the difference in days
|
|
3952
|
+
const differenceInDays = ( yesterday.getDate() - firstDateOfMonth.getDate() );
|
|
3953
|
+
|
|
3954
|
+
for ( let i =1; i<=differenceInDays; i++ ) {
|
|
3955
3955
|
const previousDate = dayjs( new Date() ).subtract( i, 'days' );
|
|
3956
3956
|
const fileDate = dayjs( previousDate ).format( 'DD-MM-YYYY' );
|
|
3957
|
-
const configTimeSpentSec = userWallet.minTimeSpentSec; // 21600 seconds / 6 hours;
|
|
3958
|
-
// const beforeCountX = userWallet.beforeCountCreditPerc; // 0.0335;
|
|
3959
|
-
// const afterCountY = userWallet.afterCountCreditPerc; // 0.0035;
|
|
3960
3957
|
const reduce = userWallet.reductionPerc; // 0.05;
|
|
3961
|
-
const today = new Date();
|
|
3962
3958
|
|
|
3963
3959
|
// Subtract one day to get the previous day
|
|
3964
3960
|
const previousDay = new Date( today );
|
|
@@ -3971,7 +3967,7 @@ export async function getUserAuditCount( req, res ) {
|
|
|
3971
3967
|
{
|
|
3972
3968
|
$match: {
|
|
3973
3969
|
$and: [
|
|
3974
|
-
{
|
|
3970
|
+
{ tangoUserType: { $eq: 'audit' } },
|
|
3975
3971
|
{ isActive: { $eq: true } },
|
|
3976
3972
|
],
|
|
3977
3973
|
},
|
|
@@ -3989,7 +3985,7 @@ export async function getUserAuditCount( req, res ) {
|
|
|
3989
3985
|
},
|
|
3990
3986
|
},
|
|
3991
3987
|
];
|
|
3992
|
-
const auditUserList = await
|
|
3988
|
+
const auditUserList = await aggregateUser( auditUserQuery );
|
|
3993
3989
|
if ( auditUserList.length==0 ) {
|
|
3994
3990
|
return res.sendError( 'No users available', 204 );
|
|
3995
3991
|
}
|
|
@@ -4003,93 +3999,119 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4003
3999
|
],
|
|
4004
4000
|
},
|
|
4005
4001
|
},
|
|
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
4002
|
{
|
|
4026
4003
|
$group: {
|
|
4027
4004
|
_id: null,
|
|
4028
|
-
// trafficUserCount: { $addToSet: '$trafficUserCount' },
|
|
4029
|
-
// zoneUserCount: { $addToSet: '$zoneUserCount' },
|
|
4030
|
-
// trafficFilesCount: { $sum: '$trafficFilesCount' },
|
|
4031
|
-
// zoneFilesCount: { $sum: '$zoneFilesCount' },
|
|
4032
4005
|
userCount: { $addToSet: '$userId' },
|
|
4033
4006
|
filesCount: { $sum: '$beforeCount' },
|
|
4034
4007
|
},
|
|
4035
4008
|
},
|
|
4036
4009
|
];
|
|
4037
4010
|
|
|
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
4011
|
const userCount = await aggregateUserAuditCount( userCountQuery );
|
|
4072
4012
|
|
|
4073
|
-
// const totalStoreData = await aggregateAuditStoreData( storeDataQuery );
|
|
4074
4013
|
if ( userCount?.length == 0 ) {
|
|
4075
4014
|
return res.sendError( 'No Data Found', 204 );
|
|
4076
4015
|
}
|
|
4077
4016
|
const minimumTarget =userCount[0]?.userCount?.length !== 0 && userCount[0]?.filesCount !==0 ? Math.floor( userCount[0].filesCount/userCount[0].userCount.length ) : 0;
|
|
4078
|
-
|
|
4079
|
-
const
|
|
4080
|
-
|
|
4081
|
-
|
|
4017
|
+
const beforeCreditCal = userWallet?.beforeCountCredit/minimumTarget;
|
|
4018
|
+
const afterCountCredit = userWallet?.afterCountCredit;
|
|
4019
|
+
const filter = [
|
|
4020
|
+
{ fileDate: { $eq: fileDate } },
|
|
4021
|
+
{
|
|
4022
|
+
auditStatus: { $eq: 'completed' },
|
|
4023
|
+
},
|
|
4024
|
+
{ userId: { $in: auditUserList[0].userList } },
|
|
4025
|
+
];
|
|
4082
4026
|
|
|
4083
|
-
const
|
|
4027
|
+
const lateLoginQuery =[
|
|
4084
4028
|
{
|
|
4085
4029
|
$match: {
|
|
4086
|
-
$and:
|
|
4087
|
-
|
|
4030
|
+
$and: filter,
|
|
4031
|
+
},
|
|
4032
|
+
},
|
|
4033
|
+
{
|
|
4034
|
+
$lookup: {
|
|
4035
|
+
from: 'users',
|
|
4036
|
+
let: { userId: '$userId' }, // Assuming userId is the linking field
|
|
4037
|
+
pipeline: [
|
|
4088
4038
|
{
|
|
4089
|
-
|
|
4039
|
+
$match: {
|
|
4040
|
+
$expr: { $eq: [ '$_id', '$$userId' ] },
|
|
4041
|
+
},
|
|
4042
|
+
},
|
|
4043
|
+
{
|
|
4044
|
+
$project: {
|
|
4045
|
+
_id: 0, // Exclude _id if not needed
|
|
4046
|
+
email: 1,
|
|
4047
|
+
userName: 1,
|
|
4048
|
+
},
|
|
4090
4049
|
},
|
|
4091
|
-
{ userId: { $in: auditUserList[0].userList } },
|
|
4092
4050
|
],
|
|
4051
|
+
as: 'users',
|
|
4052
|
+
},
|
|
4053
|
+
},
|
|
4054
|
+
{ $unwind: { path: '$users', preserveNullAndEmptyArrays: true } },
|
|
4055
|
+
{
|
|
4056
|
+
$project: {
|
|
4057
|
+
startTime: 1,
|
|
4058
|
+
userId: 1,
|
|
4059
|
+
userEmail: '$user.email',
|
|
4060
|
+
fileDate: 1,
|
|
4061
|
+
parsedDate: {
|
|
4062
|
+
$dateFromString: {
|
|
4063
|
+
dateString: '$fileDate',
|
|
4064
|
+
format: '%d-%m-%Y',
|
|
4065
|
+
},
|
|
4066
|
+
},
|
|
4067
|
+
deductionByLateLogin: {
|
|
4068
|
+
$cond: [
|
|
4069
|
+
{ $gt: [ '$startTime', lateLogin ] }, true, false,
|
|
4070
|
+
],
|
|
4071
|
+
},
|
|
4072
|
+
},
|
|
4073
|
+
}, {
|
|
4074
|
+
$group: {
|
|
4075
|
+
_id: null,
|
|
4076
|
+
updatedData: {
|
|
4077
|
+
$push: {
|
|
4078
|
+
$cond: [
|
|
4079
|
+
{ $eq: [ '$deductionByLateLogin', true ] }, { userId: '$userId', userEmail: '$userEmail', fileDate: 'fileDate', week: { $week: '$parsedDate' },
|
|
4080
|
+
month: { $month: '$parsedDate' } }, '$$REMOVE',
|
|
4081
|
+
],
|
|
4082
|
+
},
|
|
4083
|
+
},
|
|
4084
|
+
},
|
|
4085
|
+
},
|
|
4086
|
+
{
|
|
4087
|
+
$project: {
|
|
4088
|
+
_id: 0,
|
|
4089
|
+
updatedData: 1,
|
|
4090
|
+
},
|
|
4091
|
+
},
|
|
4092
|
+
];
|
|
4093
|
+
const getLateLogin = await aggregateUserAuditCount( lateLoginQuery );
|
|
4094
|
+
|
|
4095
|
+
for ( let i=0; getLateLogin[0]?.updatedData?.length>0 && 1<getLateLogin[0]?.updatedData?.length; i++ ) {
|
|
4096
|
+
const query = {
|
|
4097
|
+
email: getLateLogin[0]?.updatedData[i]?.userEmail,
|
|
4098
|
+
week: getLateLogin[0]?.updatedData[i]?.week,
|
|
4099
|
+
};
|
|
4100
|
+
const record ={
|
|
4101
|
+
email: getLateLogin[0]?.updatedData[i]?.userEmail,
|
|
4102
|
+
userId: getLateLogin[0]?.updatedData[i]?.userId,
|
|
4103
|
+
month: getLateLogin[0]?.updatedData[i]?.month,
|
|
4104
|
+
week: getLateLogin[0]?.updatedData[i]?.week,
|
|
4105
|
+
fileDate: getLateLogin[0]?.updatedData[i]?.fileDate,
|
|
4106
|
+
lateLogin: 1,
|
|
4107
|
+
|
|
4108
|
+
};
|
|
4109
|
+
await updateOneAuditUsers( query, record );
|
|
4110
|
+
}
|
|
4111
|
+
const query = [
|
|
4112
|
+
{
|
|
4113
|
+
$match: {
|
|
4114
|
+
$and: filter,
|
|
4093
4115
|
},
|
|
4094
4116
|
},
|
|
4095
4117
|
{
|
|
@@ -4110,7 +4132,6 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4110
4132
|
singleImageAmount: { $ifNull: [ '$beforeCreditCal', 0 ] },
|
|
4111
4133
|
totalReducedAmount: { $ifNull: [ 0, 0 ] },
|
|
4112
4134
|
totalCredit: { $ifNull: [ 0, 0 ] },
|
|
4113
|
-
deductionBytimeSpent: { $ifNull: [ 0, 0 ] },
|
|
4114
4135
|
deductionByMinimumTarget: { $ifNull: [ 0, 0 ] },
|
|
4115
4136
|
deductionByLateLogin: { $ifNull: [ 0, 0 ] },
|
|
4116
4137
|
startTime: 1,
|
|
@@ -4136,7 +4157,6 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4136
4157
|
totalReducedAmount: { $first: '$totalReducedAmount' },
|
|
4137
4158
|
totalCredit: { $first: '$totalCredit' },
|
|
4138
4159
|
deductionByMinimumTarget: { $first: '$deductionByMinimumTarget' },
|
|
4139
|
-
deductionBytimeSpent: { $first: '$deductionBytimeSpent' },
|
|
4140
4160
|
singleImageAmount: { $first: '$singleImageAmount' },
|
|
4141
4161
|
startTime: { $first: '$startTime' },
|
|
4142
4162
|
deductionByLateLogin: { $first: '$deductionByLateLogin' },
|
|
@@ -4155,19 +4175,8 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4155
4175
|
minimumTarget: 1,
|
|
4156
4176
|
singleImageAmount: 1,
|
|
4157
4177
|
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
4178
|
afterCountCredit: afterCountCredit,
|
|
4169
4179
|
totalEarn: { $add: [ { $multiply: [ '$totalBeforeCount', '$singleImageAmount' ] }, 136 ] },
|
|
4170
|
-
deductionBytimeSpent: 1,
|
|
4171
4180
|
deductionByMinimumTarget: 1,
|
|
4172
4181
|
mappingperc: { $multiply: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 100 ] },
|
|
4173
4182
|
deductionByMapping: { $cond: [ { $and: [
|
|
@@ -4210,11 +4219,6 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4210
4219
|
beforeCountCredit: 1,
|
|
4211
4220
|
afterCountCredit: 1,
|
|
4212
4221
|
totalEarn: 1,
|
|
4213
|
-
deductionBytimeSpent: { $cond: [
|
|
4214
|
-
{ $lt: [ '$totalTimeSpent', configTimeSpentSec ] },
|
|
4215
|
-
{ $multiply: [ reduce, '$totalEarn' ] }, '$deductionBytimeSpent',
|
|
4216
|
-
] },
|
|
4217
|
-
|
|
4218
4222
|
deductionByMinimumTarget:
|
|
4219
4223
|
{ $cond: [
|
|
4220
4224
|
{ $lt: [ '$totalBeforeCount', '$minimumTarget' ] },
|
|
@@ -4269,11 +4273,10 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4269
4273
|
totalEarn: 1,
|
|
4270
4274
|
deductionByMinimumTarget: 1,
|
|
4271
4275
|
singleImageAmount: 1,
|
|
4272
|
-
deductionBytimeSpent: 1,
|
|
4273
4276
|
mappingperc: 1,
|
|
4274
4277
|
deductionByMapping: 1,
|
|
4275
4278
|
totalCredit: { $subtract: [ '$totalEarn', '$totalReducedAmount' ] },
|
|
4276
|
-
totalReducedAmount: { $round: [ { $add: [ '$
|
|
4279
|
+
totalReducedAmount: { $round: [ { $add: [ '$deductionByMinimumTarget', '$deductionByMapping', '$deductionByLateLogin' ] }, 2 ] },
|
|
4277
4280
|
deductionByLateLogin: 1,
|
|
4278
4281
|
startTime: {
|
|
4279
4282
|
$dateToString: {
|
|
@@ -4324,7 +4327,6 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4324
4327
|
minimumTarget: 1,
|
|
4325
4328
|
singleImageAmount: 1,
|
|
4326
4329
|
deductionByMinimumTarget: { $round: [ '$deductionByMinimumTarget', 2 ] },
|
|
4327
|
-
deductionBytimeSpent: { $round: [ '$deductionBytimeSpent', 2 ] },
|
|
4328
4330
|
mappingperc: 1,
|
|
4329
4331
|
deductionByMapping: 1,
|
|
4330
4332
|
totalReducedAmount: 1,
|
|
@@ -4345,7 +4347,7 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4345
4347
|
if ( result.length == 0 ) {
|
|
4346
4348
|
return res.sendError( 'No Record Inserted', 500 );
|
|
4347
4349
|
}
|
|
4348
|
-
if ( i ==
|
|
4350
|
+
if ( i == differenceInDays ) {
|
|
4349
4351
|
return res.sendSuccess( { message: 'Inserted successfully!' } );
|
|
4350
4352
|
}
|
|
4351
4353
|
}
|
|
@@ -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: {
|
|
@@ -355,7 +340,7 @@ export async function auditWalletSummary( req, res ) {
|
|
|
355
340
|
'Total BC': '$totalBeforeCount',
|
|
356
341
|
'Total AC': '$totalAfterCount',
|
|
357
342
|
'Total Earn': '$totalEarn',
|
|
358
|
-
'Deduction By
|
|
343
|
+
'Deduction By Minimum Target': '$deductionByMinimumTarget',
|
|
359
344
|
// 'Mapping Percentage': '$mappingperc',
|
|
360
345
|
'Deduction By Mapping': '$deductionByMapping',
|
|
361
346
|
'Deduction By Late Login': '$deductionByLateLogin',
|
|
@@ -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 );
|
|
@@ -396,7 +399,7 @@ export async function auditWalletSummary( req, res ) {
|
|
|
396
399
|
|
|
397
400
|
|
|
398
401
|
if ( inputData.isExport ) {
|
|
399
|
-
await download(
|
|
402
|
+
await download( count, res );
|
|
400
403
|
return;
|
|
401
404
|
}
|
|
402
405
|
|
|
@@ -420,4 +423,16 @@ export async function auditWalletSummary( req, res ) {
|
|
|
420
423
|
}
|
|
421
424
|
}
|
|
422
425
|
|
|
426
|
+
export async function generateReport( req, res ) {
|
|
427
|
+
try {
|
|
428
|
+
const inputData = req.query;
|
|
429
|
+
logger.info( { inputData: inputData } );
|
|
430
|
+
return res.sendSuccess( { result: 'Generate Reort SuccessFully' } );
|
|
431
|
+
} catch ( error ) {
|
|
432
|
+
const err = error.message || 'Internal Server Error';
|
|
433
|
+
logger.error( { error: error, message: req.query, function: 'generateReport' } );
|
|
434
|
+
return res.sendError( err, 500 );
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
423
438
|
|
|
@@ -193,4 +193,32 @@ export const auditWalletDocs = {
|
|
|
193
193
|
},
|
|
194
194
|
},
|
|
195
195
|
},
|
|
196
|
+
'/v3/audit-wallet/generate-report': {
|
|
197
|
+
get: {
|
|
198
|
+
tags: [ 'Audit Wallet' ],
|
|
199
|
+
description: 'Generate user wallet report ',
|
|
200
|
+
operationId: 'generate-report',
|
|
201
|
+
parameters: [
|
|
202
|
+
{
|
|
203
|
+
in: 'query',
|
|
204
|
+
name: 'fromDate',
|
|
205
|
+
scema: j2s( consolidatedCardSASchema ).swagger,
|
|
206
|
+
require: false,
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
in: 'query',
|
|
210
|
+
name: 'toDate',
|
|
211
|
+
scema: j2s( consolidatedCardSASchema ).swagger,
|
|
212
|
+
require: false,
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
responses: {
|
|
216
|
+
200: { description: 'Successful' },
|
|
217
|
+
401: { description: 'Unauthorized User' },
|
|
218
|
+
422: { description: 'Field Error' },
|
|
219
|
+
500: { description: 'Server Error' },
|
|
220
|
+
204: { description: 'Not Found' },
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
},
|
|
196
224
|
};
|
|
@@ -49,3 +49,13 @@ export const auditWalletSummarySchema = joi.object( {
|
|
|
49
49
|
export const auditWalletSummaryValid = {
|
|
50
50
|
query: auditWalletSummarySchema,
|
|
51
51
|
};
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
export const generateReportSchema = joi.object( {
|
|
55
|
+
fromDate: joi.string().required(),
|
|
56
|
+
toDate: joi.string().required(),
|
|
57
|
+
} );
|
|
58
|
+
|
|
59
|
+
export const generateReportValid = {
|
|
60
|
+
query: generateReportSchema,
|
|
61
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import { auditUserDetailsValid, auditUserSummaryValid, auditWalletSummaryValid, consolidatedCardSAValid } from '../dtos/auditWallet.dtos.js';
|
|
2
|
+
import { auditUserDetailsValid, auditUserSummaryValid, auditWalletSummaryValid, consolidatedCardSAValid, generateReportValid } from '../dtos/auditWallet.dtos.js';
|
|
3
3
|
import { dateValidation, ValidateConsolidatedCard, roleVerification, ValidateWalletSummary } from '../validation/auditWallet.validation.js';
|
|
4
4
|
import { accessVerification, isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
5
|
-
import { auditUserSummary, auditWalletSummary, consolidatedCard, getAuditUserDetails } from '../controllers/auditWallet.controllers.js';
|
|
5
|
+
import { auditUserSummary, auditWalletSummary, consolidatedCard, generateReport, getAuditUserDetails } from '../controllers/auditWallet.controllers.js';
|
|
6
6
|
|
|
7
7
|
export const auditWalletRouter = Router();
|
|
8
8
|
|
|
@@ -13,6 +13,7 @@ auditWalletRouter.get( '/audit-user-summary', isAllowedSessionHandler, accessVer
|
|
|
13
13
|
auditWalletRouter.get( '/get-audit-user-details', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), roleVerification, validate( auditUserDetailsValid ), getAuditUserDetails );
|
|
14
14
|
auditWalletRouter.get( '/consolidated-card', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), ValidateConsolidatedCard, validate( consolidatedCardSAValid ), consolidatedCard );
|
|
15
15
|
auditWalletRouter.get( '/audit-wallet-summary', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), ValidateWalletSummary, validate( auditWalletSummaryValid ), auditWalletSummary );
|
|
16
|
+
auditWalletRouter.get( '/generate-report', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), roleVerification, validate( generateReportValid ), generateReport );
|
|
16
17
|
|
|
17
18
|
export default auditWalletRouter;
|
|
18
19
|
|
|
@@ -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
|
+
{ $inc: lateLogin,
|
|
14
|
+
$setOnInsert: record }, { upsert: true } );
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
export function updateManyAuditUsers( query, fields ) {
|