tango-app-api-audit 3.4.23 → 3.4.25

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.23",
3
+ "version": "3.4.25",
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
  }
@@ -4735,6 +4735,9 @@ export async function auditViewLogs( req, res ) {
4735
4735
  ],
4736
4736
  },
4737
4737
  },
4738
+ 'sort': [
4739
+ { createdAt: { order: 'desc' } },
4740
+ ],
4738
4741
  };
4739
4742
  break;
4740
4743
  case 'left-in-middle':
@@ -4771,6 +4774,9 @@ export async function auditViewLogs( req, res ) {
4771
4774
  ],
4772
4775
  },
4773
4776
  },
4777
+ 'sort': [
4778
+ { createdAt: { order: 'desc' } },
4779
+ ],
4774
4780
  };
4775
4781
  break;
4776
4782
  case 'uniform-detection':
@@ -4803,6 +4809,9 @@ export async function auditViewLogs( req, res ) {
4803
4809
  ],
4804
4810
  },
4805
4811
  },
4812
+ 'sort': [
4813
+ { createdAt: { order: 'desc' } },
4814
+ ],
4806
4815
  };
4807
4816
  break;
4808
4817
  case 'hygiene':
@@ -4839,6 +4848,9 @@ export async function auditViewLogs( req, res ) {
4839
4848
  ],
4840
4849
  },
4841
4850
  },
4851
+ 'sort': [
4852
+ { createdAt: { order: 'desc' } },
4853
+ ],
4842
4854
  };
4843
4855
  break;
4844
4856
  case 'camera-angle-change':
@@ -4875,6 +4887,9 @@ export async function auditViewLogs( req, res ) {
4875
4887
  ],
4876
4888
  },
4877
4889
  },
4890
+ 'sort': [
4891
+ { createdAt: { order: 'desc' } },
4892
+ ],
4878
4893
  };
4879
4894
  break;
4880
4895
  default:
