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

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "3.4.68-beta.1",
3
+ "version": "3.4.68-beta.2",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,4 +1,4 @@
1
- import { getOpenSearchData, getOpenSearchById, logger, insertOpenSearchData, updateOpenSearchData } from 'tango-app-api-middleware';
1
+ import { getOpenSearchData, getOpenSearchById, logger, insertOpenSearchData, updateOpenSearchData, download, chunkArray } from 'tango-app-api-middleware';
2
2
  import { findOneUser } from '../service/user.service.js';
3
3
  import mongoose from 'mongoose';
4
4
  import dayjs from 'dayjs';
@@ -28,21 +28,24 @@ export async function getList( req, res ) {
28
28
  },
29
29
 
30
30
  ];
31
- let search ={
32
- 'must': filter,
33
- };
34
31
 
35
- if ( inputData.visitorsType && inputData.visitorsType.lenght > 0 ) {
36
- filter.push( {
37
32
 
38
- 'terms': {
39
- 'visitorsType.keyword': inputData.visitorsType,
33
+ // if ( inputData.demographics && inputData.demographics.length > 0 ) {
34
+ // filter.push( {
35
+ // 'terms': {
36
+ // 'visitorsType.keyword': inputData.demographics,
37
+ // },
38
+ // } );
39
+ // }
40
+ if ( inputData.type && inputData.type!='' ) {
41
+ filter.push( {
42
+ 'term': {
43
+ 'type.keyword': inputData.type,
40
44
  },
41
45
 
42
46
  } );
43
47
  }
44
-
45
- if ( inputData.storeId && inputData.storeId.lenght > 0 ) {
48
+ if ( inputData.storeId && inputData.storeId.length > 0 ) {
46
49
  filter.push( {
47
50
 
48
51
  'terms': {
@@ -51,6 +54,9 @@ export async function getList( req, res ) {
51
54
 
52
55
  } );
53
56
  }
57
+ let search ={
58
+ 'must': filter,
59
+ };
54
60
 
55
61
  if ( inputData.searchValue && inputData.searchValue !== '' ) {
56
62
  search ={
@@ -109,14 +115,43 @@ export async function getList( req, res ) {
109
115
  'minimum_should_match': 1,
110
116
  };
111
117
  }
112
-
113
118
  let searchQuery={
114
119
  'from': offset,
115
120
  'size': limit,
116
121
  'query': {
117
122
  'bool': search,
118
123
  },
124
+ 'sort': [
125
+ { date: { order: 'desc' } },
126
+ ],
119
127
  };
128
+ if ( inputData.sortBy && inputData.sortBy !== '' ) {
129
+ const sortBy = inputData.sortBy;
130
+ const order = inputData.sortOrder || -1;
131
+ searchQuery={
132
+ 'from': offset,
133
+ 'size': limit,
134
+ 'query': {
135
+ 'bool': search,
136
+ },
137
+ 'sort': [
138
+ { [sortBy]: { order: order === -1 ?'desc':'asc' } },
139
+ ],
140
+ };
141
+ }
142
+
143
+ if ( inputData.isExport==true ) {
144
+ searchQuery={
145
+ 'from': 0,
146
+ 'size': 10000,
147
+ 'query': {
148
+ 'bool': search,
149
+ },
150
+ 'sort': [
151
+ { createdAt: { order: 'desc' } },
152
+ ],
153
+ };
154
+ }
120
155
  const result = await getOpenSearchData( openSearch.EyeTestInput, searchQuery );
121
156
  const count = result?.body?.hits?.total?.value;
122
157
  if ( !count || count == 0 ) {
@@ -126,6 +161,70 @@ export async function getList( req, res ) {
126
161
  if ( !searchValue || searchValue?.length == 0 ) {
127
162
  return res.sendError( 'No data found', 204 );
128
163
  }
164
+ if ( inputData.isExport == true ) {
165
+ const chunkedMappingData = await chunkArray( searchValue, 10 );
166
+ const promises = chunkedMappingData.map( async ( chunk ) => {
167
+ const exportData = [];
168
+ chunk.forEach( async ( element ) => {
169
+ const testDuration = element?._source?.testDuration;
170
+ const minutes = Math.floor( testDuration / 60 );
171
+ const seconds = testDuration % 60;
172
+ const minutes1 =minutes> 1? `${minutes} mins` : `${minutes} min`;
173
+ const seconds1 = seconds > 1? `${minutes} secs`: seconds == 1? `${minutes} sec` : '';
174
+ const duration =`${minutes1} ${seconds1}`;
175
+ const userName = await findOneUser( { _id: element?._source?.userId }, { _id: 0, userName: 1 } );
176
+ if ( element?._source?.type == 'physical' ) {
177
+ exportData.push( {
178
+ 'Date': dayjs( element?._source?.date ).format( 'YYYY,MMM D' ),
179
+ 'Store Name': element?._source?.storeName,
180
+ 'Store ID': element?._source?.storeId || 'Un Assigned',
181
+ 'Store Name': element?._source?.storeName ||'Un Assigned',
182
+ 'Optum ID': element?._source?.optumId,
183
+ 'Queue ID': element?._source?.queueId,
184
+ 'Compliance Score': element?._source?.complianceScore || 0,
185
+ 'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
186
+ 'Visitor Type': element?._source?.visitorsType,
187
+ 'Test Duration': duration || '',
188
+ 'Audit Status': element?._source?.auditStatus || '',
189
+ 'Audited By': userName?.userName || '',
190
+
191
+ } );
192
+ } else {
193
+ exportData.push( {
194
+ 'Date': dayjs( element?._source?.date ).format( 'YYYY,MMM D' ),
195
+ 'Store Name': element?._source?.storeName,
196
+ 'Store ID': element?._source?.storeId || 'Un Assigned',
197
+ 'Store Name': element?._source?.storeName ||'Un Assigned',
198
+ 'Engagement ID': element?._source?.engagementId,
199
+ 'Compliance Score': element?._source?.complianceScore || 0,
200
+ 'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
201
+ 'Visitor Type': element?._source?.visitorsType,
202
+ 'Test Duration': duration || '',
203
+ 'Audit Status': element?._source?.auditStatus || '',
204
+ 'Audited By': userName.userName || '',
205
+
206
+ } );
207
+ }
208
+ } );
209
+ return exportData;
210
+ } );
211
+ const mappedArrays = await Promise.all( promises );
212
+ const result = mappedArrays.flat();
213
+ await download( result, res );
214
+ return;
215
+ } else {
216
+ for ( const [ i, item ] of searchValue.entries() ) {
217
+ const userName = await findOneUser( { _id: item?._source?.userId }, { _id: 0, userName: 1 } );
218
+ const testDuration = searchValue[i]?._source?.testDuration;
219
+ const minutes = Math.floor( testDuration / 60 );
220
+ const seconds = testDuration % 60;
221
+
222
+ searchValue[i]._source.min = minutes;
223
+ searchValue[i]._source.sec = seconds;
224
+ searchValue[i]._source.auditedBy = userName?.userName || '';
225
+ }
226
+ }
227
+
129
228
  return res.sendSuccess( { result: searchValue, count: count } );
130
229
  } catch ( error ) {
131
230
  const err = error.message || 'Internal Server Error';
@@ -150,13 +249,13 @@ export async function viewFile( req, res ) {
150
249
 
151
250
  let searchFilter =[
152
251
  {
153
- 'terms': {
252
+ 'term': {
154
253
  'queueId.keyword': getData?.queueId,
155
254
  },
156
255
 
157
256
  },
158
257
  {
159
- 'terms': {
258
+ 'term': {
160
259
  'type.keyword': getData?.type,
161
260
  },
162
261
 
@@ -165,13 +264,13 @@ export async function viewFile( req, res ) {
165
264
  if ( getData?.type == 'remote' ) {
166
265
  searchFilter =[
167
266
  {
168
- 'terms': {
267
+ 'term': {
169
268
  'engagementId.keyword': getData?.engagementId,
170
269
  },
171
270
 
172
271
  },
173
272
  {
174
- 'terms': {
273
+ 'term': {
175
274
  'type.keyword': getData?.type,
176
275
  },
177
276
 
@@ -190,21 +289,25 @@ export async function viewFile( req, res ) {
190
289
  { createdAt: { order: 'desc' } },
191
290
  ],
192
291
  };
292
+
193
293
  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 } );
294
+ const temp = searchRes?.body?.hits?.hits?.length > 0? searchRes?.body?.hits?.hits[0] : [];
295
+
296
+ const getUserName = await findOneUser( { _id: new mongoose.Types.ObjectId( temp?._source?.userId ) }, { userName: 1 } );
196
297
 
197
298
  const searchData = temp?
198
299
  getData['lastAuditedDetails']= {
199
300
  'auditedBy': getUserName?.userName || '',
200
- 'completionTime': temp?.startTime? new Date( temp?.startTime ).toLocaleTimeString( 'en-IN', { hour12: false } ): '',
301
+ 'completionTime': temp?._source?.startTime? new Date( temp?._source?.startTime ).toLocaleTimeString( 'en-IN', { hour12: false } ): '',
201
302
  'timeZone': temp?.timeZone || '',
202
303
  } : null;
203
304
  getData['complianceScore'] = getData.complianceScore || getData?.totalSteps>0 ? Math.round( ( getData?.coveredStepsAI/ getData?.totalSteps )*100 ): 0;
204
305
  getData['trustScore'] = getData?.trustScore || 0;
205
306
  getData['testDuration'] = Math.round( getData?.testDuration/60 ) || 0;
206
307
  getData['filePath'] = `${url[getData?.type]}${getData?.filePath}`;
308
+ getData['auditType'] = getData.auditType || 'Audit';
207
309
  const response = getData;
310
+
208
311
  switch ( getData?.auditStatus ) {
209
312
  case 'Yet-to-Audit':
210
313
  isEnable=true;
@@ -216,9 +319,9 @@ export async function viewFile( req, res ) {
216
319
  if ( searchData.userId !== req.user._id ) {
217
320
  isEnable=false;
218
321
  }
219
- return res.sendSuccess( { result: result } );
220
322
  break;
221
323
  case 'Audited':
324
+ response['steps']= temp._source?.steps;
222
325
  case 'Re-Audited':
223
326
  isEnable=true;
224
327
  }
@@ -226,7 +329,7 @@ export async function viewFile( req, res ) {
226
329
  return res.sendSuccess( { result: response, isEnable: isEnable } );
227
330
  } catch ( error ) {
228
331
  const err = error.message || 'Internal Server Error';
229
- logger.error( { message: error, data: req.body, function: 'eyetestAudit-controller-viewFile' } );
332
+ logger.error( { message: error, data: req.params, function: 'eyetestAudit-controller-viewFile' } );
230
333
  return res.sendError( err, 500 );
231
334
  }
232
335
  }
@@ -321,6 +424,7 @@ export async function getFile( req, res ) {
321
424
  'startTime': dayjs().tz( 'Asia/Kolkata' ),
322
425
  'createdAt': dayjs().tz( 'Asia/Kolkata' ),
323
426
  'updatedAt': dayjs().tz( 'Asia/Kolkata' ),
427
+ 'auditType': 'Audit',
324
428
 
325
429
  };
326
430
  record?.steps?.map( ( item, i ) => {
@@ -329,7 +433,7 @@ export async function getFile( req, res ) {
329
433
  if ( !searchData ) {
330
434
  const data1 = await insertOpenSearchData( openSearch.EyeTestOutput, record );
331
435
  logger.info( { data1: data1 } );
332
- await updateOpenSearchData( openSearch.EyeTestInput, inputData.id, { doc: { auditStatus: 'In-Progress', userId: req?.user?._id } } );
436
+ await updateOpenSearchData( openSearch.EyeTestInput, inputData.id, { doc: { auditStatus: 'In-Progress', auditType: 'Audit', userId: req?.user?._id } } );
333
437
  }
334
438
 
335
439
  break;
@@ -370,13 +474,14 @@ export async function getFile( req, res ) {
370
474
  'totalSteps': getData?.totalSteps,
371
475
  'filePath': `${url[getData?.type]}${getData?.filePath}`,
372
476
  'steps': getData?.steps,
477
+ 'auditType': 'Re-Audit',
373
478
  'startTime': dayjs().tz( 'Asia/Kolkata' ),
374
479
  'createdAt': dayjs().tz( 'Asia/Kolkata' ),
375
480
  'updatedAt': dayjs().tz( 'Asia/Kolkata' ),
376
481
 
377
482
  };
378
483
  await insertOpenSearchData( openSearch.EyeTestOutput, newRecord );
379
- await updateOpenSearchData( openSearch.EyeTestInput, inputData.id, { doc: { auditStatus: 'In-Progress' } } );
484
+ await updateOpenSearchData( openSearch.EyeTestInput, inputData.id, { doc: { auditStatus: 'In-Progress', auditType: 'Re-Audit' } } );
380
485
 
381
486
  break;
382
487
  default:
@@ -390,6 +495,101 @@ export async function getFile( req, res ) {
390
495
  return res.sendError( err, 500 );
391
496
  }
392
497
  }
498
+ export async function save( req, res ) {
499
+ try {
500
+ const inputData = req.body;
501
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
502
+
503
+ let searchFilter =[
504
+ {
505
+ 'term': {
506
+ 'queueId.keyword': inputData?.fileId,
507
+ },
508
+
509
+ },
510
+ {
511
+ 'term': {
512
+ 'type.keyword': inputData?.type,
513
+ },
514
+
515
+ },
516
+
517
+ {
518
+ 'term': {
519
+ 'auditStatus.keyword': 'In-Progress',
520
+ },
521
+ },
522
+ ];
523
+ if ( inputData?.type == 'remote' ) {
524
+ searchFilter =[
525
+ {
526
+ 'term': {
527
+ 'engagementId.keyword': inputData?.fileId,
528
+ },
529
+
530
+ },
531
+ {
532
+ 'term': {
533
+ 'type.keyword': inputData?.type,
534
+ },
535
+
536
+ },
537
+ {
538
+ 'term': {
539
+ 'userId.keyword': req?.user?._id,
540
+ },
541
+ },
542
+ {
543
+ 'term': {
544
+ 'auditStatus.keyword': 'In-Progress',
545
+ },
546
+ },
547
+ ];
548
+ }
549
+
550
+ let searchQuery={
551
+ 'size': 1,
552
+ 'query': {
553
+ 'bool': {
554
+ 'must': searchFilter,
555
+ },
556
+ },
557
+ };
558
+ const getOutput = await getOpenSearchData( openSearch.EyeTestOutput, searchQuery );
559
+ logger.info( { getOutput: getOutput } );
560
+ const output = getOutput?.body?.hits?.hits?.length > 0 ? getOutput?.body?.hits?.hits[0] : null;
561
+ if ( !output ) {
562
+ return res.sendError( 'No saved records found', 400 );
563
+ }
564
+ const record ={
565
+ steps: inputData?.steps,
566
+ auditStatus: inputData?.auditStatus,
567
+ auditedSteps: inputData?.auditedSteps,
568
+ overRides: inputData?.overRides,
569
+ trustScore: Math.round( 100-( ( inputData?.overRides / inputData?.steps?.length ) * 100 ) ),
570
+ spokenLanguage: inputData?.spokenLanguage,
571
+ endTime: dayjs().tz( 'Asia/Kolkata' ),
572
+
573
+ };
574
+ const inputrecord ={
575
+
576
+ auditStatus: inputData?.auditStatus,
577
+ auditedSteps: inputData?.auditedSteps,
578
+ overRides: inputData?.overRides,
579
+ trustScore: Math.round( 100-( ( inputData?.overRides / inputData?.steps?.length ) * 100 ) ),
580
+ spokenLanguage: inputData?.spokenLanguage,
581
+ endTime: dayjs().tz( 'Asia/Kolkata' ),
582
+
583
+ };
584
+ await updateOpenSearchData( openSearch.EyeTestOutput, output?._id, { doc: record } );
585
+ await updateOpenSearchData( openSearch.EyeTestInput, inputData.id, { doc: inputrecord } );
586
+ return res.sendSuccess( 'The file has been submited successfully' );
587
+ } catch ( error ) {
588
+ const err = error.message || 'Internal Server Error';
589
+ logger.error( { message: error, data: req.params, function: 'eyetestAudit-controller-save' } );
590
+ return res.sendError( err, 500 );
591
+ }
592
+ }
393
593
 
394
594
  export async function getFileHistory( req, res ) {
395
595
  try {
@@ -460,7 +660,9 @@ export async function userAuditedData( req, res ) {
460
660
  try {
461
661
  const parsedOpenSearch = JSON.parse( process.env.OPENSEARCH );
462
662
  const inputData = req.params;
663
+
463
664
  const resposnse = await getOpenSearchById( parsedOpenSearch.EyeTestOutput, inputData.id );
665
+
464
666
  if ( resposnse.body&&resposnse.body._source ) {
465
667
  return res.sendSuccess( { result: resposnse.body._source.steps } );
466
668
  } else {
@@ -1,5 +1,5 @@
1
1
  import j2s from 'joi-to-swagger';
2
- import { getListSchema, getFileSchema, getFileHistorySchema, userAuditedDataSchema, viewFileSchema } from '../dtos/eyeTestAudit.dtos.js';
2
+ import { getListSchema, getFileSchema, getFileHistorySchema, userAuditedDataSchema, viewFileSchema, saveSchema } from '../dtos/eyeTestAudit.dtos.js';
3
3
 
4
4
  export const eyeTestAuditDocs = {
5
5
 
@@ -71,6 +71,28 @@ export const eyeTestAuditDocs = {
71
71
  },
72
72
  },
73
73
 
74
+ '/v3/eye-test-audit/save': {
75
+ post: {
76
+ tags: [ 'Eye Test Audit' ],
77
+ description: 'submit eytest audit',
78
+ operationId: 'save',
79
+ requestBody: {
80
+ content: {
81
+ 'application/json': {
82
+ schema: j2s( saveSchema ).swagger,
83
+ },
84
+ },
85
+ },
86
+ responses: {
87
+ 200: { description: 'Successful' },
88
+ 401: { description: 'Unauthorized User' },
89
+ 422: { description: 'Field Error' },
90
+ 500: { description: 'Server Error' },
91
+ 204: { description: 'Not Found' },
92
+ },
93
+ },
94
+ },
95
+
74
96
  '/v3/eye-test-audit/get-file-history/{id}': {
75
97
  get: {
76
98
  tags: [ 'Eye Test Audit' ],
@@ -11,6 +11,8 @@ export const getListSchema = joi.object(
11
11
  offset: joi.number().optional(),
12
12
  searchValue: joi.string().optional().allow( '' ),
13
13
  isExport: joi.boolean().optional(),
14
+ sortBy: joi.string().optional(),
15
+ sortOrder: joi.number().optional(),
14
16
  },
15
17
  );
16
18
 
@@ -35,6 +37,22 @@ export const getFileValid = {
35
37
  params: getFileSchema,
36
38
  };
37
39
 
40
+ export const saveSchema = joi.object( {
41
+ type: joi.string().required(),
42
+ fileId: joi.string().required(),
43
+ id: joi.string().required(),
44
+ steps: joi.array().required(),
45
+ auditedSteps: joi.number().required(),
46
+ auditStatus: joi.string().required(),
47
+ overRides: joi.number().required(),
48
+ spokenLanguage: joi.string().optional(),
49
+ } );
50
+
51
+ export const saveValid = {
52
+ body: saveSchema,
53
+ };
54
+
55
+
38
56
  export const getFileHistorySchema = joi.object( {
39
57
  id: joi.string().required(),
40
58
  type: joi.string().required(),
@@ -1,15 +1,15 @@
1
1
  import { Router } from 'express';
2
2
  import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
3
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';
4
+ import { getFileHistoryValid, getFileValid, getListValid, saveValid, userAuditedDataValid, viewFileValid } from '../dtos/eyeTestAudit.dtos.js';
5
+ import { getFile, getFileHistory, getList, save, userAuditedData, viewFile } from '../controllers/eyeTestAudit.controllers.js';
6
6
 
7
7
  export const eyeTestAuditRouter = Router();
8
8
 
9
9
  eyeTestAuditRouter.post( '/get-list', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( getListValid ), getList );
10
10
  eyeTestAuditRouter.get( '/view-file/:id', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( viewFileValid ), viewFile );
11
11
  eyeTestAuditRouter.get( '/get-file/:id', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( getFileValid ), getFile );
12
- eyeTestAuditRouter.post( '/save', isAllowedSessionHandler );
12
+ eyeTestAuditRouter.post( '/save', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( saveValid ), save );
13
13
  eyeTestAuditRouter.get( '/get-file-history/:id/:type', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( getFileHistoryValid ), getFileHistory );
14
14
  eyeTestAuditRouter.get( '/user-audited-data/:id', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( userAuditedDataValid ), userAuditedData );
15
15