tango-app-api-audit 3.4.67 → 3.4.68-beta.1

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/README.md CHANGED
@@ -1,29 +1,29 @@
1
- # README #
2
-
3
- This README would normally document whatever steps are necessary to get your application up and running.
4
-
5
- ### What is this repository for? ###
6
-
7
- * Quick summary
8
- * Version
9
- * [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
10
-
11
- ### How do I get set up? ###
12
-
13
- * Summary of set up
14
- * Configuration
15
- * Dependencies
16
- * Database configuration
17
- * How to run tests
18
- * Deployment instructions
19
-
20
- ### Contribution guidelines ###
21
-
22
- * Writing tests
23
- * Code review
24
- * Other guidelines
25
-
26
- ### Who do I talk to? ###
27
-
28
- * Repo owner or admin
1
+ # README #
2
+
3
+ This README would normally document whatever steps are necessary to get your application up and running.
4
+
5
+ ### What is this repository for? ###
6
+
7
+ * Quick summary
8
+ * Version
9
+ * [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
10
+
11
+ ### How do I get set up? ###
12
+
13
+ * Summary of set up
14
+ * Configuration
15
+ * Dependencies
16
+ * Database configuration
17
+ * How to run tests
18
+ * Deployment instructions
19
+
20
+ ### Contribution guidelines ###
21
+
22
+ * Writing tests
23
+ * Code review
24
+ * Other guidelines
25
+
26
+ ### Who do I talk to? ###
27
+
28
+ * Repo owner or admin
29
29
  * Other community or team contact
package/index.js CHANGED
@@ -6,7 +6,9 @@ import { auditWalletRouter } from './src/routes/auditWallet.routes.js';
6
6
  import { auditDocs } from './src/docs/audit.docs.js';
7
7
  import { traxAuditDocs } from './src/docs/traxAudit.docs.js';
8
8
  import { auditWalletDocs } from './src/docs/auditWallet.docs.js';
9
+ import { eyeTestAuditRouter } from './src/routes/eyeTestAudit.routes.js';
10
+ import { eyeTestAuditDocs } from './src/docs/eyeTestAudit.docs.js';
9
11
 
10
- export { auditRouter, auditDocs, traxAuditRouter, traxAuditDocs, auditWalletRouter, auditWalletDocs };
12
+ export { auditRouter, auditDocs, traxAuditRouter, traxAuditDocs, auditWalletRouter, auditWalletDocs, eyeTestAuditRouter, eyeTestAuditDocs };
11
13
 
12
14
 
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "3.4.67",
3
+ "version": "3.4.68-beta.1",
4
4
  "description": "audit & audit metrics apis",
5
- "main": "app.js",
5
+ "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "start": "nodemon --exec \"eslint --fix . && node app.js\""
8
+ "start": "nodemon --exec \"eslint --fix . && node index.js\""
9
9
  },
10
10
  "engines": {
11
11
  "node": ">=18.10.0"
@@ -0,0 +1,474 @@
1
+ import { getOpenSearchData, getOpenSearchById, logger, insertOpenSearchData, updateOpenSearchData } from 'tango-app-api-middleware';
2
+ import { findOneUser } from '../service/user.service.js';
3
+ import mongoose from 'mongoose';
4
+ import dayjs from 'dayjs';
5
+ import utc from 'dayjs/plugin/utc.js';
6
+ import timezone from 'dayjs/plugin/timezone.js';
7
+ import 'dayjs/locale/en.js';
8
+
9
+ dayjs.extend( utc );
10
+ dayjs.extend( timezone );
11
+
12
+ export async function getList( req, res ) {
13
+ try {
14
+ const inputData = req.body;
15
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
16
+ const limit = inputData.limit || 10;
17
+ const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
18
+
19
+
20
+ let filter= [
21
+ {
22
+ 'range': {
23
+ 'date': {
24
+ 'gte': new Date( inputData.fromDate ),
25
+ 'lte': new Date( inputData.toDate ),
26
+ },
27
+ },
28
+ },
29
+
30
+ ];
31
+ let search ={
32
+ 'must': filter,
33
+ };
34
+
35
+ if ( inputData.visitorsType && inputData.visitorsType.lenght > 0 ) {
36
+ filter.push( {
37
+
38
+ 'terms': {
39
+ 'visitorsType.keyword': inputData.visitorsType,
40
+ },
41
+
42
+ } );
43
+ }
44
+
45
+ if ( inputData.storeId && inputData.storeId.lenght > 0 ) {
46
+ filter.push( {
47
+
48
+ 'terms': {
49
+ 'storeId.keyword': inputData.storeId,
50
+ },
51
+
52
+ } );
53
+ }
54
+
55
+ if ( inputData.searchValue && inputData.searchValue !== '' ) {
56
+ search ={
57
+ 'must': filter,
58
+ 'should': [
59
+ {
60
+ 'wildcard': {
61
+ 'storeName.keyword': {
62
+ 'value': `*${inputData.searchValue}*`,
63
+ },
64
+ },
65
+ },
66
+ {
67
+ 'wildcard': {
68
+ 'storeId.keyword': {
69
+ 'value': `*${inputData.searchValue}*`,
70
+ },
71
+ },
72
+ },
73
+ {
74
+ 'wildcard': {
75
+ 'engagementId.keyword': {
76
+ 'value': `*${inputData.searchValue}*`,
77
+ },
78
+ },
79
+ },
80
+ {
81
+ 'wildcard': {
82
+ 'queueId.keyword': {
83
+ 'value': `*${inputData.searchValue}*`,
84
+ },
85
+ },
86
+ },
87
+ {
88
+ 'wildcard': {
89
+ 'optumId.keyword': {
90
+ 'value': `*${inputData.engagementId}*`,
91
+ },
92
+ },
93
+ },
94
+ {
95
+ 'wildcard': {
96
+ 'visitorsType.keyword': {
97
+ 'value': `*${inputData.searchValue}*`,
98
+ },
99
+ },
100
+ },
101
+ {
102
+ 'wildcard': {
103
+ 'auditStatus.keyword': {
104
+ 'value': `*${inputData.searchValue}*`,
105
+ },
106
+ },
107
+ },
108
+ ],
109
+ 'minimum_should_match': 1,
110
+ };
111
+ }
112
+
113
+ let searchQuery={
114
+ 'from': offset,
115
+ 'size': limit,
116
+ 'query': {
117
+ 'bool': search,
118
+ },
119
+ };
120
+ const result = await getOpenSearchData( openSearch.EyeTestInput, searchQuery );
121
+ const count = result?.body?.hits?.total?.value;
122
+ if ( !count || count == 0 ) {
123
+ return res.sendError( 'No data found', 204 );
124
+ }
125
+ const searchValue = result?.body?.hits?.hits;
126
+ if ( !searchValue || searchValue?.length == 0 ) {
127
+ return res.sendError( 'No data found', 204 );
128
+ }
129
+ return res.sendSuccess( { result: searchValue, count: count } );
130
+ } catch ( error ) {
131
+ const err = error.message || 'Internal Server Error';
132
+ logger.error( { message: error, data: req.body, function: 'eyetestAudit-controller-getList' } );
133
+ return res.sendError( err, 500 );
134
+ }
135
+ }
136
+
137
+ export async function viewFile( req, res ) {
138
+ try {
139
+ const inputData = req.params;
140
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
141
+ const url = JSON.parse( process.env.URL );
142
+ let isEnable =true;
143
+
144
+ const getInput = await getOpenSearchById( openSearch.EyeTestInput, inputData.id );
145
+ if ( !getInput || !getInput?.body ) {
146
+ return res.sendError( 'No Data Found', 204 );
147
+ }
148
+ const getData =getInput?.body?._source;
149
+
150
+
151
+ let searchFilter =[
152
+ {
153
+ 'terms': {
154
+ 'queueId.keyword': getData?.queueId,
155
+ },
156
+
157
+ },
158
+ {
159
+ 'terms': {
160
+ 'type.keyword': getData?.type,
161
+ },
162
+
163
+ },
164
+ ];
165
+ if ( getData?.type == 'remote' ) {
166
+ searchFilter =[
167
+ {
168
+ 'terms': {
169
+ 'engagementId.keyword': getData?.engagementId,
170
+ },
171
+
172
+ },
173
+ {
174
+ 'terms': {
175
+ 'type.keyword': getData?.type,
176
+ },
177
+
178
+ },
179
+ ];
180
+ }
181
+
182
+ let searchQuery={
183
+ 'size': 1,
184
+ 'query': {
185
+ 'bool': {
186
+ 'must': searchFilter,
187
+ },
188
+ },
189
+ 'sort': [
190
+ { createdAt: { order: 'desc' } },
191
+ ],
192
+ };
193
+ const searchRes= await getOpenSearchData( openSearch.EyeTestOutput, searchQuery );
194
+ const temp = searchRes?.body?.hits?.hits?.lenght > 0? searchRes?.body?.hits?.hits[0] : [];
195
+ const getUserName = await findOneUser( { _id: new mongoose.Types.ObjectId( temp?.userId ) }, { userName: 1 } );
196
+
197
+ const searchData = temp?
198
+ getData['lastAuditedDetails']= {
199
+ 'auditedBy': getUserName?.userName || '',
200
+ 'completionTime': temp?.startTime? new Date( temp?.startTime ).toLocaleTimeString( 'en-IN', { hour12: false } ): '',
201
+ 'timeZone': temp?.timeZone || '',
202
+ } : null;
203
+ getData['complianceScore'] = getData.complianceScore || getData?.totalSteps>0 ? Math.round( ( getData?.coveredStepsAI/ getData?.totalSteps )*100 ): 0;
204
+ getData['trustScore'] = getData?.trustScore || 0;
205
+ getData['testDuration'] = Math.round( getData?.testDuration/60 ) || 0;
206
+ getData['filePath'] = `${url[getData?.type]}${getData?.filePath}`;
207
+ const response = getData;
208
+ switch ( getData?.auditStatus ) {
209
+ case 'Yet-to-Audit':
210
+ isEnable=true;
211
+ break;
212
+ case 'In-Progress':
213
+ if ( searchData.lenght ==0 ) {
214
+ return res.sendError( 'No saved records found', 400 );
215
+ }
216
+ if ( searchData.userId !== req.user._id ) {
217
+ isEnable=false;
218
+ }
219
+ return res.sendSuccess( { result: result } );
220
+ break;
221
+ case 'Audited':
222
+ case 'Re-Audited':
223
+ isEnable=true;
224
+ }
225
+
226
+ return res.sendSuccess( { result: response, isEnable: isEnable } );
227
+ } catch ( error ) {
228
+ const err = error.message || 'Internal Server Error';
229
+ logger.error( { message: error, data: req.body, function: 'eyetestAudit-controller-viewFile' } );
230
+ return res.sendError( err, 500 );
231
+ }
232
+ }
233
+
234
+ export async function getFile( req, res ) {
235
+ try {
236
+ const inputData = req.params;
237
+ const url = JSON.parse( process.env.URL );
238
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
239
+
240
+ const getInput = await getOpenSearchById( openSearch.EyeTestInput, inputData.id );
241
+ if ( !getInput || !getInput?.body ) {
242
+ return res.sendError( 'No Data Found', 204 );
243
+ }
244
+ const getData =getInput?.body?._source;
245
+
246
+
247
+ let searchFilter =[
248
+ {
249
+ 'terms': {
250
+ 'queueId.keyword': getData?.queueId,
251
+ },
252
+
253
+ },
254
+ {
255
+ 'terms': {
256
+ 'type.keyword': getData?.type,
257
+ },
258
+
259
+ },
260
+ ];
261
+ if ( getData?.type == 'remote' ) {
262
+ searchFilter =[
263
+ {
264
+ 'terms': {
265
+ 'engagementId.keyword': getData?.engagementId,
266
+ },
267
+
268
+ },
269
+ {
270
+ 'terms': {
271
+ 'type.keyword': getData?.type,
272
+ },
273
+
274
+ },
275
+ ];
276
+ }
277
+
278
+ let searchQuery={
279
+ 'size': 1,
280
+ 'query': {
281
+ 'bool': {
282
+ 'must': searchFilter,
283
+ },
284
+ },
285
+ 'sort': [
286
+ { createdAt: { order: 'desc' } },
287
+ ],
288
+ };
289
+ const searchRes= await getOpenSearchData( openSearch.EyeTestOutput, searchQuery );
290
+ const searchData = searchRes?.body?.hits?.hits?.lenght > 0? searchRes?.body?.hits?.hits[0] : null;
291
+ logger.info( { searchData: searchData, getData: getData, messahe: '...........3' } );
292
+ switch ( getData?.auditStatus ) {
293
+ case 'Yet-to-Audit':
294
+ const record= {
295
+ 'date': getData?.date,
296
+ 'fileDate': getData?.fileDate,
297
+ 'storeName': getData?.storeName,
298
+ 'storeId': getData?.storeId,
299
+ 'userId': req?.user?._id,
300
+ 'type': getData?.type,
301
+ 'engagementId': getData?.engagementId,
302
+ 'queueId': getData?.queueId,
303
+ 'optumId': getData?.optumId,
304
+ 'displayName': getData?.displayName,
305
+ 'complianceScore': getData?.totalSteps>0 ? Math.round( ( getData?.coveredStepsAI/ getData?.totalSteps )*100 ): 0,
306
+ 'coveredStepsAI': getData?.coveredStepsAI,
307
+ 'auditedSteps': 0,
308
+ 'overRides': 0,
309
+ 'trustScore': 0,
310
+ 'visitorsType': getData?.visitorsType,
311
+ 'testDuration': Math.round( getData?.testDuration/60 ) || 0,
312
+ 'testStartTime': getData?.testStartTime,
313
+ 'testEndTime': getData?.testEndTime,
314
+ 'timeZone': 'IST',
315
+ 'spokenLanguage': '',
316
+ 'auditStatus': 'In-Progress',
317
+ 'totalSteps': getData?.totalSteps,
318
+ 'inputBucketName': getData?.inputBucketName,
319
+ 'filePath': `${url[getData?.type]}${getData?.filePath}`,
320
+ 'steps': getData?.steps,
321
+ 'startTime': dayjs().tz( 'Asia/Kolkata' ),
322
+ 'createdAt': dayjs().tz( 'Asia/Kolkata' ),
323
+ 'updatedAt': dayjs().tz( 'Asia/Kolkata' ),
324
+
325
+ };
326
+ record?.steps?.map( ( item, i ) => {
327
+ record.steps[i]['auditedStatus']= null, record.steps[i]['reason'] = '', record.steps[i]['startTime'] = '', record.steps[i]['endTime'] = '';
328
+ } );
329
+ if ( !searchData ) {
330
+ const data1 = await insertOpenSearchData( openSearch.EyeTestOutput, record );
331
+ logger.info( { data1: data1 } );
332
+ await updateOpenSearchData( openSearch.EyeTestInput, inputData.id, { doc: { auditStatus: 'In-Progress', userId: req?.user?._id } } );
333
+ }
334
+
335
+ break;
336
+ case 'In-Progress':
337
+
338
+ if ( !searchData ) {
339
+ return res.sendError( 'No saved records found', 400 );
340
+ }
341
+ if ( searchData?.userId !== req.user._id ) {
342
+ return res.sendError( 'Forbidden to this action', 403 );
343
+ }
344
+ break;
345
+ case 'Audited':
346
+ case 'Re-Audited':
347
+ const newRecord= {
348
+ 'date': getData?.date,
349
+ 'fileDate': getData?.fileDate,
350
+ 'storeName': getData?.storeName,
351
+ 'storeId': getData?.storeId,
352
+ 'userId': req?.user?._id,
353
+ 'type': getData?.type,
354
+ 'engagementId': getData?.engagementId,
355
+ 'queueId': getData?.queueId,
356
+ 'optumId': getData?.optumId,
357
+ 'displayName': getData?.displayName,
358
+ 'complianceScore': getData?.totalSteps>0 ? Math.round( ( getData?.coveredStepsAI/ getData?.totalSteps )*100 ): 0,
359
+ 'coveredStepsAI': getData?.coveredStepsAI,
360
+ 'auditedSteps': getData?.auditedSteps || 0,
361
+ 'overRides': getData?.overRides || 0,
362
+ 'trustScore': getData?.trustScore || 0,
363
+ 'visitorsType': getData?.visitorsType,
364
+ 'testDuration': getData?.testDuration,
365
+ 'testStartTime': getData?.testStartTime,
366
+ 'testEndTime': getData?.testEndTime,
367
+ 'timeZone': getData?.timeZone,
368
+ 'spokenLanguage': getData?.spokenLanguage || '',
369
+ 'auditStatus': 'In-Progress',
370
+ 'totalSteps': getData?.totalSteps,
371
+ 'filePath': `${url[getData?.type]}${getData?.filePath}`,
372
+ 'steps': getData?.steps,
373
+ 'startTime': dayjs().tz( 'Asia/Kolkata' ),
374
+ 'createdAt': dayjs().tz( 'Asia/Kolkata' ),
375
+ 'updatedAt': dayjs().tz( 'Asia/Kolkata' ),
376
+
377
+ };
378
+ await insertOpenSearchData( openSearch.EyeTestOutput, newRecord );
379
+ await updateOpenSearchData( openSearch.EyeTestInput, inputData.id, { doc: { auditStatus: 'In-Progress' } } );
380
+
381
+ break;
382
+ default:
383
+ return res.sendError( 'Status must be valid', 400 );
384
+ }
385
+
386
+ return res.sendSuccess( 'The status has been updated' );
387
+ } catch ( error ) {
388
+ const err = error.message || 'Internal Server Error';
389
+ logger.error( { message: error, data: req.body, function: 'eyetestAudit-controller-getFile' } );
390
+ return res.sendError( err, 500 );
391
+ }
392
+ }
393
+
394
+ export async function getFileHistory( req, res ) {
395
+ try {
396
+ const parsedOpenSearch = JSON.parse( process.env.OPENSEARCH );
397
+ const inputData = req.params;
398
+ let Query = {};
399
+ if ( inputData.type==='physical' ) {
400
+ Query = {
401
+ 'size': 100,
402
+ 'query': {
403
+ 'bool': {
404
+ 'must': [
405
+ {
406
+ 'term': {
407
+ 'queueId.keyword': inputData.id,
408
+ },
409
+ },
410
+
411
+ ],
412
+ },
413
+ },
414
+ };
415
+ } else {
416
+ Query = {
417
+ 'size': 100,
418
+ 'query': {
419
+ 'bool': {
420
+ 'must': [
421
+ {
422
+ 'term': {
423
+ 'engagementId.keyword': inputData.id,
424
+ },
425
+ },
426
+
427
+ ],
428
+ },
429
+ },
430
+ };
431
+ };
432
+
433
+ const resposnse = await getOpenSearchData( parsedOpenSearch.EyeTestOutput, Query );
434
+ if ( resposnse.body.hits.hits.length > 0 ) {
435
+ let sourcesArray = resposnse.body.hits.hits.map( ( hit ) => hit );
436
+ let outputData=[];
437
+ for ( let data of sourcesArray ) {
438
+ let findUser= await findOneUser( { _id: new mongoose.Types.ObjectId( data._source.userId ) } );
439
+ outputData.push( {
440
+ _id: data._id,
441
+ userId: data._source.userId,
442
+ userName: findUser.userName,
443
+ Date: dayjs( data._source.endTime ).format( 'DD/MM/YYYY' ),
444
+ Time: dayjs( data._source.endTime ).format( 'HH:MM:ss' ),
445
+ } );
446
+ }
447
+
448
+ return res.sendSuccess( { result: outputData } );
449
+ } else {
450
+ return res.sendError( 'No data found', 204 );
451
+ }
452
+ } catch ( error ) {
453
+ const err = error.message || 'Internal Server Error';
454
+ logger.error( { message: error, data: req.body, function: 'eyetestAudit-controller-getFileHistory' } );
455
+ return res.sendError( err, 500 );
456
+ }
457
+ }
458
+
459
+ export async function userAuditedData( req, res ) {
460
+ try {
461
+ const parsedOpenSearch = JSON.parse( process.env.OPENSEARCH );
462
+ const inputData = req.params;
463
+ const resposnse = await getOpenSearchById( parsedOpenSearch.EyeTestOutput, inputData.id );
464
+ if ( resposnse.body&&resposnse.body._source ) {
465
+ return res.sendSuccess( { result: resposnse.body._source.steps } );
466
+ } else {
467
+ return res.sendError( 'No data found', 204 );
468
+ }
469
+ } catch ( error ) {
470
+ const err = error.message || 'Internal Server Error';
471
+ logger.error( { message: error, data: req.body, function: 'eyetestAudit-controller-userAuditedData' } );
472
+ return res.sendError( err, 500 );
473
+ }
474
+ }
@@ -0,0 +1,119 @@
1
+ import j2s from 'joi-to-swagger';
2
+ import { getListSchema, getFileSchema, getFileHistorySchema, userAuditedDataSchema, viewFileSchema } from '../dtos/eyeTestAudit.dtos.js';
3
+
4
+ export const eyeTestAuditDocs = {
5
+
6
+ '/v3/eye-test-audit/get-list': {
7
+ post: {
8
+ tags: [ 'Eye Test Audit' ],
9
+ description: 'Get list of files',
10
+ operationId: 'get-list',
11
+ requestBody: {
12
+ content: {
13
+ 'application/json': {
14
+ schema: j2s( getListSchema ).swagger,
15
+ },
16
+ },
17
+ },
18
+ responses: {
19
+ 200: { description: 'Successful' },
20
+ 401: { description: 'Unauthorized User' },
21
+ 422: { description: 'Field Error' },
22
+ 500: { description: 'Server Error' },
23
+ 204: { description: 'Not Found' },
24
+ },
25
+ },
26
+ },
27
+
28
+ '/v3/eye-test-audit/view-file/{id}': {
29
+ get: {
30
+ tags: [ 'Eye Test Audit' ],
31
+ description: 'View a file via Open Serach',
32
+ operationId: 'view-file',
33
+ parameters: [
34
+ {
35
+ in: 'path',
36
+ name: 'id',
37
+ scema: j2s( viewFileSchema ).swagger,
38
+ require: true,
39
+ },
40
+ ],
41
+ responses: {
42
+ 200: { description: 'Successful' },
43
+ 401: { description: 'Unauthorized User' },
44
+ 422: { description: 'Field Error' },
45
+ 500: { description: 'Server Error' },
46
+ 204: { description: 'Not Found' },
47
+ },
48
+ },
49
+ },
50
+
51
+ '/v3/eye-test-audit/get-file/{id}': {
52
+ get: {
53
+ tags: [ 'Eye Test Audit' ],
54
+ description: 'Get a file via Open Serach',
55
+ operationId: 'get-file',
56
+ parameters: [
57
+ {
58
+ in: 'path',
59
+ name: 'id',
60
+ scema: j2s( getFileSchema ).swagger,
61
+ require: true,
62
+ },
63
+ ],
64
+ responses: {
65
+ 200: { description: 'Successful' },
66
+ 401: { description: 'Unauthorized User' },
67
+ 422: { description: 'Field Error' },
68
+ 500: { description: 'Server Error' },
69
+ 204: { description: 'Not Found' },
70
+ },
71
+ },
72
+ },
73
+
74
+ '/v3/eye-test-audit/get-file-history/{id}': {
75
+ get: {
76
+ tags: [ 'Eye Test Audit' ],
77
+ description: 'Get a file history via Open Serach',
78
+ operationId: 'get-file-history',
79
+ parameters: [
80
+ {
81
+ in: 'path',
82
+ name: 'id',
83
+ scema: j2s( getFileHistorySchema ).swagger,
84
+ require: true,
85
+ },
86
+ ],
87
+ responses: {
88
+ 200: { description: 'Successful' },
89
+ 401: { description: 'Unauthorized User' },
90
+ 422: { description: 'Field Error' },
91
+ 500: { description: 'Server Error' },
92
+ 204: { description: 'Not Found' },
93
+ },
94
+ },
95
+ },
96
+
97
+ '/v3/eye-test-audit/user-audited-data/{id}': {
98
+ get: {
99
+ tags: [ 'Eye Test Audit' ],
100
+ description: `Get a user's audited file`,
101
+ operationId: 'user-audited-data',
102
+ parameters: [
103
+ {
104
+ in: 'path',
105
+ name: 'id',
106
+ scema: j2s( userAuditedDataSchema ).swagger,
107
+ require: true,
108
+ },
109
+ ],
110
+ responses: {
111
+ 200: { description: 'Successful' },
112
+ 401: { description: 'Unauthorized User' },
113
+ 422: { description: 'Field Error' },
114
+ 500: { description: 'Server Error' },
115
+ 204: { description: 'Not Found' },
116
+ },
117
+ },
118
+ },
119
+ };
@@ -0,0 +1,55 @@
1
+ import joi from 'joi';
2
+
3
+ export const getListSchema = joi.object(
4
+ {
5
+ fromDate: joi.string().required(),
6
+ toDate: joi.string().required(),
7
+ type: joi.string().required(),
8
+ demographics: joi.array().optional(),
9
+ storeId: joi.array().optional(),
10
+ limit: joi.number().optional(),
11
+ offset: joi.number().optional(),
12
+ searchValue: joi.string().optional().allow( '' ),
13
+ isExport: joi.boolean().optional(),
14
+ },
15
+ );
16
+
17
+ export const getListValid = {
18
+ body: getListSchema,
19
+ };
20
+
21
+ export const viewFileSchema = joi.object( {
22
+ id: joi.string().required(),
23
+ } );
24
+
25
+ export const viewFileValid = {
26
+ params: viewFileSchema,
27
+ };
28
+
29
+
30
+ export const getFileSchema = joi.object( {
31
+ id: joi.string().required(),
32
+ } );
33
+
34
+ export const getFileValid = {
35
+ params: getFileSchema,
36
+ };
37
+
38
+ export const getFileHistorySchema = joi.object( {
39
+ id: joi.string().required(),
40
+ type: joi.string().required(),
41
+ } );
42
+
43
+ export const getFileHistoryValid = {
44
+ params: getFileHistorySchema,
45
+ };
46
+
47
+ export const userAuditedDataSchema = joi.object( {
48
+ id: joi.string().required(),
49
+ } );
50
+
51
+ export const userAuditedDataValid = {
52
+ params: userAuditedDataSchema,
53
+ };
54
+
55
+
@@ -0,0 +1,17 @@
1
+ import { Router } from 'express';
2
+ import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
3
+ import { accessVerification } from 'tango-app-api-middleware';
4
+ import { getFileHistoryValid, getFileValid, getListValid, userAuditedDataValid, viewFileValid } from '../dtos/eyeTestAudit.dtos.js';
5
+ import { getFile, getFileHistory, getList, userAuditedData, viewFile } from '../controllers/eyeTestAudit.controllers.js';
6
+
7
+ export const eyeTestAuditRouter = Router();
8
+
9
+ eyeTestAuditRouter.post( '/get-list', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( getListValid ), getList );
10
+ eyeTestAuditRouter.get( '/view-file/:id', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( viewFileValid ), viewFile );
11
+ eyeTestAuditRouter.get( '/get-file/:id', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( getFileValid ), getFile );
12
+ eyeTestAuditRouter.post( '/save', isAllowedSessionHandler );
13
+ eyeTestAuditRouter.get( '/get-file-history/:id/:type', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( getFileHistoryValid ), getFileHistory );
14
+ eyeTestAuditRouter.get( '/user-audited-data/:id', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( userAuditedDataValid ), userAuditedData );
15
+
16
+
17
+ export default eyeTestAuditRouter;
package/app.js DELETED
@@ -1,40 +0,0 @@
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 cors from 'cors';
13
- const { json, urlencoded } = pkg;
14
- const env=dotenv.config();
15
-
16
- const app = express();
17
- const PORT = process.env.PORT || 3000;
18
- app.use( cors() );
19
-
20
- app.use( json( { limit: '500mb' } ) );
21
- app.use(
22
- urlencoded( {
23
- extended: true,
24
- } ),
25
- );
26
- app.use( responseMiddleware );
27
- app.use( errorMiddleware );
28
- if ( env.error ) {
29
- logger.error( '.env not found' );
30
- process.exit( 1 );
31
- }
32
-
33
- app.use( '/api-docs', swagger.serve, swagger.setup( swaggerConfig ) );
34
- app.use( '/v3/audit', auditRouter );
35
- app.use( '/trax-audit', traxAuditRouter );
36
-
37
- app.listen( PORT, async () => {
38
- connectdb();
39
- logger.info( `server is running on port= ${PORT} ` );
40
- } );