tango-app-api-audit 3.4.24 → 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/index.js CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
  import { auditRouter } from './src/routes/audit.routes.js';
4
4
  import { traxAuditRouter } from './src/routes/traxAudit.routes.js';
5
+ import { auditWalletRouter } from './src/routes/auditWallet.routes.js';
5
6
  import { auditDocs } from './src/docs/audit.docs.js';
6
7
  import { traxAuditDocs } from './src/docs/traxAudit.docs.js';
8
+ import { auditWalletDocs } from './src/docs/auditWallet.docs.js';
7
9
 
8
- export { auditRouter, auditDocs, traxAuditRouter, traxAuditDocs };
10
+ export { auditRouter, auditDocs, traxAuditRouter, traxAuditDocs, auditWalletRouter, auditWalletDocs };
9
11
 
10
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "3.4.24",
3
+ "version": "3.4.26",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -3950,7 +3950,7 @@ export async function getUserAuditCount( req, res ) {
3950
3950
  // if ( isFirstDay ) {
3951
3951
  // await updateManyAuditUsers( {}, { lateLogin: 0 } );
3952
3952
  // }
3953
- for ( let i =1; i<7; i++ ) {
3953
+ for ( let i =2; i<32; i++ ) {
3954
3954
  const userWallet = JSON.parse( process.env.USER_WALLET );
3955
3955
  const previousDate = dayjs( new Date() ).subtract( i, 'days' );
3956
3956
  const fileDate = dayjs( previousDate ).format( 'DD-MM-YYYY' );
@@ -4345,7 +4345,7 @@ export async function getUserAuditCount( req, res ) {
4345
4345
  if ( result.length == 0 ) {
4346
4346
  return res.sendError( 'No Record Inserted', 500 );
4347
4347
  }
4348
- if ( i == 6 ) {
4348
+ if ( i == 31 ) {
4349
4349
  return res.sendSuccess( { message: 'Inserted successfully!' } );
4350
4350
  }
4351
4351
  }
@@ -0,0 +1,491 @@
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
+
5
+ export async function auditUserSummary( req, res ) {
6
+ try {
7
+ const inputData =req.query;
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 } );
189
+ } catch ( error ) {
190
+ const err = error.message || 'Internal Server Error';
191
+ logger.error( { error: error, message: req.query, function: 'auditUserSummary' } );
192
+ return res.sendError( err, 500 );
193
+ }
194
+ }
195
+
196
+ export async function getAuditUserDetails( req, res ) {
197
+ try {
198
+ const inputData =req.query;
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] } );
266
+ } catch ( error ) {
267
+ const err = error.message || 'Internal Server Error';
268
+ logger.error( { error: error, message: req.query, function: 'consolidatedCard' } );
269
+ return res.sendError( err, 500 );
270
+ }
271
+ }
272
+
273
+ export async function consolidatedCard( req, res ) {
274
+ try {
275
+ const inputData =req.query;
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] } );
331
+ } catch ( error ) {
332
+ const err = error.message || 'Internal Server Error';
333
+ logger.error( { error: error, message: req.query, function: 'consolidatedCard' } );
334
+ return res.sendError( err, 500 );
335
+ }
336
+ }
337
+
338
+ export async function auditWalletSummary( req, res ) {
339
+ try {
340
+ const inputData =req.query;
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 } );
484
+ } catch ( error ) {
485
+ const err = error.message || 'Internal Server Error';
486
+ logger.error( { error: error, message: req.query, function: 'auditWalletSummary' } );
487
+ return res.sendError( err, 500 );
488
+ }
489
+ }
490
+
491
+
@@ -1,4 +1,4 @@
1
- import { checkFileExist, chunkArray, download, getDate, getDateWithCustomizeTime, getUTC, insertOpenSearchData, listFileByPath, logger, signedUrl, sqsReceive } from 'tango-app-api-middleware';
1
+ import { checkFileExist, chunkArray, download, getDate, getDateWithCustomizeTime, getOpenSearchData, getUTC, insertOpenSearchData, listFileByPath, logger, signedUrl, sqsReceive, updateOpenSearchData } from 'tango-app-api-middleware';
2
2
  import { aggregateBinaryAudit, createBinaryAudit, updateOneBinaryAuditModel } from '../service/binaryAudit.service.js';
3
3
  import { countDocumentsStore, findOneStore } from '../service/store.service.js';
