tango-app-api-audit 3.4.25 → 3.4.27

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/app.js ADDED
@@ -0,0 +1,45 @@
1
+ import express from 'express';
2
+ import { auditRouter } from './index.js';
3
+ import dotenv from 'dotenv';
4
+ import { logger } from 'tango-app-api-middleware';
5
+ import { connectdb } from './config/database/database.js';
6
+ import responseMiddleware from './config/response/response.js';
7
+ import errorMiddleware from './config/response/error.js';
8
+ import pkg from 'body-parser';
9
+ import { swaggerConfig } from './config/swagger/swagger.js';
10
+ import swagger from 'swagger-ui-express';
11
+ import { traxAuditRouter } from './src/routes/traxAudit.routes.js';
12
+ import { auditWalletRouter } from './src/routes/auditWallet.routes.js';
13
+ // import externalParameterModel from 'tango-api-schema/schema/externalParameter.model.js';
14
+
15
+ const { json, urlencoded } = pkg;
16
+ const env=dotenv.config();
17
+
18
+ const app = express();
19
+ const PORT = process.env.PORT || 3000;
20
+
21
+
22
+ app.use( json( { limit: '500mb' } ) );
23
+ app.use(
24
+ urlencoded( {
25
+ extended: true,
26
+ } ),
27
+ );
28
+ app.use( responseMiddleware );
29
+ app.use( errorMiddleware );
30
+ if ( env.error ) {
31
+ logger.error( '.env not found' );
32
+ process.exit( 1 );
33
+ }
34
+
35
+
36
+ app.use( '/api-docs', swagger.serve, swagger.setup( swaggerConfig ) );
37
+ app.use( '/v3/audit', auditRouter );
38
+ app.use( '/v3/trax-audit', traxAuditRouter );
39
+ app.use( '/v3/audit-wallet', auditWalletRouter );
40
+
41
+ app.listen( PORT, async () => {
42
+ connectdb();
43
+ logger.info( `server is running on port= ${PORT} ` );
44
+ } );
45
+
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "3.4.25",
3
+ "version": "3.4.27",
4
4
  "description": "audit & audit metrics apis",
5
- "main": "index.js",
5
+ "main": "app.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "start": "nodemon --exec \"eslint --fix . && node index.js\""
8
+ "start": "nodemon --exec \"eslint --fix . && node app.js\""
9
9
  },