@@ -4886,7 +4901,7 @@ export async function auditViewLogs( req, res ) {
4886
4901
  logger.info( { logs: logs.body.hits, inputData: inputData, auditLog: parsedOpenSearch.auditLog } );
4887
4902
  if ( logs.body.hits.hits.length > 0 ) {
4888
4903
  const sourcesArray = logs.body.hits.hits.map( ( hit ) => hit._source );
4889
- for ( const i of sourcesArray ) { // Loop through sourcesArray, not result._doc.camera
4904
+ for ( const i of sourcesArray ) { // Loop through sourcesArray
4890
4905
  if ( i.logSubType == 'auditDone' ) {
4891
4906
  const convertedTime = await convertTimestampToDateTime( i.logData.endTime );
4892
4907
  logData.push( {
@@ -0,0 +1,45 @@
1
+ export async function auditUserSummary( req, res ) {
2
+ try {
3
+ const inputData =req.query;
4
+ return res.sendSuccess( { result: inputData } );
5
+ } catch ( error ) {
6
+ const err = error.message || 'Internal Server Error';
7
+ logger.error( { error: error, message: req.query, function: 'auditUserSummary' } );
8
+ return res.sendError( err, 500 );
9
+ }
10
+ }
11
+
12
+ export async function getAuditUserDetails( req, res ) {
13
+ try {
14
+ const inputData =req.query;
15
+ return res.sendSuccess( { result: inputData } );
16
+ } catch ( error ) {
17
+ const err = error.message || 'Internal Server Error';
18
+ logger.error( { error: error, message: req.query, function: 'consolidatedCard' } );
19
+ return res.sendError( err, 500 );
20
+ }
21
+ }
22
+
23
+ export async function consolidatedCard( req, res ) {
24
+ try {
25
+ const inputData =req.query;
26
+ return res.sendSuccess( { result: inputData } );
27
+ } catch ( error ) {
28
+ const err = error.message || 'Internal Server Error';
29
+ logger.error( { error: error, message: req.query, function: 'consolidatedCard' } );
30
+ return res.sendError( err, 500 );
31
+ }
32
+ }
33
+
34
+ export async function auditWalletSummary( req, res ) {
35
+ try {
36
+ const inputData =req.query;
37
+ return res.sendSuccess( { result: inputData } );
38
+ } catch ( error ) {
39
+ const err = error.message || 'Internal Server Error';
40
+ logger.error( { error: error, message: req.query, function: 'consolidatedCard' } );
41
+ return res.sendError( err, 500 );
42
+ }
43
+ }
44
+
45
+
@@ -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';
@@ -2715,6 +2715,7 @@ export async function pendingSummaryTable( req, res ) {
2715
2715
  storeId: 1,
2716
2716
  streamName: 1,
2717
2717
  tempId: 1,
2718
+ zoneName: 1,
2718
2719
  question: 1,
2719
2720
  questionType: 1,
2720
2721
  answer: 1,
@@ -2769,6 +2770,7 @@ export async function pendingSummaryTable( req, res ) {
2769
2770
  storeId: 1,
2770
2771
  streamName: 1,
2771
2772
  tempId: 1,
2773
+ zoneName: 1,
2772
2774
  question: 1,
2773
2775
  questionType: 1,
2774
2776
  answer: 1,
@@ -3977,7 +3979,43 @@ export async function save( req, res ) {
3977
3979
  folderPath: getFilePath?.sqs?.Body?.folderPath,
3978
3980
  createdAt: new Date(),
3979
3981
  };
3980
- 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
+
3981
4019
  const logData = {
3982
4020
  userId: req.user._id,
3983
4021
  userName: req.user.userName,
@@ -0,0 +1,197 @@
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: 'userId',
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: 'userId',
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
+
127
+ '/v3/audit-wallet/audit-wallet-summary': {
128
+ get: {
129
+ tags: [ 'Audit Wallet' ],
130
+ description: 'Get a file via queue message',
131
+ operationId: 'audit-wallet-summary',
132
+ parameters: [
133
+ {
134
+ in: 'query',
135
+ name: 'fromDate',
136
+ scema: j2s( auditWalletSummarySchema ).swagger,
137
+ require: true,
138
+ },
139
+ {
140
+ in: 'query',
141
+ name: 'fromDate',
142
+ scema: j2s( auditWalletSummarySchema ).swagger,
143
+ require: true,
144
+ },
145
+ {
146
+ in: 'query',
147
+ name: 'toDate',
148
+ scema: j2s( auditWalletSummarySchema ).swagger,
149
+ require: true,
150
+ },
151
+ {
152
+ in: 'query',
153
+ name: 'searchValue',
154
+ scema: j2s( auditWalletSummarySchema ).swagger,
155
+ require: false,
156
+ },
157
+ {
158
+ in: 'query',
159
+ name: 'limit',
160
+ scema: j2s( auditWalletSummarySchema ).swagger,
161
+ require: false,
162
+ },
163
+ {
164
+ in: 'query',
165
+ name: 'offset',
166
+ scema: j2s( auditWalletSummarySchema ).swagger,
167
+ require: false,
168
+ },
169
+ {
170
+ in: 'query',
171
+ name: 'isExport',
172
+ scema: j2s( auditWalletSummarySchema ).swagger,
173
+ require: false,
174
+ },
175
+ {
176
+ in: 'query',
177
+ name: 'sortColumnName',
178
+ scema: j2s( auditWalletSummarySchema ).swagger,
179
+ require: true,
180
+ },
181
+ {
182
+ in: 'query',
183
+ name: 'sortBy',
184
+ scema: j2s( auditWalletSummarySchema ).swagger,
185
+ require: true,
186
+ },
187
+ ],
188
+ responses: {
189
+ 200: { description: 'Successful' },
190
+ 401: { description: 'Unauthorized User' },
191
+ 422: { description: 'Field Error' },
192
+ 500: { description: 'Server Error' },
193
+ 204: { description: 'Not Found' },
194
+ },
195
+ },
196
+ },
197
+ };
@@ -0,0 +1,50 @@
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
+ userId: joi.string().required(),
23
+ } );
24
+
25
+ export const consolidatedCardSAValid = {
26
+ query: consolidatedCardSASchema,
27
+ };
28
+
29
+ export const auditUserDetailsSchema = joi.object( {
30
+ userId: joi.string().required(),
31
+ } );
32
+
33
+ export const auditUserDetailsValid = {
34
+ query: auditUserDetailsSchema,
35
+ };
36
+
37
+ export const auditWalletSummarySchema = joi.object( {
38
+ fromDate: joi.string().optional(),
39
+ toDate: joi.string().optional(),
40
+ searchValue: joi.string().optional().allow( '' ),
41
+ limit: joi.number().optional(),
42
+ offset: joi.number().optional(),
43
+ isExport: joi.boolean().optional(),
44
+ sortColumnName: joi.string().optional(),
45
+ sortBy: joi.number().optional(),
46
+ } );
47
+
48
+ export const auditWalletSummaryValid = {
49
+ query: auditWalletSummarySchema,
50
+ };
@@ -0,0 +1,18 @@
1
+ import { Router } from 'express';
2
+ import { auditUserDetailsValid, auditUserSummaryValid, auditWalletSummaryValid } from '../dtos/auditWallet.dtos.js';
3
+ import { roleValidate, roleVerification } 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 ), 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' ] } ), roleValidate, consolidatedCard );
15
+ auditWalletRouter.get( '/audit-wallet-summary', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( auditWalletSummaryValid ), auditWalletSummary );
16
+
17
+ export default auditWalletRouter;
18
+
@@ -0,0 +1,36 @@
1
+ import { validate } from 'tango-app-api-middleware';
2
+ import { consolidatedCardSAValid } from '../dtos/auditWallet.dtos.js';
3
+
4
+ export async function roleVerification( req, res, next ) {
5
+ try {
6
+ if ( [ 'superadmin' ].includes( req?.user?.role ) ) {
7
+ return next();
8
+ } else {
9
+ return res.sendError( 'access forbidden', 403 );
10
+ }
11
+ } catch ( error ) {
12
+ const err = error.message || 'Internal Server Error';
13
+ logger.error( { error: error, message: req.body, function: 'roleVerification' } );
14
+ return res.sendError( err, 500 );
15
+ }
16
+ }
17
+
18
+ export async function roleValidate( req, res, next ) {
19
+ try {
20
+ if ( [ 'superadmin' ].includes( req?.user?.role ) ) {
21
+ validate( consolidatedCardSAValid );
22
+ return next();
23
+ } else {
24
+ const yesterday = dayjs( new Date() ).subtract( 1, 'days' );
25
+ const yesterdayFT = new Date( dayjs( yesterday ).format( 'YYYY-MM-DD' ) );
26
+ req.query = req.user._id;
27
+ req.fromDate = yesterdayFT;
28
+ req.toDate = yesterdayFT;
29
+ return next();
30
+ }
31
+ } catch ( error ) {
32
+ const err = error.message || 'Internal Server Error';
33
+ logger.error( { error: error, message: req.body, function: 'roleValidate' } );
34
+ return res.sendError( err, 500 );
35
+ }
36
+ }