tango-app-api-audit 3.6.42-eyetest.2 → 3.6.44

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "3.6.42-eyetest.2",
3
+ "version": "3.6.44",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -29,7 +29,7 @@
29
29
  "nodemon": "^3.1.3",
30
30
  "swagger-ui-express": "^5.0.1",
31
31
  "tango-api-schema": "^2.5.27",
32
- "tango-app-api-middleware": "^3.6.8",
32
+ "tango-app-api-middleware": "^3.6.18",
33
33
  "winston": "^3.13.0",
34
34
  "winston-daily-rotate-file": "^5.0.0"
35
35
  },
@@ -1,4 +1,4 @@
1
- import { getOpenSearchData, getOpenSearchById, logger, insertOpenSearchData, updateOpenSearchData, download, chunkArray, getOpenSearchCount, insertWithId } from 'tango-app-api-middleware';
1
+ import { getOpenSearchData, getOpenSearchById, logger, insertOpenSearchData, updateOpenSearchData, download, chunkArray, getOpenSearchCount, insertWithId, signedUrl } from 'tango-app-api-middleware';
2
2
  import { aggregateUser, findOneUser, findUser } from '../service/user.service.js';
3
3
  import mongoose from 'mongoose';
4
4
  import dayjs from 'dayjs';
@@ -25,17 +25,32 @@ export async function getList( req, res ) {
25
25
 
26
26
  const sortBy = inputData?.sortBy ? [ 'coveredStepsAI', 'trustScore', 'date' ].includes( inputData.sortBy ) ? inputData.sortBy :`${inputData.sortBy}.keyword` : 'storeName.keyword';
27
27
  const order = inputData?.sortOrder || -1;
28
- let filter= [
29
- {
30
- 'range': {
31
- 'date': {
32
- 'gte': new Date( inputData.fromDate ),
33
- 'lte': new Date( inputData.toDate ),
28
+ let filter;
29
+ if ( dateType === 'auditedDate' ) {
30
+ filter= [
31
+ {
32
+ 'range': {
33
+ 'updatedAt': {
34
+ 'gte': new Date( inputData.fromDate ),
35
+ 'lte': new Date( inputData.toDate ),
36
+ },
34
37
  },
35
38
  },
36
- },
37
39
 
38
- ];
40
+ ];
41
+ } else {
42
+ filter= [
43
+ {
44
+ 'range': {
45
+ 'date': {
46
+ 'gte': new Date( inputData.fromDate ),
47
+ 'lte': new Date( inputData.toDate ),
48
+ },
49
+ },
50
+ },
51
+
52
+ ];
53
+ }
39
54
 
40
55
 
41
56
  if ( inputData.demographics && inputData.demographics.length > 0 ) {
@@ -298,49 +313,7 @@ export async function getList( req, res ) {
298
313
  }
299
314
  }
300
315
 
301
- // export async function fetchAllDocuments( index, data ) {
302
- // try {
303
- // const pageSize = 1000; // safer chunk size
304
- // let allHits = [];
305
- // let searchAfter = null;
306
- // let hasMore = true;
307
- // let i =0;
308
-
309
- // while ( hasMore ) {
310
- // const body={
311
- // size: pageSize,
312
- // query: {
313
- // bool: data,
314
- // },
315
- // sort: [
316
- // { 'storeName.keyword': 'desc' },
317
- // { '_id': 'asc' }, // Required for stable search_after
318
- // ],
319
- // };
320
-
321
- // if ( searchAfter ) {
322
- // body.search_after = searchAfter;
323
- // }
324
-
325
- // const response = await getOpenSearchData( index, body );
326
- // const hits = response.body.hits.hits;
327
- // i = i+hits.length;
328
- // logger.info( { index: i, length: hits.length, msg: '........index' } );
329
- // allHits.push( ...hits );
330
- // if ( allHits.length >= 50000 ) {
331
- // hasMore = false;
332
- // } else {
333
- // searchAfter = hits[hits.length - 1].sort;
334
- // }
335
- // }
336
-
337
- // logger.info( `Fetched ${allHits.length} documents` );
338
- // return allHits;
339
- // } catch ( error ) {
340
- // const err = error.message || 'Internal Server Error';
341
- // return res.sendError( err, 500 );
342
- // };
343
- // };
316
+
344
317
  export async function fetchDeepPage( index, data, limit, offset, sortBy, order, searchAfter1 ) {
345
318
  try {
346
319
  logger.info( { index: index, data: data, limit: limit, offset: offset } );
@@ -365,27 +338,6 @@ export async function fetchDeepPage( index, data, limit, offset, sortBy, order,
365
338
  );
366
339
 
367
340
  const hits = response?.body?.hits?.hits;
368
- // while ( currentCount < offset + limit ) {
369
- // const response = await getOpenSearchData(
370
- // index,
371
- // body,
372
- // );
373
-
374
- // const hits = response?.body?.hits?.hits;
375
- // logger.info( { response: response } );
376
- // if ( !hits.length || offset + limit <= i ) break;
377
- // i = i+hits.length;
378
- // logger.info( { hits: hits, function: '.........hits' } );
379
- // currentCount += hits.length;
380
- // searchAfter = hits[hits.length - 1].sort;
381
- // logger.info( { searchAfter: searchAfter } );
382
- // // Only keep the target range
383
- // const startIndex = Math.max( 0, hits.length - ( currentCount - offset ) );
384
- // const sliced = hits.slice( startIndex, startIndex + limit );
385
- // if ( currentCount >= offset ) {
386
- // finalResults.push( ...sliced );
387
- // }
388
- // }
389
341
  return hits;
390
342
  } catch ( error ) {
391
343
  const err = error.message || 'Internal Server Error';
@@ -398,7 +350,10 @@ export async function viewFile( req, res ) {
398
350
  try {
399
351
  const inputData = req.params;
400
352
  const openSearch = JSON.parse( process.env.OPENSEARCH );
401
- const url = JSON.parse( process.env.URL );
353
+ const bucket = JSON.parse( process.env.BUCKET );
354
+ // const url = JSON.parse( process.env.URL );
355
+ const updatedDate = process.env.EYE_TEST_UPDATED_DATE;
356
+ const remoteUpdatedDate = process.env.REMOTE_UPDATED_DATE;
402
357
  let isEnable =true;
403
358
  const order = [
404
359
  'Distance-VA-Check',
@@ -472,7 +427,18 @@ export async function viewFile( req, res ) {
472
427
  const temp = searchRes?.body?.hits?.hits?.length > 0? searchRes?.body?.hits?.hits[0] : [];
473
428
 
474
429
  const getUserName = await findOneUser( { _id: new mongoose.Types.ObjectId( temp?._source?.userId ) }, { userName: 1 } );
475
-
430
+ const inputBucketName = getData?.type === 'remote'? bucket?.remoteInput : bucket?.physicalInput;
431
+ const inputOldBucketName = getData?.type === 'remote'? bucket?.remoteOldInput : bucket?.physicalOldInput;
432
+ const configDate = getData?.type === 'remote'? new Date( remoteUpdatedDate ): new Date( updatedDate );
433
+ const fileDate = new Date( getData?.fileDate );
434
+ const params = {
435
+ file_path: getData?.filePath,
436
+ Bucket: fileDate > configDate ? inputBucketName: inputOldBucketName,
437
+ key: fileDate > configDate ?'akamai' : 'aws',
438
+ type: getData?.type,
439
+ };
440
+ const getSignedUrl = await signedUrl( params );
441
+ logger.info( { mesagee: 'signedurl', getSignedUrl: getSignedUrl, params: params } );
476
442
  const searchData = temp?
477
443
  getData['lastAuditedDetails']= {
478
444
  'auditedBy': getUserName?.userName || '',
@@ -482,7 +448,7 @@ export async function viewFile( req, res ) {
482
448
  getData['complianceScore'] = getData.complianceScore || getData?.totalSteps>0 ? Math.round( ( getData?.coveredStepsAI/ getData?.totalSteps )*100 ): 0;
483
449
  getData['trustScore'] = getData?.trustScore || 0;
484
450
  getData['testDuration'] = Math.round( getData?.testDuration/60 ) || 0;
485
- getData['filePath'] = `${url[getData?.type]}${getData?.filePath}`;
451
+ getData['filePath'] = getSignedUrl; // `${url[getData?.type]}${getData?.filePath}`;
486
452
  getData['auditType'] = getData.auditType || 'Audit';
487
453
  const response = getData;
488
454
 
@@ -589,9 +555,11 @@ export async function viewFile( req, res ) {
589
555
  export async function getFile( req, res ) {
590
556
  try {
591
557
  const inputData = req.params;
592
- const url = JSON.parse( process.env.URL );
558
+ // const url = JSON.parse( process.env.URL );
593
559
  const openSearch = JSON.parse( process.env.OPENSEARCH );
594
-
560
+ const bucket = JSON.parse( process.env.BUCKET );
561
+ const updatedDate = process.env.EYE_TEST_UPDATED_DATE;
562
+ const remoteUpdatedDate = process.env.REMOTE_UPDATED_DATE;
595
563
  const getInput = await getOpenSearchById( openSearch.EyeTestInput, inputData.id );
596
564
  if ( !getInput || !getInput?.body ) {
597
565
  return res.sendError( 'No Data Found', 204 );
@@ -643,7 +611,18 @@ export async function getFile( req, res ) {
643
611
  };
644
612
  const searchRes= await getOpenSearchData( openSearch.EyeTestOutput, searchQuery );
645
613
  const searchData = searchRes?.body?.hits?.hits?.lenght > 0? searchRes?.body?.hits?.hits[0] : null;
646
- logger.info( { searchData: searchData, getData: getData, messahe: '...........3' } );
614
+ const inputBucketName = getData?.type === 'remote'? bucket?.remoteInput : bucket?.physicalInput;
615
+ const inputOldBucketName = getData?.type === 'remote'? bucket?.remoteOldInput : bucket?.physicalOldInput;
616
+ const configDate = getData?.type === 'remote'? new Date( remoteUpdatedDate ): new Date( updatedDate );
617
+ const fileDate = new Date( getData?.fileDate );
618
+ const params = {
619
+ file_path: getData?.filePath,
620
+ Bucket: fileDate > configDate ? inputBucketName: inputOldBucketName,
621
+ key: fileDate > configDate ?'akamai' : 'aws',
622
+ type: getData?.type,
623
+ };
624
+ const getSignedUrl = await signedUrl( params );
625
+ logger.info( { mesagee: 'signedurl', getSignedUrl: getSignedUrl, params: params } );
647
626
  switch ( getData?.auditStatus ) {
648
627
  case 'Yet-to-Audit':
649
628
  const record= {
@@ -671,7 +650,7 @@ export async function getFile( req, res ) {
671
650
  'auditStatus': 'In-Progress',
672
651
  'totalSteps': getData?.totalSteps,
673
652
  'inputBucketName': getData?.inputBucketName,
674
- 'filePath': `${url[getData?.type]}${getData?.filePath}`,
653
+ 'filePath': getSignedUrl, // `${url[getData?.type]}${getData?.filePath}`,
675
654
  'steps': getData?.steps,
676
655
  'startTime': dayjs().tz( 'Asia/Kolkata' ),
677
656
  'createdAt': dayjs().tz( 'Asia/Kolkata' ),
@@ -724,7 +703,7 @@ export async function getFile( req, res ) {
724
703
  'spokenLanguage': getData?.spokenLanguage || '',
725
704
  'auditStatus': 'In-Progress',
726
705
  'totalSteps': getData?.totalSteps,
727
- 'filePath': `${url[getData?.type]}${getData?.filePath}`,
706
+ 'filePath': getSignedUrl, // `${url[getData?.type]}${getData?.filePath}`,
728
707
  'steps': getData?.steps,
729
708
  'auditType': 'Re-Audit',
730
709
  'startTime': dayjs().tz( 'Asia/Kolkata' ),
@@ -752,7 +731,10 @@ export async function save( req, res ) {
752
731
  const inputData = req.body;
753
732
  const openSearch = JSON.parse( process.env.OPENSEARCH );
754
733
  const ses = JSON.parse( process.env.SES );
755
- const url = JSON.parse( process.env.URL );
734
+ const bucket = JSON.parse( process.env.BUCKET );
735
+ // const url = JSON.parse( process.env.URL );
736
+ const updatedDate = process.env.EYE_TEST_UPDATED_DATE;
737
+ const remoteUpdatedDate = process.env.REMOTE_UPDATED_DATE;
756
738
 
757
739
  let searchFilter =[
758
740
  {
@@ -818,6 +800,7 @@ export async function save( req, res ) {
818
800
  if ( !output ) {
819
801
  return res.sendError( 'This file is currently being audited by another user. Any actions you perform will not be saved.', 400 );
820
802
  }
803
+
821
804
  const record ={
822
805
  'steps': inputData?.steps,
823
806
  'auditStatus': inputData?.auditStatus,
@@ -905,6 +888,18 @@ export async function save( req, res ) {
905
888
  steps.sort(
906
889
  ( a, b ) => order.indexOf( a.processName ) - order.indexOf( b.processName ),
907
890
  );
891
+ const inputBucketName = inputUpdatedData?._source?.type === 'remote'? bucket?.remoteInput : bucket?.physicalInput;
892
+ const inputOldBucketName = inputUpdatedData?._source?.type === 'remote'? bucket?.remoteOldInput : bucket?.physicalOldInput;
893
+ const configDate = inputUpdatedData?._source?.type === 'remote'? new Date( remoteUpdatedDate ): new Date( updatedDate );
894
+ const fileDate = new Date( inputUpdatedData?._source?.fileDate );
895
+ const params = {
896
+ file_path: inputUpdatedData?._source?.filePath,
897
+ Bucket: fileDate > configDate ? inputBucketName: inputOldBucketName,
898
+ key: fileDate > configDate ?'akamai' : 'aws',
899
+ type: inputUpdatedData?._source?.type,
900
+ };
901
+ const getSignedUrl = await signedUrl( params );
902
+ logger.info( { mesagee: 'signedurl', getSignedUrl: getSignedUrl, params: params } );
908
903
  switch ( condition ) {
909
904
  case '>': if ( humanScore > value ) {
910
905
  const record1 = {
@@ -943,7 +938,7 @@ export async function save( req, res ) {
943
938
  startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source?.testEndTime}`,
944
939
  compliancePercentage: humanScore,
945
940
  steps: steps,
946
- videoUrl: `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
941
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
947
942
  ref: reference1,
948
943
  } );
949
944
  }
@@ -983,7 +978,7 @@ export async function save( req, res ) {
983
978
  startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source.testEndTime}`,
984
979
  compliancePercentage: humanScore,
985
980
  steps: steps,
986
- videoUrl: `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
981
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
987
982
  ref: reference2,
988
983
  } );
989
984
  };
@@ -1028,7 +1023,7 @@ export async function save( req, res ) {
1028
1023
  startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source.testEndTime}`,
1029
1024
  compliancePercentage: humanScore,
1030
1025
  steps: steps,
1031
- videoUrl: `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1026
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1032
1027
 
1033
1028
  ref: reference3,
1034
1029
  } );
@@ -1072,7 +1067,7 @@ export async function save( req, res ) {
1072
1067
  startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source.testEndTime}`,
1073
1068
  compliancePercentage: humanScore,
1074
1069
  steps: steps,
1075
- videoUrl: `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1070
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1076
1071
  ref: reference4,
1077
1072
  } );
1078
1073
  }
@@ -1113,7 +1108,7 @@ export async function save( req, res ) {
1113
1108
  startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source.testEndTime}`,
1114
1109
  compliancePercentage: humanScore,
1115
1110
  steps: steps,
1116
- videoUrl: `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1111
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1117
1112
  ref: reference5,
1118
1113
  } );
1119
1114
  }
@@ -1152,7 +1147,7 @@ export async function save( req, res ) {
1152
1147
  startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source.testEndTime}`,
1153
1148
  compliancePercentage: humanScore,
1154
1149
  steps: steps,
1155
- videoUrl: `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1150
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1156
1151
  ref: reference6,
1157
1152
  } );
1158
1153
  }
@@ -1417,21 +1412,36 @@ export async function summaryList( req, res ) {
1417
1412
  const limit = inputData.limit || 10;
1418
1413
  const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
1419
1414
 
1420
- const sortBy = inputData?.sortBy ? [ 'coveredStepsAI', 'trustScore', 'date', 'ComplianceScore', 'auditedSteps' ].includes( inputData.sortBy ) ? inputData.sortBy :`${inputData.sortBy}.keyword` : 'storeName.keyword';
1415
+ const sortBy = inputData?.sortBy ? inputData?.sortBy === 'auditedDate'? 'updatedAt': [ 'coveredStepsAI', 'trustScore', 'date', 'ComplianceScore', 'auditedSteps' ].includes( inputData.sortBy ) ? inputData.sortBy :`${inputData.sortBy}.keyword` : 'storeName.keyword';
1421
1416
  const order = inputData?.sortOrder || -1;
1422
1417
 
1423
1418
  // declare filter and assign range values from inputData
1424
- let filter= [
1425
- {
1426
- 'range': {
1427
- 'date': {
1428
- 'gte': new Date( inputData.fromDate ),
1429
- 'lte': new Date( inputData.toDate ),
1419
+ let filter;
1420
+ if ( inputData?.dateType === 'auditedDate' ) {
1421
+ filter= [
1422
+ {
1423
+ 'range': {
1424
+ 'updatedAt': {
1425
+ 'gte': new Date( inputData.fromDate ),
1426
+ 'lte': new Date( inputData.toDate ),
1427
+ },
1430
1428
  },
1431
1429
  },
1432
- },
1433
1430
 
1434
- ];
1431
+ ];
1432
+ } else {
1433
+ filter= [
1434
+ {
1435
+ 'range': {
1436
+ 'date': {
1437
+ 'gte': new Date( inputData.fromDate ),
1438
+ 'lte': new Date( inputData.toDate ),
1439
+ },
1440
+ },
1441
+ },
1442
+
1443
+ ];
1444
+ }
1435
1445
 
1436
1446
  // filter by Audit Status if key has minimum one element
1437
1447
  if ( inputData?.auditStatus && inputData?.auditStatus?.length > 0 ) {
@@ -1544,7 +1554,9 @@ export async function summaryList( req, res ) {
1544
1554
  }
1545
1555
  }
1546
1556
 
1547
-
1557
+ mustQuery = [
1558
+ ...filter,
1559
+ ];
1548
1560
  if ( inputData.keyType === 'rm' || inputData.keyType === 'cluster' ) {
1549
1561
  let sort ={
1550
1562
  _id: -1,
@@ -1784,7 +1796,6 @@ export async function summaryList( req, res ) {
1784
1796
 
1785
1797
  };
1786
1798
  const getResponse = await getOpenSearchData( openSearch.EyeTestInput, getClusterQuery );
1787
- logger.info( { getResponse: getResponse } );
1788
1799
  if ( getResponse?.body?.aggregations && getResponse?.body?.aggregations?.total_count?.value > 0 ) {
1789
1800
  delete temp[i].store;
1790
1801
  delete temp[i]._id;
@@ -2604,7 +2615,6 @@ export async function summaryCard( req, res ) {
2604
2615
 
2605
2616
 
2606
2617
  const getOutput = await getOpenSearchData( openSearch?.EyeTestInput, getQuery );
2607
- logger.info( { getOutput: getOutput } );
2608
2618
  const initialValue = {
2609
2619
  totalFiles: 0,
2610
2620
  completedFiles: 0,
@@ -3,6 +3,7 @@ import dayjs from 'dayjs';
3
3
 
4
4
  export const getListSchema = joi.object(
5
5
  {
6
+ dateType: joi.string().optional().valid( 'fileDate', 'auditedDate' ),
6
7
  fromDate: joi.string().required().messages( {
7
8
  'any.required': 'From Date is required',
8
9
  'string.empty': 'From Date cannot be empty',
@@ -101,6 +102,7 @@ export const userAuditedDataValid = {
101
102
  };
102
103
 
103
104
  export const summaryListSchema = joi.object( {
105
+ dateType: joi.string().optional().valid( 'fileDate', 'auditedDate' ),
104
106
  keyType: joi.string()
105
107
  .valid( 'rm', 'cluster', 'store' )
106
108
  .required()