tango-app-api-audit 3.4.25 → 3.4.26
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/auditWallet.controllers.js +451 -5
- package/src/docs/auditWallet.docs.js +3 -4
- package/src/dtos/auditWallet.dtos.js +5 -4
- package/src/routes/auditWallet.routes.js +5 -5
- package/src/service/auditUserWallet.service.js +4 -0
- package/src/service/user.service.js +2 -2
- package/src/validation/auditWallet.validation.js +38 -9
package/package.json
CHANGED
|
@@ -1,7 +1,191 @@
|
|
|
1
|
+
import { download, logger } from 'tango-app-api-middleware';
|
|
2
|
+
import { aggregateAuditUserWallet } from '../service/auditUserWallet.service.js';
|
|
3
|
+
import { aggregateUser } from '../service/user.service.js';
|
|
4
|
+
|
|
1
5
|
export async function auditUserSummary( req, res ) {
|
|
2
6
|
try {
|
|
3
7
|
const inputData =req.query;
|
|
4
|
-
|
|
8
|
+
const limit = inputData.isExport? 10000 : inputData.limit || 10;
|
|
9
|
+
const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
|
|
10
|
+
let query = [
|
|
11
|
+
{
|
|
12
|
+
$match: {
|
|
13
|
+
$and: [
|
|
14
|
+
{
|
|
15
|
+
fileDateISO: { $lte: new Date( inputData.toDate ) },
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
fileDateISO: { $gte: new Date( inputData.fromDate ) },
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
$sort: {
|
|
26
|
+
fileDate: 1,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
$group: {
|
|
31
|
+
_id: { userEmail: '$userEmail' },
|
|
32
|
+
userEmail: { $first: '$userEmail' },
|
|
33
|
+
userName: { $first: '$userName' },
|
|
34
|
+
fileDateFrom: { $first: '$fileDate' },
|
|
35
|
+
fileDateTo: { $last: '$fileDate' },
|
|
36
|
+
noOfDays: { $push: '$fileDate' },
|
|
37
|
+
moduleType: { $first: '$moduleType' },
|
|
38
|
+
totalFilesCount: { $sum: '$totalFilesCount' },
|
|
39
|
+
totalBeforeCount: { $sum: '$totalBeforeCount' },
|
|
40
|
+
totalAfterCount: { $sum: '$totalAfterCount' },
|
|
41
|
+
totalEarn: { $sum: '$totalEarn' },
|
|
42
|
+
afterCountCredit: { $sum: '$afterCountCredit' },
|
|
43
|
+
beforeCountCredit: { $sum: '$beforeCountCredit' },
|
|
44
|
+
deductionBytimeSpent: { $sum: '$deductionBytimeSpent' },
|
|
45
|
+
deductionByMinimumTarget: { $sum: '$deductionByMinimumTarget' },
|
|
46
|
+
deductionByMapping: { $sum: '$deductionByMapping' },
|
|
47
|
+
deductionByLateLogin: { $sum: '$deductionByLateLogin' },
|
|
48
|
+
totalReducedAmount: { $sum: '$totalReducedAmount' },
|
|
49
|
+
totalCredit: { $sum: '$totalCredit' },
|
|
50
|
+
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
// {
|
|
54
|
+
// $project: {
|
|
55
|
+
// '_id': 0,
|
|
56
|
+
// 'Username': '$userName',
|
|
57
|
+
// 'User Email': '$userEmail',
|
|
58
|
+
// 'File Date From': '$fileDateFrom',
|
|
59
|
+
// 'File Date To': '$fileDateTo',
|
|
60
|
+
// 'Total Files': '$totalFilesCount',
|
|
61
|
+
// // 'Product Type': '$moduleType',
|
|
62
|
+
// // 'Time Spent': '$timeSpent',
|
|
63
|
+
// // 'Minimum Target': '$minimumTarget',
|
|
64
|
+
// // 'No Of Days': { $size: '$noOfDays' },
|
|
65
|
+
// 'Total BC': '$totalBeforeCount',
|
|
66
|
+
// 'Total AC': '$totalAfterCount',
|
|
67
|
+
// 'Total Earnings(Rs)': { $round: [ '$totalEarn', 2 ] },
|
|
68
|
+
// 'BC Credit': '$beforeCountCredit',
|
|
69
|
+
// 'AC Credit': '$afterCountCredit',
|
|
70
|
+
// // 'Deduction By TimeSpent': { $round: [ '$deductionBytimeSpent', 2 ] },
|
|
71
|
+
// 'Deduction by Minimum Target': { $round: [ '$deductionByMinimumTarget', 2 ] },
|
|
72
|
+
// 'Deduction by Mapping': { $round: [ '$deductionByMapping' ] },
|
|
73
|
+
// 'Deduction by Late Login': { $round: [ '$deductionByLateLogin', 2 ] },
|
|
74
|
+
// 'Total Reduced Amount': { $round: [ '$totalReducedAmount', 2 ] },
|
|
75
|
+
// 'Total Credit': { $round: [ '$totalCredit', 2 ] },
|
|
76
|
+
// },
|
|
77
|
+
// },
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
if ( inputData.searchValue && inputData.searchValue !== '' ) {
|
|
81
|
+
query.push( {
|
|
82
|
+
$match: {
|
|
83
|
+
$or: [
|
|
84
|
+
{ 'Username': { $regex: inputData.searchValue, $options: 'i' } },
|
|
85
|
+
{ 'User Email': { $regex: inputData.searchValue, $options: 'i' } },
|
|
86
|
+
{ 'File Date From': { $regex: inputData.searchValue, $options: 'i' } },
|
|
87
|
+
{ 'File Date To': { $regex: inputData.searchValue, $options: 'i' } },
|
|
88
|
+
{ 'Total Files': { $regex: inputData.searchValue, $options: 'i' } },
|
|
89
|
+
{ 'Total BC': { $regex: inputData.searchValue, $options: 'i' } },
|
|
90
|
+
{ 'Total AC': { $regex: inputData.searchValue, $options: 'i' } },
|
|
91
|
+
{ 'Total Earnings(Rs)': { $regex: inputData.searchValue, $options: 'i' } },
|
|
92
|
+
{ 'BC Credit': { $regex: inputData.searchValue, $options: 'i' } },
|
|
93
|
+
{ 'AC Credit': { $regex: inputData.searchValue, $options: 'i' } },
|
|
94
|
+
{ 'Deduction by Minimum Target': { $regex: inputData.searchValue, $options: 'i' } },
|
|
95
|
+
{ 'Deduction by Mapping': { $regex: inputData.searchValue, $options: 'i' } },
|
|
96
|
+
{ 'Deduction by Late Login': { $regex: inputData.searchValue, $options: 'i' } },
|
|
97
|
+
{ 'Total Reduced Amount': { $regex: inputData.searchValue, $options: 'i' } },
|
|
98
|
+
{ 'Total Credit': { $regex: inputData.searchValue, $options: 'i' } },
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
} );
|
|
102
|
+
}
|
|
103
|
+
if ( inputData.sortColumnName ) {
|
|
104
|
+
const sortBy = inputData.sortBy || -1;
|
|
105
|
+
const sortColumn = inputData.sortColumnName;
|
|
106
|
+
query.push( {
|
|
107
|
+
$sort: { [sortColumn]: sortBy },
|
|
108
|
+
},
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
if ( inputData.isExport ) {
|
|
112
|
+
query.push( {
|
|
113
|
+
$project: {
|
|
114
|
+
'_id': 0,
|
|
115
|
+
'Username': '$userName',
|
|
116
|
+
'User Email': '$userEmail',
|
|
117
|
+
'File Date From': '$fileDateFrom',
|
|
118
|
+
'File Date To': '$fileDateTo',
|
|
119
|
+
'Total Files': '$totalFilesCount',
|
|
120
|
+
// 'Product Type': '$moduleType',
|
|
121
|
+
// 'Time Spent': '$timeSpent',
|
|
122
|
+
// 'Minimum Target': '$minimumTarget',
|
|
123
|
+
// 'No Of Days': { $size: '$noOfDays' },
|
|
124
|
+
'Total BC': '$totalBeforeCount',
|
|
125
|
+
'Total AC': '$totalAfterCount',
|
|
126
|
+
'Total Earnings(Rs)': { $round: [ '$totalEarn', 2 ] },
|
|
127
|
+
'BC Credit': '$beforeCountCredit',
|
|
128
|
+
'AC Credit': '$afterCountCredit',
|
|
129
|
+
// 'Deduction By TimeSpent': { $round: [ '$deductionBytimeSpent', 2 ] },
|
|
130
|
+
'Deduction by Minimum Target': { $round: [ '$deductionByMinimumTarget', 2 ] },
|
|
131
|
+
'Deduction by Mapping': { $round: [ '$deductionByMapping' ] },
|
|
132
|
+
'Deduction by Late Login': { $round: [ '$deductionByLateLogin', 2 ] },
|
|
133
|
+
'Total Reduced Amount': { $round: [ '$totalReducedAmount', 2 ] },
|
|
134
|
+
'Total Credit': { $round: [ '$totalCredit', 2 ] },
|
|
135
|
+
},
|
|
136
|
+
} );
|
|
137
|
+
} else {
|
|
138
|
+
query.push( {
|
|
139
|
+
$project: {
|
|
140
|
+
'_id': 0,
|
|
141
|
+
'Username': '$userName',
|
|
142
|
+
'UserEmail': '$userEmail',
|
|
143
|
+
'FileDateFrom': '$fileDateFrom',
|
|
144
|
+
'FileDateTo': '$fileDateTo',
|
|
145
|
+
'TotalFiles': '$totalFilesCount',
|
|
146
|
+
// 'Product Type': '$moduleType',
|
|
147
|
+
// 'Time Spent': '$timeSpent',
|
|
148
|
+
// 'Minimum Target': '$minimumTarget',
|
|
149
|
+
// 'No Of Days': { $size: '$noOfDays' },
|
|
150
|
+
'TotalBC': '$totalBeforeCount',
|
|
151
|
+
'TotalAC': '$totalAfterCount',
|
|
152
|
+
'TotalEarnings(Rs)': { $round: [ '$totalEarn', 2 ] },
|
|
153
|
+
'BCCredit': '$beforeCountCredit',
|
|
154
|
+
'ACCredit': '$afterCountCredit',
|
|
155
|
+
// 'Deduction By TimeSpent': { $round: [ '$deductionBytimeSpent', 2 ] },
|
|
156
|
+
'DeductionbyMinimum Target': { $round: [ '$deductionByMinimumTarget', 2 ] },
|
|
157
|
+
'DeductionbyMapping': { $round: [ '$deductionByMapping' ] },
|
|
158
|
+
'DeductionbyLateLogin': { $round: [ '$deductionByLateLogin', 2 ] },
|
|
159
|
+
'TotalReducedAmount': { $round: [ '$totalReducedAmount', 2 ] },
|
|
160
|
+
'TotalCredit': { $round: [ '$totalCredit', 2 ] },
|
|
161
|
+
},
|
|
162
|
+
} );
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const count = await aggregateAuditUserWallet( query );
|
|
166
|
+
if ( count.length == 0 ) {
|
|
167
|
+
return res.sendError( 'No Data Found', 204 );
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
if ( inputData.isExport ) {
|
|
172
|
+
await download( count, res );
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
query.push( {
|
|
177
|
+
$skip: offset,
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
$limit: limit,
|
|
181
|
+
} );
|
|
182
|
+
|
|
183
|
+
const result = await aggregateAuditUserWallet( query );
|
|
184
|
+
if ( result.length == 0 ) {
|
|
185
|
+
return res.sendError( 'No Data Found', 204 );
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return res.sendSuccess( { result: result, count: count.length } );
|
|
5
189
|
} catch ( error ) {
|
|
6
190
|
const err = error.message || 'Internal Server Error';
|
|
7
191
|
logger.error( { error: error, message: req.query, function: 'auditUserSummary' } );
|
|
@@ -12,7 +196,73 @@ export async function auditUserSummary( req, res ) {
|
|
|
12
196
|
export async function getAuditUserDetails( req, res ) {
|
|
13
197
|
try {
|
|
14
198
|
const inputData =req.query;
|
|
15
|
-
|
|
199
|
+
const query =[
|
|
200
|
+
{
|
|
201
|
+
$match: {
|
|
202
|
+
email: { $eq: inputData.userEmail },
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
$project: {
|
|
207
|
+
userName: 1,
|
|
208
|
+
tangoUserType: 1,
|
|
209
|
+
role: 1,
|
|
210
|
+
email: 1,
|
|
211
|
+
mobileNumber: 1,
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
$lookup: {
|
|
216
|
+
from: 'userAssignedStore',
|
|
217
|
+
let: { email: '$email' },
|
|
218
|
+
pipeline: [
|
|
219
|
+
{
|
|
220
|
+
$match: {
|
|
221
|
+
$expr: {
|
|
222
|
+
$and: [
|
|
223
|
+
{
|
|
224
|
+
$eq: [ '$userEmail', '$$email' ],
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
$eq: [ '$userType', 'tango' ],
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
$eq: [ '$assignedType', 'client' ],
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
$group: {
|
|
238
|
+
_id: null,
|
|
239
|
+
assignedCount: { $sum: 1 },
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
], as: 'userAssignedStore',
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
$unwind: {
|
|
247
|
+
path: '$userAssignedStore', preserveNullAndEmptyArrays: true,
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
$project: {
|
|
252
|
+
userName: 1,
|
|
253
|
+
tangoUserType: 1,
|
|
254
|
+
role: 1,
|
|
255
|
+
email: 1,
|
|
256
|
+
mobileNumber: 1,
|
|
257
|
+
clientAssigned: { $ifNull: [ '$userAssignedStore.assignedCount', 0 ] },
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
];
|
|
261
|
+
const result = await aggregateUser( query );
|
|
262
|
+
if ( result.length == 0 ) {
|
|
263
|
+
return res.sendError( 'No Data Found', 204 );
|
|
264
|
+
}
|
|
265
|
+
return res.sendSuccess( { result: result[0] } );
|
|
16
266
|
} catch ( error ) {
|
|
17
267
|
const err = error.message || 'Internal Server Error';
|
|
18
268
|
logger.error( { error: error, message: req.query, function: 'consolidatedCard' } );
|
|
@@ -23,7 +273,61 @@ export async function getAuditUserDetails( req, res ) {
|
|
|
23
273
|
export async function consolidatedCard( req, res ) {
|
|
24
274
|
try {
|
|
25
275
|
const inputData =req.query;
|
|
26
|
-
|
|
276
|
+
let query = [
|
|
277
|
+
{
|
|
278
|
+
$match: {
|
|
279
|
+
$and: [
|
|
280
|
+
{
|
|
281
|
+
fileDateISO: { $lte: new Date( inputData.toDate ) },
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
fileDateISO: { $gte: new Date( inputData.fromDate ) },
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
userEmail: { $eq: inputData.userEmail },
|
|
288
|
+
},
|
|
289
|
+
],
|
|
290
|
+
},
|
|
291
|
+
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
$sort: {
|
|
295
|
+
fileDate: 1,
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
$group: {
|
|
300
|
+
_id: { userEmail: '$userEmail' },
|
|
301
|
+
userEmail: { $first: '$userEmail' },
|
|
302
|
+
totalFilesCount: { $sum: '$totalFilesCount' },
|
|
303
|
+
totalBeforeCount: { $sum: '$totalBeforeCount' },
|
|
304
|
+
totalAfterCount: { $sum: '$totalAfterCount' },
|
|
305
|
+
totalEarn: { $sum: '$totalEarn' },
|
|
306
|
+
totalCredit: { $sum: '$totalCredit' },
|
|
307
|
+
totalReducedAmount: { $sum: '$totalReducedAmount' },
|
|
308
|
+
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
$project: {
|
|
313
|
+
'_id': 0,
|
|
314
|
+
'username': '$userName',
|
|
315
|
+
'userEmail': '$userEmail',
|
|
316
|
+
'totalFiles': '$totalFilesCount',
|
|
317
|
+
'totalBC': '$totalBeforeCount',
|
|
318
|
+
'totalAC': '$totalAfterCount',
|
|
319
|
+
'totalEarnings(Rs)': { $round: [ '$totalEarn', 2 ] },
|
|
320
|
+
'totalReducedAmount': { $round: [ '$totalReducedAmount', 2 ] },
|
|
321
|
+
'totalCredit': { $round: [ '$totalCredit', 2 ] },
|
|
322
|
+
'message': req.message,
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
];
|
|
326
|
+
const result = await aggregateAuditUserWallet( query );
|
|
327
|
+
if ( result.length == 0 ) {
|
|
328
|
+
return res.sendError( 'No Data Found', 204 );
|
|
329
|
+
}
|
|
330
|
+
return res.sendSuccess( { result: result[0] } );
|
|
27
331
|
} catch ( error ) {
|
|
28
332
|
const err = error.message || 'Internal Server Error';
|
|
29
333
|
logger.error( { error: error, message: req.query, function: 'consolidatedCard' } );
|
|
@@ -34,10 +338,152 @@ export async function consolidatedCard( req, res ) {
|
|
|
34
338
|
export async function auditWalletSummary( req, res ) {
|
|
35
339
|
try {
|
|
36
340
|
const inputData =req.query;
|
|
37
|
-
|
|
341
|
+
const limit = inputData.isExport? 10000 : inputData.limit || 10;
|
|
342
|
+
const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
|
|
343
|
+
let query = [
|
|
344
|
+
{
|
|
345
|
+
$match: {
|
|
346
|
+
$and: [
|
|
347
|
+
{
|
|
348
|
+
fileDateISO: { $lte: new Date( inputData.toDate ) },
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
fileDateISO: { $gte: new Date( inputData.fromDate ) },
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
userEmail: { $eq: inputData.userEmail },
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
},
|
|
358
|
+
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
$sort: {
|
|
362
|
+
fileDate: 1,
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
];
|
|
366
|
+
|
|
367
|
+
if ( inputData.searchValue && inputData.searchValue !== '' ) {
|
|
368
|
+
query.push( {
|
|
369
|
+
$match: {
|
|
370
|
+
$or: [
|
|
371
|
+
{ 'Username': { $regex: inputData.searchValue, $options: 'i' } },
|
|
372
|
+
{ 'User Email': { $regex: inputData.searchValue, $options: 'i' } },
|
|
373
|
+
{ 'File Date From': { $regex: inputData.searchValue, $options: 'i' } },
|
|
374
|
+
{ 'File Date To': { $regex: inputData.searchValue, $options: 'i' } },
|
|
375
|
+
{ 'Total Files': { $regex: inputData.searchValue, $options: 'i' } },
|
|
376
|
+
{ 'Total BC': { $regex: inputData.searchValue, $options: 'i' } },
|
|
377
|
+
{ 'Total AC': { $regex: inputData.searchValue, $options: 'i' } },
|
|
378
|
+
{ 'Total Earnings(Rs)': { $regex: inputData.searchValue, $options: 'i' } },
|
|
379
|
+
{ 'BC Credit': { $regex: inputData.searchValue, $options: 'i' } },
|
|
380
|
+
{ 'AC Credit': { $regex: inputData.searchValue, $options: 'i' } },
|
|
381
|
+
{ 'Deduction by Minimum Target': { $regex: inputData.searchValue, $options: 'i' } },
|
|
382
|
+
{ 'Deduction by Mapping': { $regex: inputData.searchValue, $options: 'i' } },
|
|
383
|
+
{ 'Deduction by Late Login': { $regex: inputData.searchValue, $options: 'i' } },
|
|
384
|
+
{ 'Total Reduced Amount': { $regex: inputData.searchValue, $options: 'i' } },
|
|
385
|
+
{ 'Total Credit': { $regex: inputData.searchValue, $options: 'i' } },
|
|
386
|
+
],
|
|
387
|
+
},
|
|
388
|
+
} );
|
|
389
|
+
}
|
|
390
|
+
if ( inputData.sortColumnName ) {
|
|
391
|
+
const sortBy = inputData.sortBy || -1;
|
|
392
|
+
const sortColumn = inputData.sortColumnName;
|
|
393
|
+
query.push( {
|
|
394
|
+
$sort: { [sortColumn]: sortBy },
|
|
395
|
+
},
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
if ( inputData.isExport ) {
|
|
399
|
+
query.push( {
|
|
400
|
+
$project: {
|
|
401
|
+
'_id': 0,
|
|
402
|
+
// "User Email":"$userEmail",
|
|
403
|
+
'User Name': '$userName',
|
|
404
|
+
'File Date': '$fileDate',
|
|
405
|
+
'Product Type': '$moduleType',
|
|
406
|
+
'Time Spent': '$timeSpent',
|
|
407
|
+
'Start Time': '$startTime',
|
|
408
|
+
'Minimum Target': '$minimumTarget',
|
|
409
|
+
'Single Image Amount': '$singleImageAmount',
|
|
410
|
+
'Total Files Count': '$totalFilesCount',
|
|
411
|
+
|
|
412
|
+
'Total Before Count': '$totalBeforeCount',
|
|
413
|
+
'Total After Count': '$totalAfterCount',
|
|
414
|
+
'Before Count Credits': '$beforeCountCredit',
|
|
415
|
+
'After Count Credits': '$afterCountCredit',
|
|
416
|
+
'Total Earn': '$totalEarn',
|
|
417
|
+
'Deduction By TimeSpent': '$deductionBytimeSpent',
|
|
418
|
+
'Deduction By MinimumTarget': '$deductionByMinimumTarget',
|
|
419
|
+
'Mapping Percentage': '$mappingperc',
|
|
420
|
+
'Deduction By Mapping': '$deductionByMapping',
|
|
421
|
+
'Deduction By Late Login': '$deductionByLateLogin',
|
|
422
|
+
'Total Reduced Amount': '$totalReducedAmount',
|
|
423
|
+
'Total Credit': '$totalCredit',
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
);
|
|
429
|
+
} else {
|
|
430
|
+
query.push( {
|
|
431
|
+
$project: {
|
|
432
|
+
'_id': 0,
|
|
433
|
+
// "User Email":"$userEmail",
|
|
434
|
+
// 'userName': '$userName',
|
|
435
|
+
'fileDate': '$fileDate',
|
|
436
|
+
'totalFilesCount': '$totalFilesCount',
|
|
437
|
+
// 'productType': '$moduleType',
|
|
438
|
+
// 'timeSpent': '$timeSpent',
|
|
439
|
+
// 'startTime': '$startTime',
|
|
440
|
+
// 'minimumTarget': '$minimumTarget',
|
|
441
|
+
// 'singleImageAmount': '$singleImageAmount',
|
|
442
|
+
'totalBeforeCount': '$totalBeforeCount',
|
|
443
|
+
'totalAfterCount': '$totalAfterCount',
|
|
444
|
+
'totalEarn': '$totalEarn',
|
|
445
|
+
// 'beforeCountCredits': '$beforeCountCredit',
|
|
446
|
+
// 'afterCountCredits': '$afterCountCredit',
|
|
447
|
+
'deductionByMinimumTarget': '$deductionByMinimumTarget',
|
|
448
|
+
'mappingPercentage': '$mappingperc',
|
|
449
|
+
'deductionByMapping': '$deductionByMapping',
|
|
450
|
+
'deductionByLateLogin': '$deductionByLateLogin',
|
|
451
|
+
'totalReducedAmount': '$totalReducedAmount',
|
|
452
|
+
'totalCredit': '$totalCredit',
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
},
|
|
456
|
+
},
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
const count = await aggregateAuditUserWallet( query );
|
|
461
|
+
if ( count.length == 0 ) {
|
|
462
|
+
return res.sendError( 'No Data Found', 204 );
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
if ( inputData.isExport ) {
|
|
467
|
+
await download( count, res );
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
query.push( {
|
|
472
|
+
$skip: offset,
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
$limit: limit,
|
|
476
|
+
} );
|
|
477
|
+
|
|
478
|
+
const result = await aggregateAuditUserWallet( query );
|
|
479
|
+
if ( result.length == 0 ) {
|
|
480
|
+
return res.sendError( 'No Data Found', 204 );
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
return res.sendSuccess( { result: result, count: count.length } );
|
|
38
484
|
} catch ( error ) {
|
|
39
485
|
const err = error.message || 'Internal Server Error';
|
|
40
|
-
logger.error( { error: error, message: req.query, function: '
|
|
486
|
+
logger.error( { error: error, message: req.query, function: 'auditWalletSummary' } );
|
|
41
487
|
return res.sendError( err, 500 );
|
|
42
488
|
}
|
|
43
489
|
}
|
|
@@ -75,7 +75,7 @@ export const auditWalletDocs = {
|
|
|
75
75
|
parameters: [
|
|
76
76
|
{
|
|
77
77
|
in: 'query',
|
|
78
|
-
name: '
|
|
78
|
+
name: 'userEmail',
|
|
79
79
|
scema: j2s( auditUserDetailsSchema ).swagger,
|
|
80
80
|
require: true,
|
|
81
81
|
},
|
|
@@ -109,7 +109,7 @@ export const auditWalletDocs = {
|
|
|
109
109
|
},
|
|
110
110
|
{
|
|
111
111
|
in: 'query',
|
|
112
|
-
name: '
|
|
112
|
+
name: 'userEmail',
|
|
113
113
|
scema: j2s( consolidatedCardSASchema ).swagger,
|
|
114
114
|
require: false,
|
|
115
115
|
},
|
|
@@ -123,7 +123,6 @@ export const auditWalletDocs = {
|
|
|
123
123
|
},
|
|
124
124
|
},
|
|
125
125
|
},
|
|
126
|
-
|
|
127
126
|
'/v3/audit-wallet/audit-wallet-summary': {
|
|
128
127
|
get: {
|
|
129
128
|
tags: [ 'Audit Wallet' ],
|
|
@@ -132,7 +131,7 @@ export const auditWalletDocs = {
|
|
|
132
131
|
parameters: [
|
|
133
132
|
{
|
|
134
133
|
in: 'query',
|
|
135
|
-
name: '
|
|
134
|
+
name: 'userEmail',
|
|
136
135
|
scema: j2s( auditWalletSummarySchema ).swagger,
|
|
137
136
|
require: true,
|
|
138
137
|
},
|
|
@@ -19,7 +19,7 @@ export const auditUserSummaryValid = {
|
|
|
19
19
|
export const consolidatedCardSASchema = joi.object( {
|
|
20
20
|
fromDate: joi.string().required(),
|
|
21
21
|
toDate: joi.string().required(),
|
|
22
|
-
|
|
22
|
+
userEmail: joi.string().required(),
|
|
23
23
|
} );
|
|
24
24
|
|
|
25
25
|
export const consolidatedCardSAValid = {
|
|
@@ -27,7 +27,7 @@ export const consolidatedCardSAValid = {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
export const auditUserDetailsSchema = joi.object( {
|
|
30
|
-
|
|
30
|
+
userEmail: joi.string().required(),
|
|
31
31
|
} );
|
|
32
32
|
|
|
33
33
|
export const auditUserDetailsValid = {
|
|
@@ -35,8 +35,9 @@ export const auditUserDetailsValid = {
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
export const auditWalletSummarySchema = joi.object( {
|
|
38
|
-
fromDate: joi.string().
|
|
39
|
-
toDate: joi.string().
|
|
38
|
+
fromDate: joi.string().required(),
|
|
39
|
+
toDate: joi.string().required(),
|
|
40
|
+
userEmail: joi.string().required(),
|
|
40
41
|
searchValue: joi.string().optional().allow( '' ),
|
|
41
42
|
limit: joi.number().optional(),
|
|
42
43
|
offset: joi.number().optional(),
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import { auditUserDetailsValid, auditUserSummaryValid, auditWalletSummaryValid } from '../dtos/auditWallet.dtos.js';
|
|
3
|
-
import {
|
|
2
|
+
import { auditUserDetailsValid, auditUserSummaryValid, auditWalletSummaryValid, consolidatedCardSAValid } from '../dtos/auditWallet.dtos.js';
|
|
3
|
+
import { dateValidation, ValidateConsolidatedCard, roleVerification, ValidateWalletSummary } from '../validation/auditWallet.validation.js';
|
|
4
4
|
import { accessVerification, isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
5
5
|
import { auditUserSummary, auditWalletSummary, consolidatedCard, getAuditUserDetails } from '../controllers/auditWallet.controllers.js';
|
|
6
6
|
|
|
7
7
|
export const auditWalletRouter = Router();
|
|
8
8
|
|
|
9
9
|
// superadmin - view
|
|
10
|
-
auditWalletRouter.get( '/audit-user-summary', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), roleVerification, validate( auditUserSummaryValid ), auditUserSummary );
|
|
10
|
+
auditWalletRouter.get( '/audit-user-summary', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), roleVerification, validate( auditUserSummaryValid ), dateValidation, auditUserSummary );
|
|
11
11
|
|
|
12
12
|
// single user view
|
|
13
13
|
auditWalletRouter.get( '/get-audit-user-details', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( auditUserDetailsValid ), getAuditUserDetails );
|
|
14
|
-
auditWalletRouter.get( '/consolidated-card', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ),
|
|
15
|
-
auditWalletRouter.get( '/audit-wallet-summary', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( auditWalletSummaryValid ), auditWalletSummary );
|
|
14
|
+
auditWalletRouter.get( '/consolidated-card', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), ValidateConsolidatedCard, validate( consolidatedCardSAValid ), consolidatedCard );
|
|
15
|
+
auditWalletRouter.get( '/audit-wallet-summary', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), ValidateWalletSummary, validate( auditWalletSummaryValid ), auditWalletSummary );
|
|
16
16
|
|
|
17
17
|
export default auditWalletRouter;
|
|
18
18
|
|
|
@@ -15,3 +15,7 @@ export function updateManyAuditUserWallet( query, record ) {
|
|
|
15
15
|
export function createempDetectionOutput( query, field, option ) {
|
|
16
16
|
return empDetectionOutputModel.updateOne( query, field, option );
|
|
17
17
|
};
|
|
18
|
+
|
|
19
|
+
export function aggregateAuditUserWallet( query ) {
|
|
20
|
+
return auditUserWalletModel.aggregate( query );
|
|
21
|
+
};
|
|
@@ -5,6 +5,6 @@ export function findOneUser( query, fields ) {
|
|
|
5
5
|
return userModel.findOne( query, fields );
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export function aggregateUser( query
|
|
9
|
-
return userModel.aggregate( query
|
|
8
|
+
export function aggregateUser( query ) {
|
|
9
|
+
return userModel.aggregate( query );
|
|
10
10
|
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { validate } from 'tango-app-api-middleware';
|
|
2
|
-
import { consolidatedCardSAValid } from '../dtos/auditWallet.dtos.js';
|
|
3
|
-
|
|
4
1
|
export async function roleVerification( req, res, next ) {
|
|
5
2
|
try {
|
|
6
3
|
if ( [ 'superadmin' ].includes( req?.user?.role ) ) {
|
|
@@ -15,22 +12,54 @@ export async function roleVerification( req, res, next ) {
|
|
|
15
12
|
}
|
|
16
13
|
}
|
|
17
14
|
|
|
18
|
-
export async function
|
|
15
|
+
export async function ValidateConsolidatedCard( req, res, next ) {
|
|
19
16
|
try {
|
|
20
17
|
if ( [ 'superadmin' ].includes( req?.user?.role ) ) {
|
|
21
|
-
|
|
18
|
+
req.message = 'Total Credits for yesterday';
|
|
22
19
|
return next();
|
|
23
20
|
} else {
|
|
21
|
+
const message = req.query.fromDate == req.query.toDate ? new Date( dayjs( req.query.fromDate ).format( 'DD MMM, YYYY' ) ): `${new Date( dayjs( req.query.fromDate ).format( 'DD MMM, YYYY' ) )}-${new Date( dayjs( req.query.toDate ).format( 'DD MMM, YYYY' ) )}`;
|
|
24
22
|
const yesterday = dayjs( new Date() ).subtract( 1, 'days' );
|
|
25
23
|
const yesterdayFT = new Date( dayjs( yesterday ).format( 'YYYY-MM-DD' ) );
|
|
26
|
-
req.query = req.user.
|
|
27
|
-
req.fromDate = yesterdayFT;
|
|
28
|
-
req.toDate = yesterdayFT;
|
|
24
|
+
req.query.userEmail = req.user.email;
|
|
25
|
+
req.query.fromDate = yesterdayFT;
|
|
26
|
+
req.query.toDate = yesterdayFT;
|
|
27
|
+
req.message = `Total Credits for ${message}`;
|
|
28
|
+
return next();
|
|
29
|
+
}
|
|
30
|
+
} catch ( error ) {
|
|
31
|
+
const err = error.message || 'Internal Server Error';
|
|
32
|
+
logger.error( { error: error, message: req.body, function: 'ValidateConsolidatedCard' } );
|
|
33
|
+
return res.sendError( err, 500 );
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function ValidateWalletSummary( req, res, next ) {
|
|
38
|
+
try {
|
|
39
|
+
if ( [ 'superadmin' ].includes( req?.user?.role ) ) {
|
|
29
40
|
return next();
|
|
41
|
+
} else {
|
|
42
|
+
req.query.userEmail = req.user.email;
|
|
43
|
+
return next();
|
|
44
|
+
}
|
|
45
|
+
} catch ( error ) {
|
|
46
|
+
const err = error.message || 'Internal Server Error';
|
|
47
|
+
logger.error( { error: error, message: req.body, function: 'ValidateWalletSummary' } );
|
|
48
|
+
return res.sendError( err, 500 );
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function dateValidation( req, res, next ) {
|
|
53
|
+
try {
|
|
54
|
+
const inputData = req.method === 'POST' ? req.body : req.query;
|
|
55
|
+
if ( inputData ) {
|
|
56
|
+
return next();
|
|
57
|
+
} else {
|
|
58
|
+
return res.sendError( 'From Date is Greater than To Date', 400 );
|
|
30
59
|
}
|
|
31
60
|
} catch ( error ) {
|
|
32
61
|
const err = error.message || 'Internal Server Error';
|
|
33
|
-
logger.error( { error: error, message: req.body, function: '
|
|
62
|
+
logger.error( { error: error, message: req.body, function: 'dateValidation' } );
|
|
34
63
|
return res.sendError( err, 500 );
|
|
35
64
|
}
|
|
36
65
|
}
|