10
10
  "engines": {
11
11
  "node": ">=18.10.0"
@@ -1,7 +1,156 @@
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
- return res.sendSuccess( { result: inputData } );
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
+
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
+ if ( inputData.isExport ) {
87
+ query.push( {
88
+ $project: {
89
+ '_id': 0,
90
+ 'Username': '$userName',
91
+ 'User Email': '$userEmail',
92
+ 'File Date From': '$fileDateFrom',
93
+ 'File Date To': '$fileDateTo',
94
+ 'Total Files': '$totalFilesCount',
95
+ 'Total BC': '$totalBeforeCount',
96
+ 'Total AC': '$totalAfterCount',
97
+ 'Total Earnings(Rs)': { $round: [ '$totalEarn', 2 ] },
98
+ 'BC Credit': '$beforeCountCredit',
99
+ 'AC Credit': '$afterCountCredit',
100
+ 'Deduction by Minimum Target': { $round: [ '$deductionByMinimumTarget', 2 ] },
101
+ 'Deduction by Mapping': { $round: [ '$deductionByMapping' ] },
102
+ 'Deduction by Late Login': { $round: [ '$deductionByLateLogin', 2 ] },
103
+ 'Total Reduced Amount': { $round: [ '$totalReducedAmount', 2 ] },
104
+ 'Total Credit': { $round: [ '$totalCredit', 2 ] },
105
+ },
106
+ } );
107
+ } else {
108
+ query.push( {
109
+ $project: {
110
+ '_id': 0,
111
+ 'userName': '$userName',
112
+ 'userEmail': '$userEmail',
113
+ 'fileDateFrom': '$fileDateFrom',
114
+ 'fileDateTo': '$fileDateTo',
115
+ 'totalFiles': '$totalFilesCount',
116
+ 'totalBC': '$totalBeforeCount',
117
+ 'totalAC': '$totalAfterCount',
118
+ 'totalEarnings': { $round: [ '$totalEarn', 2 ] },
119
+ 'bcCredit': '$beforeCountCredit',
120
+ 'acCredit': '$afterCountCredit',
121
+ 'deductionbyMinimumTarget': { $round: [ '$deductionByMinimumTarget', 2 ] },
122
+ 'deductionbyMapping': { $round: [ '$deductionByMapping' ] },
123
+ 'deductionbyLateLogin': { $round: [ '$deductionByLateLogin', 2 ] },
124
+ 'totalReducedAmount': { $round: [ '$totalReducedAmount', 2 ] },
125
+ 'totalCredit': { $round: [ '$totalCredit', 2 ] },
126
+ },
127
+ } );
128
+ }
129
+
130
+ const count = await aggregateAuditUserWallet( query );
131
+ if ( count.length == 0 ) {
132
+ return res.sendError( 'No Data Found', 204 );
133
+ }
134
+
135
+
136
+ if ( inputData.isExport ) {
137
+ await download( count, res );
138
+ return;
139
+ }
140
+
141
+ query.push( {
142
+ $skip: offset,
143
+ },
144
+ {
145
+ $limit: limit,
146
+ } );
147
+
148
+ const result = await aggregateAuditUserWallet( query );
149
+ if ( result.length == 0 ) {
150
+ return res.sendError( 'No Data Found', 204 );
151
+ }
152
+
153
+ return res.sendSuccess( { result: result, count: count.length } );
5
154
  } catch ( error ) {
6
155
  const err = error.message || 'Internal Server Error';
7
156
  logger.error( { error: error, message: req.query, function: 'auditUserSummary' } );
@@ -12,7 +161,73 @@ export async function auditUserSummary( req, res ) {
12
161
  export async function getAuditUserDetails( req, res ) {
13
162
  try {
14
163
  const inputData =req.query;
15
- return res.sendSuccess( { result: inputData } );
164
+ const query =[
165
+ {
166
+ $match: {
167
+ email: { $eq: inputData.userEmail },
168
+ },
169
+ },
170
+ {
171
+ $project: {
172
+ userName: 1,
173
+ tangoUserType: 1,
174
+ role: 1,
175
+ email: 1,
176
+ mobileNumber: 1,
177
+ },
178
+ },
179
+ {
180
+ $lookup: {
181
+ from: 'userAssignedStore',
182
+ let: { email: '$email' },
183
+ pipeline: [
184
+ {
185
+ $match: {
186
+ $expr: {
187
+ $and: [
188
+ {
189
+ $eq: [ '$userEmail', '$$email' ],
190
+ },
191
+ {
192
+ $eq: [ '$userType', 'tango' ],
193
+ },
194
+ {
195
+ $eq: [ '$assignedType', 'client' ],
196
+ },
197
+ ],
198
+ },
199
+ },
200
+ },
201
+ {
202
+ $group: {
203
+ _id: null,
204
+ assignedCount: { $sum: 1 },
205
+ },
206
+ },
207
+ ], as: 'userAssignedStore',
208
+ },
209
+ },
210
+ {
211
+ $unwind: {
212
+ path: '$userAssignedStore', preserveNullAndEmptyArrays: true,
213
+ },
214
+ },
215
+ {
216
+ $project: {
217
+ userName: 1,
218
+ tangoUserType: 1,
219
+ role: 1,
220
+ email: 1,
221
+ mobileNumber: 1,
222
+ clientAssigned: { $ifNull: [ '$userAssignedStore.assignedCount', 0 ] },
223
+ },
224
+ },
225
+ ];
226
+ const result = await aggregateUser( query );
227
+ if ( result.length == 0 ) {
228
+ return res.sendError( 'No Data Found', 204 );
229
+ }
230
+ return res.sendSuccess( { result: result[0] } );
16
231
  } catch ( error ) {
17
232
  const err = error.message || 'Internal Server Error';
18
233
  logger.error( { error: error, message: req.query, function: 'consolidatedCard' } );
@@ -23,7 +238,61 @@ export async function getAuditUserDetails( req, res ) {
23
238
  export async function consolidatedCard( req, res ) {
24
239
  try {
25
240
  const inputData =req.query;
26
- return res.sendSuccess( { result: inputData } );
241
+ let query = [
242
+ {
243
+ $match: {
244
+ $and: [
245
+ {
246
+ fileDateISO: { $lte: new Date( inputData.toDate ) },
247
+ },
248
+ {
249
+ fileDateISO: { $gte: new Date( inputData.fromDate ) },
250
+ },
251
+ {
252
+ userEmail: { $eq: inputData.userEmail },
253
+ },
254
+ ],
255
+ },
256
+
257
+ },
258
+ {
259
+ $sort: {
260
+ fileDate: 1,
261
+ },
262
+ },
263
+ {
264
+ $group: {
265
+ _id: { userEmail: '$userEmail' },
266
+ userEmail: { $first: '$userEmail' },
267
+ totalFilesCount: { $sum: '$totalFilesCount' },
268
+ totalBeforeCount: { $sum: '$totalBeforeCount' },
269
+ totalAfterCount: { $sum: '$totalAfterCount' },
270
+ totalEarn: { $sum: '$totalEarn' },
271
+ totalCredit: { $sum: '$totalCredit' },
272
+ totalReducedAmount: { $sum: '$totalReducedAmount' },
273
+
274
+ },
275
+ },
276
+ {
277
+ $project: {
278
+ '_id': 0,
279
+ 'username': '$userName',
280
+ 'userEmail': '$userEmail',
281
+ 'totalFiles': '$totalFilesCount',
282
+ 'totalBC': '$totalBeforeCount',
283
+ 'totalAC': '$totalAfterCount',
284
+ 'totalEarnings(Rs)': { $round: [ '$totalEarn', 2 ] },
285
+ 'totalReducedAmount': { $round: [ '$totalReducedAmount', 2 ] },
286
+ 'totalCredit': { $round: [ '$totalCredit', 2 ] },
287
+ 'message': req.message,
288
+ },
289
+ },
290
+ ];
291
+ const result = await aggregateAuditUserWallet( query );
292
+ if ( result.length == 0 ) {
293
+ return res.sendError( 'No Data Found', 204 );
294
+ }
295
+ return res.sendSuccess( { result: result[0] } );
27
296
  } catch ( error ) {
28
297
  const err = error.message || 'Internal Server Error';
29
298
  logger.error( { error: error, message: req.query, function: 'consolidatedCard' } );
@@ -34,10 +303,127 @@ export async function consolidatedCard( req, res ) {
34
303
  export async function auditWalletSummary( req, res ) {
35
304
  try {
36
305
  const inputData =req.query;
37
- return res.sendSuccess( { result: inputData } );
306
+ const limit = inputData.isExport? 10000 : inputData.limit || 10;
307
+ const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
308
+ let query = [
309
+ {
310
+ $match: {
311
+ $and: [
312
+ {
313
+ fileDateISO: { $lte: new Date( inputData.toDate ) },
314
+ },
315
+ {
316
+ fileDateISO: { $gte: new Date( inputData.fromDate ) },
317
+ },
318
+ {
319
+ userEmail: { $eq: inputData.userEmail },
320
+ },
321
+ ],
322
+ },
323
+
324
+ },
325
+ {
326
+ $sort: {
327
+ fileDate: 1,
328
+ },
329
+ },
330
+ ];
331
+
332
+ if ( inputData.searchValue && inputData.searchValue !== '' ) {
333
+ query.push( {
334
+ $match: {
335
+ $or: [
336
+ { 'fileDate': { $regex: inputData.searchValue, $options: 'i' } },
337
+ { 'tolFilesCount': { $regex: inputData.searchValue, $options: 'i' } },
338
+ { 'totalBeforeCount': { $regex: inputData.searchValue, $options: 'i' } },
339
+ { 'totalAfterCount': { $regex: inputData.searchValue, $options: 'i' } },
340
+ { 'totalEarn': { $regex: inputData.searchValue, $options: 'i' } },
341
+ { 'deductionByMinimumTarget': { $regex: inputData.searchValue, $options: 'i' } },
342
+ { 'deductionByMapping': { $regex: inputData.searchValue, $options: 'i' } },
343
+ { 'deductionByLateLogin': { $regex: inputData.searchValue, $options: 'i' } },
344
+ { 'totalReducedAmount': { $regex: inputData.searchValue, $options: 'i' } },
345
+ { 'totalCredit': { $regex: inputData.searchValue, $options: 'i' } },
346
+ ],
347
+ },
348
+ } );
349
+ }
350
+ if ( inputData.sortColumnName ) {
351
+ const sortBy = inputData.sortBy || -1;
352
+ const sortColumn = inputData.sortColumnName;
353
+ query.push( {
354
+ $sort: { [sortColumn]: sortBy },
355
+ },
356
+ );
357
+ }
358
+ if ( inputData.isExport ) {
359
+ query.push( {
360
+ $project: {
361
+ '_id': 0,
362
+ 'File Date': '$fileDate',
363
+ 'Total Files': '$tolFilesCount',
364
+ 'Total BC': '$totalBeforeCount',
365
+ 'Total AC': '$totalAfterCount',
366
+ 'Total Earn': '$totalEarn',
367
+ 'Deduction By MinimumTarget': '$deductionByMinimumTarget',
368
+ // 'Mapping Percentage': '$mappingperc',
369
+ 'Deduction By Mapping': '$deductionByMapping',
370
+ 'Deduction By Late Login': '$deductionByLateLogin',
371
+ 'Total Reduced Amount': '$totalReducedAmount',
372
+ 'Total Credit': '$totalCredit',
373
+
374
+
375
+ },
376
+ },
377
+ );
378
+ } else {
379
+ query.push( {
380
+ $project: {
381
+ '_id': 0,
382
+ 'fileDate': '$fileDate',
383
+ 'totalFilesCount': '$totalFilesCount',
384
+ 'totalBeforeCount': '$totalBeforeCount',
385
+ 'totalAfterCount': '$totalAfterCount',
386
+ 'totalEarn': '$totalEarn',
387
+ 'deductionByMinimumTarget': '$deductionByMinimumTarget',
388
+ 'mappingPercentage': '$mappingperc',
389
+ 'deductionByMapping': '$deductionByMapping',
390
+ 'deductionByLateLogin': '$deductionByLateLogin',
391
+ 'totalReducedAmount': '$totalReducedAmount',
392
+ 'totalCredit': '$totalCredit',
393
+
394
+
395
+ },
396
+ },
397
+ );
398
+ }
399
+
400
+ const count = await aggregateAuditUserWallet( query );
401
+ if ( count.length == 0 ) {
402
+ return res.sendError( 'No Data Found', 204 );
403
+ }
404
+
405
+
406
+ if ( inputData.isExport ) {
407
+ await download( count, res );
408
+ return;
409
+ }
410
+
411
+ query.push( {
412
+ $skip: offset,
413
+ },
414
+ {
415
+ $limit: limit,
416
+ } );
417
+
418
+ const result = await aggregateAuditUserWallet( query );
419
+ if ( result.length == 0 ) {
420
+ return res.sendError( 'No Data Found', 204 );
421
+ }
422
+
423
+ return res.sendSuccess( { result: result, count: count.length } );
38
424
  } catch ( error ) {
39
425
  const err = error.message || 'Internal Server Error';
40
- logger.error( { error: error, message: req.query, function: 'consolidatedCard' } );
426
+ logger.error( { error: error, message: req.query, function: 'auditWalletSummary' } );
41
427
  return res.sendError( err, 500 );
42
428
  }
43
429
  }
@@ -75,7 +75,7 @@ export const auditWalletDocs = {
75
75
  parameters: [
76
76
  {
77
77
  in: 'query',
78
- name: 'userId',
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: 'userId',
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: 'fromDate',
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
- userId: joi.string().required(),
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
- userId: joi.string().required(),
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().optional(),
39
- toDate: joi.string().optional(),
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 { roleValidate, roleVerification } from '../validation/auditWallet.validation.js';
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' ] } ), roleValidate, consolidatedCard );
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, fields ) {
9
- return userModel.aggregate( query, fields );
8
+ export function aggregateUser( query ) {
9
+ return userModel.aggregate( query );
10
10
  }
@@ -1,5 +1,5 @@
1
- import { validate } from 'tango-app-api-middleware';
2
- import { consolidatedCardSAValid } from '../dtos/auditWallet.dtos.js';
1
+ import { logger } from 'tango-app-api-middleware';
2
+ import dayjs from 'dayjs';
3
3
 
4
4
  export async function roleVerification( req, res, next ) {
5
5
  try {
@@ -15,22 +15,54 @@ export async function roleVerification( req, res, next ) {
15
15
  }
16
16
  }
17
17
 
18
- export async function roleValidate( req, res, next ) {
18
+ export async function ValidateConsolidatedCard( req, res, next ) {
19
19
  try {
20
20
  if ( [ 'superadmin' ].includes( req?.user?.role ) ) {
21
- validate( consolidatedCardSAValid );
21
+ const message = req.query.fromDate == req.query.toDate ? dayjs( req.query.fromDate ).format( 'DD MMM, YYYY' ) : `${ dayjs( req.query.fromDate ).format( 'DD MMM, YYYY' ) } - ${ dayjs( req.query.toDate ).format( 'DD MMM, YYYY' )}`;
22
+ req.message = `Total Credits for ${message}`;
22
23
  return next();
23
24
  } else {
24
25
  const yesterday = dayjs( new Date() ).subtract( 1, 'days' );
25
26
  const yesterdayFT = new Date( dayjs( yesterday ).format( 'YYYY-MM-DD' ) );
26
- req.query = req.user._id;
27
- req.fromDate = yesterdayFT;
28
- req.toDate = yesterdayFT;
27
+ req.query.userEmail = req.user.email;
28
+ req.query.fromDate = yesterdayFT;
29
+ req.query.toDate = yesterdayFT;
30
+ req.message = 'Total Credits for yesterday';
29
31
  return next();
30
32
  }
31
33
  } catch ( error ) {
32
34
  const err = error.message || 'Internal Server Error';
33
- logger.error( { error: error, message: req.body, function: 'roleValidate' } );
35
+ logger.error( { error: error, message: req.body, function: 'ValidateConsolidatedCard' } );
36
+ return res.sendError( err, 500 );
37
+ }
38
+ }
39
+
40
+ export async function ValidateWalletSummary( req, res, next ) {
41
+ try {
42
+ if ( [ 'superadmin' ].includes( req?.user?.role ) ) {
43
+ return next();
44
+ } else {
45
+ req.query.userEmail = req.user.email;
46
+ return next();
47
+ }
48
+ } catch ( error ) {
49
+ const err = error.message || 'Internal Server Error';
50
+ logger.error( { error: error, message: req.body, function: 'ValidateWalletSummary' } );
51
+ return res.sendError( err, 500 );
52
+ }
53
+ }
54
+
55
+ export async function dateValidation( req, res, next ) {
56
+ try {
57
+ const inputData = req.method === 'POST' ? req.body : req.query;
58
+ if ( inputData ) {
59
+ return next();
60
+ } else {
61
+ return res.sendError( 'From Date is Greater than To Date', 400 );
62
+ }
63
+ } catch ( error ) {
64
+ const err = error.message || 'Internal Server Error';
65
+ logger.error( { error: error, message: req.body, function: 'dateValidation' } );
34
66
  return res.sendError( err, 500 );
35
67
  }
36
68
  }