4
4
  import { findOneUser } from '../service/user.service.js';
@@ -3979,7 +3979,43 @@ export async function save( req, res ) {
3979
3979
  folderPath: getFilePath?.sqs?.Body?.folderPath,
3980
3980
  createdAt: new Date(),
3981
3981
  };
3982
- await insertOpenSearchData( openSearch.traxDetectionOutput, output );
3982
+ let filter= [
3983
+ {
3984
+ 'term': {
3985
+ 'storeId.keyword': inputData.storeId,
3986
+ },
3987
+ },
3988
+ {
3989
+ 'term': {
3990
+ 'fileDate.keyword': inputData.fileDate,
3991
+ },
3992
+ },
3993
+ ];
3994
+
3995
+ inputData.moduleType === 'hygiene'?
3996
+ filter.push( {
3997
+ 'term': {
3998
+ 'zoneName.keyword': inputData.zoneName,
3999
+ },
4000
+ } ) : null;
4001
+
4002
+ let searchQuery={
4003
+ 'size': 1,
4004
+ 'query': {
4005
+ 'bool': {
4006
+ 'must': filter,
4007
+ },
4008
+ },
4009
+ };
4010
+
4011
+ const searchData= await getOpenSearchData( openSearch.nob, searchQuery );
4012
+ logger.info( { length: searchData?.body?.hits?.hits?.length, _id: searchData?.body?.hits?.hits[0]?._id, output: output } );
4013
+ if ( searchData?.body?.hits?.hits?.length >0 ) {
4014
+ await updateOpenSearchData( openSearch.traxDetectionOutput, searchData?.body?.hits?.hits[0]?._id, { doc: output } );
4015
+ } else {
4016
+ await insertOpenSearchData( openSearch.traxDetectionOutput, output );
4017
+ }
4018
+
3983
4019
  const logData = {
3984
4020
  userId: req.user._id,
3985
4021
  userName: req.user.userName,
@@ -0,0 +1,196 @@
1
+ import j2s from 'joi-to-swagger';
2
+ import { auditUserDetailsSchema, auditUserSummarySchema, auditWalletSummarySchema, consolidatedCardSASchema } from '../dtos/auditWallet.dtos.js';
3
+
4
+ export const auditWalletDocs = {
5
+
6
+ '/v3/audit-wallet/audit-user-summary': {
7
+ get: {
8
+ tags: [ 'Audit Wallet' ],
9
+ description: 'Consolidated wallet details of each audit users for a superadmin view',
10
+ operationId: 'audit-user-summary',
11
+ parameters: [
12
+ {
13
+ in: 'query',
14
+ name: 'fromDate',
15
+ scema: j2s( auditUserSummarySchema ).swagger,
16
+ require: true,
17
+ },
18
+ {
19
+ in: 'query',
20
+ name: 'toDate',
21
+ scema: j2s( auditUserSummarySchema ).swagger,
22
+ require: true,
23
+ },
24
+ {
25
+ in: 'query',
26
+ name: 'searchValue',
27
+ scema: j2s( auditUserSummarySchema ).swagger,
28
+ require: false,
29
+ },
30
+ {
31
+ in: 'query',
32
+ name: 'limit',
33
+ scema: j2s( auditUserSummarySchema ).swagger,
34
+ require: false,
35
+ },
36
+ {
37
+ in: 'query',
38
+ name: 'offset',
39
+ scema: j2s( auditUserSummarySchema ).swagger,
40
+ require: false,
41
+ },
42
+ {
43
+ in: 'query',
44
+ name: 'isExport',
45
+ scema: j2s( auditUserSummarySchema ).swagger,
46
+ require: false,
47
+ },
48
+ {
49
+ in: 'query',
50
+ name: 'sortColumnName',
51
+ scema: j2s( auditUserSummarySchema ).swagger,
52
+ require: true,
53
+ },
54
+ {
55
+ in: 'query',
56
+ name: 'sortBy',
57
+ scema: j2s( auditUserSummarySchema ).swagger,
58
+ require: true,
59
+ },
60
+ ],
61
+ responses: {
62
+ 200: { description: 'Successful' },
63
+ 401: { description: 'Unauthorized User' },
64
+ 422: { description: 'Field Error' },
65
+ 500: { description: 'Server Error' },
66
+ 204: { description: 'Not Found' },
67
+ },
68
+ },
69
+ },
70
+ '/v3/audit-wallet/get-audit-user-details': {
71
+ get: {
72
+ tags: [ 'Audit Wallet' ],
73
+ description: 'get a user personal info and assigned client count',
74
+ operationId: 'get-audit-user-details',
75
+ parameters: [
76
+ {
77
+ in: 'query',
78
+ name: 'userEmail',
79
+ scema: j2s( auditUserDetailsSchema ).swagger,
80
+ require: true,
81
+ },
82
+ ],
83
+ responses: {
84
+ 200: { description: 'Successful' },
85
+ 401: { description: 'Unauthorized User' },
86
+ 422: { description: 'Field Error' },
87
+ 500: { description: 'Server Error' },
88
+ 204: { description: 'Not Found' },
89
+ },
90
+ },
91
+ },
92
+ '/v3/audit-wallet/consolidated-card': {
93
+ get: {
94
+ tags: [ 'Audit Wallet' ],
95
+ description: 'get consolidated of wallet details card of a audit user',
96
+ operationId: 'consolidated-card',
97
+ parameters: [
98
+ {
99
+ in: 'query',
100
+ name: 'fromDate',
101
+ scema: j2s( consolidatedCardSASchema ).swagger,
102
+ require: false,
103
+ },
104
+ {
105
+ in: 'query',
106
+ name: 'toDate',
107
+ scema: j2s( consolidatedCardSASchema ).swagger,
108
+ require: false,
109
+ },
110
+ {
111
+ in: 'query',
112
+ name: 'userEmail',
113
+ scema: j2s( consolidatedCardSASchema ).swagger,
114
+ require: false,
115
+ },
116
+ ],
117
+ responses: {
118
+ 200: { description: 'Successful' },
119
+ 401: { description: 'Unauthorized User' },
120
+ 422: { description: 'Field Error' },
121
+ 500: { description: 'Server Error' },
122
+ 204: { description: 'Not Found' },
123
+ },
124
+ },
125
+ },
126
+ '/v3/audit-wallet/audit-wallet-summary': {
127
+ get: {
128
+ tags: [ 'Audit Wallet' ],
129
+ description: 'Get a file via queue message',
130
+ operationId: 'audit-wallet-summary',
131
+ parameters: [
132
+ {
133
+ in: 'query',
134
+ name: 'userEmail',
135
+ scema: j2s( auditWalletSummarySchema ).swagger,
136
+ require: true,
137
+ },
138
+ {
139
+ in: 'query',
140
+ name: 'fromDate',
141
+ scema: j2s( auditWalletSummarySchema ).swagger,
142
+ require: true,
143
+ },
144
+ {
145
+ in: 'query',
146
+ name: 'toDate',
147
+ scema: j2s( auditWalletSummarySchema ).swagger,
148
+ require: true,
149
+ },
150
+ {
151
+ in: 'query',
152
+ name: 'searchValue',
153
+ scema: j2s( auditWalletSummarySchema ).swagger,
154
+ require: false,
155
+ },
156
+ {
157
+ in: 'query',
158
+ name: 'limit',
159
+ scema: j2s( auditWalletSummarySchema ).swagger,
160
+ require: false,
161
+ },
162
+ {
163
+ in: 'query',
164
+ name: 'offset',
165
+ scema: j2s( auditWalletSummarySchema ).swagger,
166
+ require: false,
167
+ },
168
+ {
169
+ in: 'query',
170
+ name: 'isExport',
171
+ scema: j2s( auditWalletSummarySchema ).swagger,
172
+ require: false,
173
+ },
174
+ {
175
+ in: 'query',
176
+ name: 'sortColumnName',
177
+ scema: j2s( auditWalletSummarySchema ).swagger,
178
+ require: true,
179
+ },
180
+ {
181
+ in: 'query',
182
+ name: 'sortBy',
183
+ scema: j2s( auditWalletSummarySchema ).swagger,
184
+ require: true,
185
+ },
186
+ ],
187
+ responses: {
188
+ 200: { description: 'Successful' },
189
+ 401: { description: 'Unauthorized User' },
190
+ 422: { description: 'Field Error' },
191
+ 500: { description: 'Server Error' },
192
+ 204: { description: 'Not Found' },
193
+ },
194
+ },
195
+ },
196
+ };
@@ -0,0 +1,51 @@
1
+ import joi from 'joi';
2
+
3
+
4
+ export const auditUserSummarySchema = joi.object( {
5
+ fromDate: joi.string().optional(),
6
+ toDate: joi.string().optional(),
7
+ searchValue: joi.string().optional().allow( '' ),
8
+ limit: joi.number().optional(),
9
+ offset: joi.number().optional(),
10
+ isExport: joi.boolean().optional(),
11
+ sortColumnName: joi.string().optional(),
12
+ sortBy: joi.number().optional(),
13
+ } );
14
+
15
+ export const auditUserSummaryValid = {
16
+ query: auditUserSummarySchema,
17
+ };
18
+
19
+ export const consolidatedCardSASchema = joi.object( {
20
+ fromDate: joi.string().required(),
21
+ toDate: joi.string().required(),
22
+ userEmail: joi.string().required(),
23
+ } );
24
+
25
+ export const consolidatedCardSAValid = {
26
+ query: consolidatedCardSASchema,
27
+ };
28
+
29
+ export const auditUserDetailsSchema = joi.object( {
30
+ userEmail: joi.string().required(),
31
+ } );
32
+
33
+ export const auditUserDetailsValid = {
34
+ query: auditUserDetailsSchema,
35
+ };
36
+
37
+ export const auditWalletSummarySchema = joi.object( {
38
+ fromDate: joi.string().required(),
39
+ toDate: joi.string().required(),
40
+ userEmail: joi.string().required(),
41
+ searchValue: joi.string().optional().allow( '' ),
42
+ limit: joi.number().optional(),
43
+ offset: joi.number().optional(),
44
+ isExport: joi.boolean().optional(),
45
+ sortColumnName: joi.string().optional(),
46
+ sortBy: joi.number().optional(),
47
+ } );
48
+
49
+ export const auditWalletSummaryValid = {
50
+ query: auditWalletSummarySchema,
51
+ };
@@ -0,0 +1,18 @@
1
+ import { Router } from 'express';
2
+ import { auditUserDetailsValid, auditUserSummaryValid, auditWalletSummaryValid, consolidatedCardSAValid } from '../dtos/auditWallet.dtos.js';
3
+ import { dateValidation, ValidateConsolidatedCard, roleVerification, ValidateWalletSummary } from '../validation/auditWallet.validation.js';
4
+ import { accessVerification, isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
5
+ import { auditUserSummary, auditWalletSummary, consolidatedCard, getAuditUserDetails } from '../controllers/auditWallet.controllers.js';
6
+
7
+ export const auditWalletRouter = Router();
8
+
9
+ // superadmin - view
10
+ auditWalletRouter.get( '/audit-user-summary', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), roleVerification, validate( auditUserSummaryValid ), dateValidation, auditUserSummary );
11
+
12
+ // single user view
13
+ auditWalletRouter.get( '/get-audit-user-details', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( auditUserDetailsValid ), getAuditUserDetails );
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
+
17
+ export default auditWalletRouter;
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, fields ) {
9
- return userModel.aggregate( query, fields );
8
+ export function aggregateUser( query ) {
9
+ return userModel.aggregate( query );
10
10
  }
@@ -0,0 +1,65 @@
1
+ export async function roleVerification( req, res, next ) {
2
+ try {
3
+ if ( [ 'superadmin' ].includes( req?.user?.role ) ) {
4
+ return next();
5
+ } else {
6
+ return res.sendError( 'access forbidden', 403 );
7
+ }
8
+ } catch ( error ) {
9
+ const err = error.message || 'Internal Server Error';
10
+ logger.error( { error: error, message: req.body, function: 'roleVerification' } );
11
+ return res.sendError( err, 500 );
12
+ }
13
+ }
14
+
15
+ export async function ValidateConsolidatedCard( req, res, next ) {
16
+ try {
17
+ if ( [ 'superadmin' ].includes( req?.user?.role ) ) {
18
+ req.message = 'Total Credits for yesterday';
19
+ return next();
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' ) )}`;
22
+ const yesterday = dayjs( new Date() ).subtract( 1, 'days' );
23
+ const yesterdayFT = new Date( dayjs( yesterday ).format( 'YYYY-MM-DD' ) );
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 ) ) {
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 );
59
+ }
60
+ } catch ( error ) {
61
+ const err = error.message || 'Internal Server Error';
62
+ logger.error( { error: error, message: req.body, function: 'dateValidation' } );
63
+ return res.sendError( err, 500 );
64
+ }
65
+ }