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

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.43",
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';
@@ -398,7 +398,10 @@ export async function viewFile( req, res ) {
398
398
  try {
399
399
  const inputData = req.params;
400
400
  const openSearch = JSON.parse( process.env.OPENSEARCH );
401
- const url = JSON.parse( process.env.URL );
401
+ const bucket = JSON.parse( process.env.BUCKET );
402
+ // const url = JSON.parse( process.env.URL );
403
+ const updatedDate = process.env.EYE_TEST_UPDATED_DATE;
404
+ const remoteUpdatedDate = process.env.REMOTE_UPDATED_DATE;
402
405
  let isEnable =true;
403
406
  const order = [
404
407
  'Distance-VA-Check',
@@ -472,7 +475,18 @@ export async function viewFile( req, res ) {
472
475
  const temp = searchRes?.body?.hits?.hits?.length > 0? searchRes?.body?.hits?.hits[0] : [];
473
476
 
474
477
  const getUserName = await findOneUser( { _id: new mongoose.Types.ObjectId( temp?._source?.userId ) }, { userName: 1 } );
475
-
478
+ const inputBucketName = getData?.type === 'remote'? bucket?.remoteInput : bucket?.physicalInput;
479
+ const inputOldBucketName = getData?.type === 'remote'? bucket?.remoteOldInput : bucket?.physicalOldInput;
480
+ const configDate = getData?.type === 'remote'? new Date( remoteUpdatedDate ): new Date( updatedDate );
481
+ const fileDate = new Date( getData?.fileDate );
482
+ const params = {
483
+ file_path: getData?.filePath,
484
+ Bucket: fileDate > configDate ? inputBucketName: inputOldBucketName,
485
+ key: fileDate > configDate ?'akamai' : 'aws',
486
+ type: getData?.type,
487
+ };
488
+ const getSignedUrl = await signedUrl( params );
489
+ logger.info( { mesagee: 'signedurl', getSignedUrl: getSignedUrl, params: params } );
476
490
  const searchData = temp?
477
491
  getData['lastAuditedDetails']= {
478
492
  'auditedBy': getUserName?.userName || '',
@@ -482,7 +496,7 @@ export async function viewFile( req, res ) {
482
496
  getData['complianceScore'] = getData.complianceScore || getData?.totalSteps>0 ? Math.round( ( getData?.coveredStepsAI/ getData?.totalSteps )*100 ): 0;
483
497
  getData['trustScore'] = getData?.trustScore || 0;
484
498
  getData['testDuration'] = Math.round( getData?.testDuration/60 ) || 0;
485
- getData['filePath'] = `${url[getData?.type]}${getData?.filePath}`;
499
+ getData['filePath'] = getSignedUrl; // `${url[getData?.type]}${getData?.filePath}`;
486
500
  getData['auditType'] = getData.auditType || 'Audit';
487
501
  const response = getData;
488
502
 
@@ -589,9 +603,11 @@ export async function viewFile( req, res ) {
589
603
  export async function getFile( req, res ) {
590
604
  try {
591
605
  const inputData = req.params;
592
- const url = JSON.parse( process.env.URL );
606
+ // const url = JSON.parse( process.env.URL );
593
607
  const openSearch = JSON.parse( process.env.OPENSEARCH );
594
-
608
+ const bucket = JSON.parse( process.env.BUCKET );
609
+ const updatedDate = process.env.EYE_TEST_UPDATED_DATE;
610
+ const remoteUpdatedDate = process.env.REMOTE_UPDATED_DATE;
595
611
  const getInput = await getOpenSearchById( openSearch.EyeTestInput, inputData.id );
596
612
  if ( !getInput || !getInput?.body ) {
597
613
  return res.sendError( 'No Data Found', 204 );
@@ -643,7 +659,18 @@ export async function getFile( req, res ) {
643
659
  };
644
660
  const searchRes= await getOpenSearchData( openSearch.EyeTestOutput, searchQuery );
645
661
  const searchData = searchRes?.body?.hits?.hits?.lenght > 0? searchRes?.body?.hits?.hits[0] : null;
646
- logger.info( { searchData: searchData, getData: getData, messahe: '...........3' } );
662
+ const inputBucketName = getData?.type === 'remote'? bucket?.remoteInput : bucket?.physicalInput;
663
+ const inputOldBucketName = getData?.type === 'remote'? bucket?.remoteOldInput : bucket?.physicalOldInput;
664
+ const configDate = getData?.type === 'remote'? new Date( remoteUpdatedDate ): new Date( updatedDate );
665
+ const fileDate = new Date( getData?.fileDate );
666
+ const params = {
667
+ file_path: getData?.filePath,
668
+ Bucket: fileDate > configDate ? inputBucketName: inputOldBucketName,
669
+ key: fileDate > configDate ?'akamai' : 'aws',
670
+ type: getData?.type,
671
+ };
672
+ const getSignedUrl = await signedUrl( params );
673
+ logger.info( { mesagee: 'signedurl', getSignedUrl: getSignedUrl, params: params } );
647
674
  switch ( getData?.auditStatus ) {
648
675
  case 'Yet-to-Audit':
649
676
  const record= {
@@ -671,7 +698,7 @@ export async function getFile( req, res ) {
671
698
  'auditStatus': 'In-Progress',
672
699
  'totalSteps': getData?.totalSteps,
673
700
  'inputBucketName': getData?.inputBucketName,
674
- 'filePath': `${url[getData?.type]}${getData?.filePath}`,
701
+ 'filePath': getSignedUrl, // `${url[getData?.type]}${getData?.filePath}`,
675
702
  'steps': getData?.steps,
676
703
  'startTime': dayjs().tz( 'Asia/Kolkata' ),
677
704
  'createdAt': dayjs().tz( 'Asia/Kolkata' ),
@@ -724,7 +751,7 @@ export async function getFile( req, res ) {
724
751
  'spokenLanguage': getData?.spokenLanguage || '',
725
752
  'auditStatus': 'In-Progress',
726
753
  'totalSteps': getData?.totalSteps,
727
- 'filePath': `${url[getData?.type]}${getData?.filePath}`,
754
+ 'filePath': getSignedUrl, // `${url[getData?.type]}${getData?.filePath}`,
728
755
  'steps': getData?.steps,
729
756
  'auditType': 'Re-Audit',
730
757
  'startTime': dayjs().tz( 'Asia/Kolkata' ),
@@ -752,7 +779,10 @@ export async function save( req, res ) {
752
779
  const inputData = req.body;
753
780
  const openSearch = JSON.parse( process.env.OPENSEARCH );
754
781
  const ses = JSON.parse( process.env.SES );
755
- const url = JSON.parse( process.env.URL );
782
+ const bucket = JSON.parse( process.env.BUCKET );
783
+ // const url = JSON.parse( process.env.URL );
784
+ const updatedDate = process.env.EYE_TEST_UPDATED_DATE;
785
+ const remoteUpdatedDate = process.env.REMOTE_UPDATED_DATE;
756
786
 
757
787
  let searchFilter =[
758
788
  {
@@ -818,6 +848,7 @@ export async function save( req, res ) {
818
848
  if ( !output ) {
819
849
  return res.sendError( 'This file is currently being audited by another user. Any actions you perform will not be saved.', 400 );
820
850
  }
851
+
821
852
  const record ={
822
853
  'steps': inputData?.steps,
823
854
  'auditStatus': inputData?.auditStatus,
@@ -905,6 +936,18 @@ export async function save( req, res ) {
905
936
  steps.sort(
906
937
  ( a, b ) => order.indexOf( a.processName ) - order.indexOf( b.processName ),
907
938
  );
939
+ const inputBucketName = inputUpdatedData?._source?.type === 'remote'? bucket?.remoteInput : bucket?.physicalInput;
940
+ const inputOldBucketName = inputUpdatedData?._source?.type === 'remote'? bucket?.remoteOldInput : bucket?.physicalOldInput;
941
+ const configDate = inputUpdatedData?._source?.type === 'remote'? new Date( remoteUpdatedDate ): new Date( updatedDate );
942
+ const fileDate = new Date( inputUpdatedData?._source?.fileDate );
943
+ const params = {
944
+ file_path: inputUpdatedData?._source?.filePath,
945
+ Bucket: fileDate > configDate ? inputBucketName: inputOldBucketName,
946
+ key: fileDate > configDate ?'akamai' : 'aws',
947
+ type: inputUpdatedData?._source?.type,
948
+ };
949
+ const getSignedUrl = await signedUrl( params );
950
+ logger.info( { mesagee: 'signedurl', getSignedUrl: getSignedUrl, params: params } );
908
951
  switch ( condition ) {
909
952
  case '>': if ( humanScore > value ) {
910
953
  const record1 = {
@@ -943,7 +986,7 @@ export async function save( req, res ) {
943
986
  startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source?.testEndTime}`,
944
987
  compliancePercentage: humanScore,
945
988
  steps: steps,
946
- videoUrl: `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
989
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
947
990
  ref: reference1,
948
991
  } );
949
992
  }
@@ -983,7 +1026,7 @@ export async function save( req, res ) {
983
1026
  startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source.testEndTime}`,
984
1027
  compliancePercentage: humanScore,
985
1028
  steps: steps,
986
- videoUrl: `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1029
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
987
1030
  ref: reference2,
988
1031
  } );
989
1032
  };
@@ -1028,7 +1071,7 @@ export async function save( req, res ) {
1028
1071
  startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source.testEndTime}`,
1029
1072
  compliancePercentage: humanScore,
1030
1073
  steps: steps,
1031
- videoUrl: `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1074
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1032
1075
 
1033
1076
  ref: reference3,
1034
1077
  } );
@@ -1072,7 +1115,7 @@ export async function save( req, res ) {
1072
1115
  startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source.testEndTime}`,
1073
1116
  compliancePercentage: humanScore,
1074
1117
  steps: steps,
1075
- videoUrl: `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1118
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1076
1119
  ref: reference4,
1077
1120
  } );
1078
1121
  }
@@ -1113,7 +1156,7 @@ export async function save( req, res ) {
1113
1156
  startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source.testEndTime}`,
1114
1157
  compliancePercentage: humanScore,
1115
1158
  steps: steps,
1116
- videoUrl: `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1159
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1117
1160
  ref: reference5,
1118
1161
  } );
1119
1162
  }
@@ -1152,7 +1195,7 @@ export async function save( req, res ) {
1152
1195
  startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source.testEndTime}`,
1153
1196
  compliancePercentage: humanScore,
1154
1197
  steps: steps,
1155
- videoUrl: `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1198
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1156
1199
  ref: reference6,
1157
1200
  } );
1158
1201
  }
@@ -1544,7 +1587,9 @@ export async function summaryList( req, res ) {
1544
1587
  }
1545
1588
  }
1546
1589
 
1547
-
1590
+ mustQuery = [
1591
+ ...filter,
1592
+ ];
1548
1593
  if ( inputData.keyType === 'rm' || inputData.keyType === 'cluster' ) {
1549
1594
  let sort ={
1550
1595
  _id: -1,
@@ -1784,7 +1829,6 @@ export async function summaryList( req, res ) {
1784
1829
 
1785
1830
  };
1786
1831
  const getResponse = await getOpenSearchData( openSearch.EyeTestInput, getClusterQuery );
1787
- logger.info( { getResponse: getResponse } );
1788
1832
  if ( getResponse?.body?.aggregations && getResponse?.body?.aggregations?.total_count?.value > 0 ) {
1789
1833
  delete temp[i].store;
1790
1834
  delete temp[i]._id;
@@ -2604,7 +2648,6 @@ export async function summaryCard( req, res ) {
2604
2648
 
2605
2649
 
2606
2650
  const getOutput = await getOpenSearchData( openSearch?.EyeTestInput, getQuery );
2607
- logger.info( { getOutput: getOutput } );
2608
2651
  const initialValue = {
2609
2652
  totalFiles: 0,
2610
2653
  completedFiles: 0,