tango-app-api-audit 3.6.41 → 3.6.42-eyetest-dynamicization.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "3.6.41",
3
+ "version": "3.6.42-eyetest-dynamicization.1",
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.15",
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,9 @@ 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;
402
404
  let isEnable =true;
403
405
  const order = [
404
406
  'Distance-VA-Check',
@@ -472,7 +474,18 @@ export async function viewFile( req, res ) {
472
474
  const temp = searchRes?.body?.hits?.hits?.length > 0? searchRes?.body?.hits?.hits[0] : [];
473
475
 
474
476
  const getUserName = await findOneUser( { _id: new mongoose.Types.ObjectId( temp?._source?.userId ) }, { userName: 1 } );
475
-
477
+ const inputBucketName = getData?.type === 'remote'? bucket?.remoteInput : bucket?.physicalInput;
478
+ const inputOldBucketName = getData?.type === 'remote'? bucket?.remoteOldInput : bucket?.physicalOldInput;
479
+ const configDate = new Date( updatedDate );
480
+ const fileDate = new Date( getData?.fileDate );
481
+ const params = {
482
+ file_path: getData?.filePath,
483
+ Bucket: fileDate > configDate ? inputBucketName: inputOldBucketName,
484
+ key: fileDate > configDate ?'akamai' : 'aws',
485
+ type: getData?.type
486
+ };
487
+ const getSignedUrl = await signedUrl( params );
488
+ logger.info( { mesagee: 'signedurl', getSignedUrl: getSignedUrl, params: params } );
476
489
  const searchData = temp?
477
490
  getData['lastAuditedDetails']= {
478
491
  'auditedBy': getUserName?.userName || '',
@@ -482,7 +495,7 @@ export async function viewFile( req, res ) {
482
495
  getData['complianceScore'] = getData.complianceScore || getData?.totalSteps>0 ? Math.round( ( getData?.coveredStepsAI/ getData?.totalSteps )*100 ): 0;
483
496
  getData['trustScore'] = getData?.trustScore || 0;
484
497
  getData['testDuration'] = Math.round( getData?.testDuration/60 ) || 0;
485
- getData['filePath'] = `${url[getData?.type]}${getData?.filePath}`;
498
+ getData['filePath'] = getSignedUrl; // `${url[getData?.type]}${getData?.filePath}`;
486
499
  getData['auditType'] = getData.auditType || 'Audit';
487
500
  const response = getData;
488
501
 
@@ -589,9 +602,10 @@ export async function viewFile( req, res ) {
589
602
  export async function getFile( req, res ) {
590
603
  try {
591
604
  const inputData = req.params;
592
- const url = JSON.parse( process.env.URL );
605
+ // const url = JSON.parse( process.env.URL );
593
606
  const openSearch = JSON.parse( process.env.OPENSEARCH );
594
-
607
+ const bucket = JSON.parse( process.env.BUCKET );
608
+ const updatedDate = process.env.EYE_TEST_UPDATED_DATE;
595
609
  const getInput = await getOpenSearchById( openSearch.EyeTestInput, inputData.id );
596
610
  if ( !getInput || !getInput?.body ) {
597
611
  return res.sendError( 'No Data Found', 204 );
@@ -643,7 +657,18 @@ export async function getFile( req, res ) {
643
657
  };
644
658
  const searchRes= await getOpenSearchData( openSearch.EyeTestOutput, searchQuery );
645
659
  const searchData = searchRes?.body?.hits?.hits?.lenght > 0? searchRes?.body?.hits?.hits[0] : null;
646
- logger.info( { searchData: searchData, getData: getData, messahe: '...........3' } );
660
+ const inputBucketName = getData?.type === 'remote'? bucket?.remoteInput : bucket?.physicalInput;
661
+ const inputOldBucketName = getData?.type === 'remote'? bucket?.remoteOldInput : bucket?.physicalOldInput;
662
+ const configDate = new Date( updatedDate );
663
+ const fileDate = new Date( getData?.fileDate );
664
+ const params = {
665
+ file_path: getData?.filePath,
666
+ Bucket: fileDate > configDate ? inputBucketName: inputOldBucketName,
667
+ key: fileDate > configDate ?'akamai' : 'aws',
668
+ type: getData?.type
669
+ };
670
+ const getSignedUrl = await signedUrl( params );
671
+ logger.info( { mesagee: 'signedurl', getSignedUrl: getSignedUrl, params: params } );
647
672
  switch ( getData?.auditStatus ) {
648
673
  case 'Yet-to-Audit':
649
674
  const record= {
@@ -671,7 +696,7 @@ export async function getFile( req, res ) {
671
696
  'auditStatus': 'In-Progress',
672
697
  'totalSteps': getData?.totalSteps,
673
698
  'inputBucketName': getData?.inputBucketName,
674
- 'filePath': `${url[getData?.type]}${getData?.filePath}`,
699
+ 'filePath': getSignedUrl, // `${url[getData?.type]}${getData?.filePath}`,
675
700
  'steps': getData?.steps,
676
701
  'startTime': dayjs().tz( 'Asia/Kolkata' ),
677
702
  'createdAt': dayjs().tz( 'Asia/Kolkata' ),
@@ -724,7 +749,7 @@ export async function getFile( req, res ) {
724
749
  'spokenLanguage': getData?.spokenLanguage || '',
725
750
  'auditStatus': 'In-Progress',
726
751
  'totalSteps': getData?.totalSteps,
727
- 'filePath': `${url[getData?.type]}${getData?.filePath}`,
752
+ 'filePath': getSignedUrl, // `${url[getData?.type]}${getData?.filePath}`,
728
753
  'steps': getData?.steps,
729
754
  'auditType': 'Re-Audit',
730
755
  'startTime': dayjs().tz( 'Asia/Kolkata' ),
@@ -752,7 +777,7 @@ export async function save( req, res ) {
752
777
  const inputData = req.body;
753
778
  const openSearch = JSON.parse( process.env.OPENSEARCH );
754
779
  const ses = JSON.parse( process.env.SES );
755
- const url = JSON.parse( process.env.URL );
780
+ // const url = JSON.parse( process.env.URL );
756
781
 
757
782
  let searchFilter =[
758
783
  {
@@ -818,6 +843,7 @@ export async function save( req, res ) {
818
843
  if ( !output ) {
819
844
  return res.sendError( 'This file is currently being audited by another user. Any actions you perform will not be saved.', 400 );
820
845
  }
846
+
821
847
  const record ={
822
848
  'steps': inputData?.steps,
823
849
  'auditStatus': inputData?.auditStatus,
@@ -847,10 +873,10 @@ export async function save( req, res ) {
847
873
 
848
874
  const getEyetestConfig = await findOneEyeTestConfig( { clientId: req?.user.userType == 'tango'? inputData?.clientId : req.user.clientId, configureType: 'email' }, { complianceThreshold: 1 } );
849
875
 
850
- if ( getEyetestConfig &&( inputData.auditStatus == 'Audited' ||inputData.auditStatus == 'Re-Audited' ) && inputUpdatedData && inputData.type === 'physical' && inputData?.isReSend !== false ) {
876
+ if ( getEyetestConfig &&( inputData.auditStatus == 'Audited' ||inputData.auditStatus == 'Re-Audited' ) && inputUpdatedData && inputData?.isReSend !== false ) {
851
877
  const value = Number( getEyetestConfig?.complianceThreshold?.value?.split( '%' )[0] );
852
878
  const condition = getEyetestConfig?.complianceThreshold?.condition;
853
- const id= inputData?.isReSend === true ?`${inputData.id}_${inputUpdatedData?._source?.optumId}_${inputData?.fileId}_${Date.now()}` : `${inputData.id}_${inputUpdatedData?._source?.optumId}_${inputData?.fileId}`;
879
+ const id= inputData?.isReSend === true ?`${inputData.id}_${inputUpdatedData?._source?.type === 'physical'?inputUpdatedData?._source?.optumId:inputUpdatedData?._source?.optm_userId}_${inputData?.fileId}_${Date.now()}` : `${inputData.id}_${inputUpdatedData?._source?.type === 'physical'?inputUpdatedData?._source?.optumId:inputUpdatedData?._source?.optm_userId}_${inputData?.fileId}`;
854
880
  const humanScore = Math.round( ( inputUpdatedData?._source?.auditedSteps /inputUpdatedData?._source?.totalSteps ) * 100 );
855
881
  const userName = await findOneUser( { _id: new mongoose.Types.ObjectId( inputUpdatedData?._source?.userId ) }, { userName: 1 } );
856
882
  const emailList = inputData?.RMEmail?.split( ',' );
@@ -905,14 +931,26 @@ export async function save( req, res ) {
905
931
  steps.sort(
906
932
  ( a, b ) => order.indexOf( a.processName ) - order.indexOf( b.processName ),
907
933
  );
934
+ const inputBucketName = inputUpdatedData?._source?.type === 'remote'? bucket?.remoteInput : bucket?.physicalInput;
935
+ const inputOldBucketName = inputUpdatedData?._source?.type === 'remote'? bucket?.remoteOldInput : bucket?.physicalOldInput;
936
+ const configDate = new Date( updatedDate );
937
+ const fileDate = new Date( inputUpdatedData?._source?.fileDate );
938
+ const params = {
939
+ file_path: inputUpdatedData?._source?.filePath,
940
+ Bucket: fileDate > configDate ? inputBucketName: inputOldBucketName,
941
+ key: fileDate > configDate ?'akamai' : 'aws',
942
+ type: getData?.type
943
+ };
944
+ const getSignedUrl = await signedUrl( params );
945
+ logger.info( { mesagee: 'signedurl', getSignedUrl: getSignedUrl, params: params } );
908
946
  switch ( condition ) {
909
947
  case '>': if ( humanScore > value ) {
910
948
  const record1 = {
911
949
  RMEmail: inputData.RMEmail,
912
950
  RMName: rmName.toString(),
913
951
  cluster: inputData.cluster,
914
- optumId: inputUpdatedData?._source?.optumId,
915
- optomEmailId: inputUpdatedData?._source?.salesmanEmailId,
952
+ optumId: inputUpdatedData?._source?.type === 'physical'?inputUpdatedData?._source?.optumId:inputUpdatedData?._source?.optm_userId,
953
+ optomEmailId: inputUpdatedData?._source?.type === 'physical'? inputUpdatedData?._source?.salesmanEmailId:inputUpdatedData?._source?.userEmail,
916
954
  storeName: inputUpdatedData?._source?.storeName,
917
955
  complianceScore: inputUpdatedData?._source?.ComplianceScore,
918
956
  humanScore: humanScore,
@@ -920,27 +958,30 @@ export async function save( req, res ) {
920
958
  trustScore: inputUpdatedData?._source?.trustScore,
921
959
  auditedId: inputUpdatedData?._id,
922
960
  queueId: inputUpdatedData?._source?.queueId,
961
+ engagementId: inputUpdatedData?._source?.type === 'physical'? '' : inputUpdatedData?._source?.engagementId,
962
+ eyetestType: inputUpdatedData?._source?.type,
923
963
  createdAt: new Date(),
924
964
  updatedAt: new Date(),
925
965
 
966
+
926
967
  };
927
968
  const reference1 ={
928
969
  storeCode: inputUpdatedData?._source?.storeName,
929
- OptomId: inputUpdatedData?._source?.optumId,
970
+ OptomId: inputUpdatedData?._source?.type === 'physical'?inputUpdatedData?._source?.optumId:inputUpdatedData?._source?.optm_userId,
930
971
  feedBackIssuedBy: req?.user?.email,
931
- RMName: inputData.RMEmail,
932
- clusterName: inputData.cluster,
972
+ RMName: inputData?.RMEmail,
973
+ clusterName: inputData?.cluster,
933
974
  };
934
975
  await insertWithId( openSearch.eyeTestEmailAlert, id, record1 );
935
976
  sendComplianceEmail( {
936
- toEmail: inputUpdatedData?._source?.salesmanEmailId,
977
+ toEmail: inputUpdatedData?._source?.type === 'physical'? inputUpdatedData?._source?.salesmanEmailId:inputUpdatedData?._source?.userEmail,
937
978
  fromEmail: ses.eyeTestAlertEmail,
938
979
  userName: 'Optom',
939
980
  storeName: inputUpdatedData?._source?.storeName,
940
- startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source.testEndTime}`,
981
+ startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source?.testEndTime}`,
941
982
  compliancePercentage: humanScore,
942
983
  steps: steps,
943
- videoUrl: `${url.physical}${inputUpdatedData?._source?.filePath}`,
984
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
944
985
  ref: reference1,
945
986
  } );
946
987
  }
@@ -950,8 +991,8 @@ export async function save( req, res ) {
950
991
  RMEmail: inputData.RMEmail,
951
992
  RMName: rmName.toString(),
952
993
  cluster: inputData.cluster,
953
- optumId: inputUpdatedData?._source?.optumId,
954
- optomEmailId: inputUpdatedData?._source?.salesmanEmailId,
994
+ optumId: inputUpdatedData?._source?.type === 'physical'?inputUpdatedData?._source?.optumId:inputUpdatedData?._source?.optm_userId,
995
+ optomEmailId: inputUpdatedData?._source?.type === 'physical'? inputUpdatedData?._source?.salesmanEmailId:inputUpdatedData?._source?.userEmail,
955
996
  storeName: inputUpdatedData?._source?.storeName,
956
997
  complianceScore: inputUpdatedData?._source?.ComplianceScore,
957
998
  humanScore: humanScore,
@@ -959,27 +1000,28 @@ export async function save( req, res ) {
959
1000
  trustScore: inputUpdatedData?._source?.trustScore,
960
1001
  auditedId: inputUpdatedData?._id,
961
1002
  queueId: inputUpdatedData?._source?.queueId,
1003
+ engagementId: inputUpdatedData?._source?.type === 'physical'? '' : inputUpdatedData?._source?.engagementId,
962
1004
  createdAt: new Date(),
963
1005
  updatedAt: new Date(),
964
1006
 
965
1007
  };
966
1008
  const reference2 ={
967
1009
  storeCode: inputUpdatedData?._source?.storeName,
968
- OptomId: inputUpdatedData?._source?.optumId,
1010
+ OptomId: inputUpdatedData?._source?.type === 'physical'?inputUpdatedData?._source?.optumId:inputUpdatedData?._source?.optm_userId,
969
1011
  feedBackIssuedBy: req?.user?.email,
970
1012
  RMName: inputData.RMEmail,
971
1013
  clusterName: inputData.cluster,
972
1014
  };
973
1015
  await insertWithId( openSearch.eyeTestEmailAlert, id, record2 );
974
1016
  sendComplianceEmail( {
975
- toEmail: inputUpdatedData?._source?.salesmanEmailId,
1017
+ toEmail: inputUpdatedData?._source?.type === 'physical'? inputUpdatedData?._source?.salesmanEmailId:inputUpdatedData?._source?.userEmail,
976
1018
  fromEmail: ses.eyeTestAlertEmail,
977
1019
  userName: 'Optom',
978
1020
  storeName: inputUpdatedData?._source?.storeName,
979
1021
  startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source.testEndTime}`,
980
1022
  compliancePercentage: humanScore,
981
1023
  steps: steps,
982
- videoUrl: `${url.physical}${inputUpdatedData?._source?.filePath}`,
1024
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
983
1025
  ref: reference2,
984
1026
  } );
985
1027
  };
@@ -989,8 +1031,10 @@ export async function save( req, res ) {
989
1031
  RMEmail: inputData.RMEmail,
990
1032
  RMName: rmName.toString(),
991
1033
  cluster: inputData.cluster,
992
- optumId: inputUpdatedData?._source?.optumId,
993
- optomEmailId: inputUpdatedData?._source?.salesmanEmailId,
1034
+ optumId: inputUpdatedData?._source?.type === 'physical'?inputUpdatedData?._source?.optumId:inputUpdatedData?._source?.optm_userId,
1035
+
1036
+ optomEmailId: inputUpdatedData?._source?.type === 'physical'? inputUpdatedData?._source?.salesmanEmailId:inputUpdatedData?._source?.userEmail,
1037
+
994
1038
  storeName: inputUpdatedData?._source?.storeName,
995
1039
  complianceScore: inputUpdatedData?._source?.ComplianceScore,
996
1040
  humanScore: humanScore,
@@ -998,27 +1042,32 @@ export async function save( req, res ) {
998
1042
  trustScore: inputUpdatedData?._source?.trustScore,
999
1043
  auditedId: inputUpdatedData?._id,
1000
1044
  queueId: inputUpdatedData?._source?.queueId,
1045
+ engagementId: inputUpdatedData?._source?.type === 'physical'? '' : inputUpdatedData?._source?.engagementId,
1046
+
1001
1047
  createdAt: new Date(),
1002
1048
  updatedAt: new Date(),
1003
1049
 
1004
1050
  };
1005
1051
  const reference3 ={
1006
1052
  storeCode: inputUpdatedData?._source?.storeName,
1007
- OptomId: inputUpdatedData?._source?.optumId,
1053
+ OptomId: inputUpdatedData?._source?.type === 'physical'?inputUpdatedData?._source?.optumId:inputUpdatedData?._source?.optm_userId,
1054
+
1008
1055
  feedBackIssuedBy: req?.user?.email,
1009
1056
  RMName: inputData.RMEmail,
1010
1057
  clusterName: inputData.cluster,
1011
1058
  };
1012
1059
  await insertWithId( openSearch.eyeTestEmailAlert, id, record3 );
1013
1060
  sendComplianceEmail( {
1014
- toEmail: inputUpdatedData?._source?.salesmanEmailId,
1061
+ toEmail: inputUpdatedData?._source?.type === 'physical'? inputUpdatedData?._source?.salesmanEmailId:inputUpdatedData?._source?.userEmail,
1062
+
1015
1063
  fromEmail: ses.eyeTestAlertEmail,
1016
1064
  userName: 'Optom',
1017
1065
  storeName: inputUpdatedData?._source?.storeName,
1018
1066
  startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source.testEndTime}`,
1019
1067
  compliancePercentage: humanScore,
1020
1068
  steps: steps,
1021
- videoUrl: `${url.physical}${inputUpdatedData?._source?.filePath}`,
1069
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1070
+
1022
1071
  ref: reference3,
1023
1072
  } );
1024
1073
  }
@@ -1028,8 +1077,10 @@ export async function save( req, res ) {
1028
1077
  RMEmail: inputData.RMEmail,
1029
1078
  RMName: rmName.toString(),
1030
1079
  cluster: inputData.cluster,
1031
- optumId: inputUpdatedData?._source?.optumId,
1032
- optomEmailId: inputUpdatedData?._source?.salesmanEmailId,
1080
+ optumId: inputUpdatedData?._source?.type === 'physical'?inputUpdatedData?._source?.optumId:inputUpdatedData?._source?.optm_userId,
1081
+ optomEmailId: inputUpdatedData?._source?.type === 'physical'? inputUpdatedData?._source?.salesmanEmailId:inputUpdatedData?._source?.userEmail,
1082
+
1083
+
1033
1084
  storeName: inputUpdatedData?._source?.storeName,
1034
1085
  complianceScore: inputUpdatedData?._source?.ComplianceScore,
1035
1086
  humanScore: humanScore,
@@ -1037,27 +1088,29 @@ export async function save( req, res ) {
1037
1088
  trustScore: inputUpdatedData?._source?.trustScore,
1038
1089
  auditedId: inputUpdatedData?._id,
1039
1090
  queueId: inputUpdatedData?._source?.queueId,
1091
+ engagementId: inputUpdatedData?._source?.type === 'physical'? '' : inputUpdatedData?._source?.engagementId,
1092
+
1040
1093
  createdAt: new Date(),
1041
1094
  updatedAt: new Date(),
1042
1095
 
1043
1096
  };
1044
1097
  const reference4 ={
1045
1098
  storeCode: inputUpdatedData?._source?.storeName,
1046
- OptomId: inputUpdatedData?._source?.optumId,
1099
+ OptomId: inputUpdatedData?._source?.type === 'physical'?inputUpdatedData?._source?.optumId:inputUpdatedData?._source?.optm_userId,
1047
1100
  feedBackIssuedBy: req?.user?.email,
1048
1101
  RMName: inputData.RMEmail,
1049
1102
  clusterName: inputData.cluster,
1050
1103
  };
1051
1104
  await insertWithId( openSearch.eyeTestEmailAlert, id, record4 );
1052
1105
  sendComplianceEmail( {
1053
- toEmail: inputUpdatedData?._source?.salesmanEmailId,
1106
+ toEmail: inputUpdatedData?._source?.type === 'physical'? inputUpdatedData?._source?.salesmanEmailId:inputUpdatedData?._source?.userEmail,
1054
1107
  fromEmail: ses.eyeTestAlertEmail,
1055
1108
  userName: 'Optom',
1056
1109
  storeName: inputUpdatedData?._source?.storeName,
1057
1110
  startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source.testEndTime}`,
1058
1111
  compliancePercentage: humanScore,
1059
1112
  steps: steps,
1060
- videoUrl: `${url.physical}${inputUpdatedData?._source?.filePath}`,
1113
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1061
1114
  ref: reference4,
1062
1115
  } );
1063
1116
  }
@@ -1068,8 +1121,8 @@ export async function save( req, res ) {
1068
1121
  RMEmail: inputData.RMEmail,
1069
1122
  RMName: rmName.toString(),
1070
1123
  cluster: inputData.cluster,
1071
- optumId: inputUpdatedData?._source?.optumId,
1072
- optomEmailId: inputUpdatedData?._source?.salesmanEmailId,
1124
+ optumId: inputUpdatedData?._source?.type === 'physical'?inputUpdatedData?._source?.optumId:inputUpdatedData?._source?.optm_userId,
1125
+ optomEmailId: inputUpdatedData?._source?.type === 'physical'? inputUpdatedData?._source?.salesmanEmailId:inputUpdatedData?._source?.userEmail,
1073
1126
  storeName: inputUpdatedData?._source?.storeName,
1074
1127
  complianceScore: inputUpdatedData?._source?.ComplianceScore,
1075
1128
  humanScore: humanScore,
@@ -1077,27 +1130,28 @@ export async function save( req, res ) {
1077
1130
  trustScore: inputUpdatedData?._source?.trustScore,
1078
1131
  auditedId: inputUpdatedData?._id,
1079
1132
  queueId: inputUpdatedData?._source?.queueId,
1133
+ engagementId: inputUpdatedData?._source?.type === 'physical'? '' : inputUpdatedData?._source?.engagementId,
1080
1134
  createdAt: new Date(),
1081
1135
  updatedAt: new Date(),
1082
1136
 
1083
1137
  };
1084
1138
  const reference5 ={
1085
1139
  storeCode: inputUpdatedData?._source?.storeName,
1086
- OptomId: inputUpdatedData?._source?.optumId,
1140
+ OptomId: inputUpdatedData?._source?.type === 'physical'?inputUpdatedData?._source?.optumId:inputUpdatedData?._source?.optm_userId,
1087
1141
  feedBackIssuedBy: req?.user?.email,
1088
1142
  RMName: inputData.RMEmail,
1089
1143
  clusterName: inputData.cluster,
1090
1144
  };
1091
1145
  await insertWithId( openSearch.eyeTestEmailAlert, id, record5 );
1092
1146
  sendComplianceEmail( {
1093
- toEmail: inputUpdatedData?._source?.salesmanEmailId,
1147
+ toEmail: inputUpdatedData?._source?.type === 'physical'? inputUpdatedData?._source?.salesmanEmailId:inputUpdatedData?._source?.userEmail,
1094
1148
  fromEmail: ses.eyeTestAlertEmail,
1095
1149
  userName: 'Optom',
1096
1150
  storeName: inputUpdatedData?._source?.storeName,
1097
1151
  startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source.testEndTime}`,
1098
1152
  compliancePercentage: humanScore,
1099
1153
  steps: steps,
1100
- videoUrl: `${url.physical}${inputUpdatedData?._source?.filePath}`,
1154
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1101
1155
  ref: reference5,
1102
1156
  } );
1103
1157
  }
@@ -1107,8 +1161,8 @@ export async function save( req, res ) {
1107
1161
  RMEmail: inputData.RMEmail,
1108
1162
  RMName: rmName.toString(),
1109
1163
  cluster: inputData.cluster,
1110
- optumId: inputUpdatedData?._source?.optumId,
1111
- optomEmailId: inputUpdatedData?._source?.salesmanEmailId,
1164
+ optumId: inputUpdatedData?._source?.type === 'physical'?inputUpdatedData?._source?.optumId:inputUpdatedData?._source?.optm_userId,
1165
+ optomEmailId: inputUpdatedData?._source?.type === 'physical'? inputUpdatedData?._source?.salesmanEmailId:inputUpdatedData?._source?.userEmail,
1112
1166
  storeName: inputUpdatedData?._source?.storeName,
1113
1167
  complianceScore: inputUpdatedData?._source?.ComplianceScore,
1114
1168
  humanScore: humanScore,
@@ -1116,26 +1170,27 @@ export async function save( req, res ) {
1116
1170
  trustScore: inputUpdatedData?._source?.trustScore,
1117
1171
  auditedId: inputUpdatedData?._id,
1118
1172
  queueId: inputUpdatedData?._source?.queueId,
1173
+ engagementId: inputUpdatedData?._source?.type === 'physical'? '' : inputUpdatedData?._source?.engagementId,
1119
1174
  createdAt: new Date(),
1120
1175
  updatedAt: new Date(),
1121
1176
  };
1122
1177
  const reference6 ={
1123
1178
  storeCode: inputUpdatedData?._source?.storeName,
1124
- OptomId: inputUpdatedData?._source?.optumId,
1179
+ OptomId: inputUpdatedData?._source?.type === 'physical'?inputUpdatedData?._source?.optumId:inputUpdatedData?._source?.optm_userId,
1125
1180
  feedBackIssuedBy: req?.user?.email,
1126
1181
  RMName: inputData.RMEmail,
1127
1182
  clusterName: inputData.cluster,
1128
1183
  };
1129
1184
  await insertWithId( openSearch.eyeTestEmailAlert, id, record6 );
1130
1185
  sendComplianceEmail( {
1131
- toEmail: inputUpdatedData?._source?.salesmanEmailId,
1186
+ toEmail: inputUpdatedData?._source?.type === 'physical'? inputUpdatedData?._source?.salesmanEmailId:inputUpdatedData?._source?.userEmail,
1132
1187
  fromEmail: ses.eyeTestAlertEmail,
1133
1188
  userName: 'Optom',
1134
1189
  storeName: inputUpdatedData?._source?.storeName,
1135
1190
  startTime: `${inputUpdatedData?._source?.fileDate}T${inputUpdatedData?._source.testEndTime}`,
1136
1191
  compliancePercentage: humanScore,
1137
1192
  steps: steps,
1138
- videoUrl: `${url.physical}${inputUpdatedData?._source?.filePath}`,
1193
+ videoUrl: getSignedUrl, // `${inputUpdatedData?._source?.type === 'physical'?url.physical:url.remote}${inputUpdatedData?._source?.filePath}`,
1139
1194
  ref: reference6,
1140
1195
  } );
1141
1196
  }
@@ -2788,7 +2843,7 @@ export async function emailAlertLog( req, res ) {
2788
2843
  const exportData = [];
2789
2844
  for ( const element of chunk ) {
2790
2845
  exportData.push( {
2791
- 'RM Name': element.RMEmail,
2846
+ 'RM Name': element.RMName,
2792
2847
  'Cluster Name': element.cluster,
2793
2848
  'Optom ID': element.optumId,
2794
2849
  'Optom Email': element.optomEmailId || '--',
@@ -281,7 +281,7 @@ export const emailAlertLogSchema = joi.object( {
281
281
  return value;
282
282
  } ),
283
283
  RMList: joi.array().items(
284
- joi.string().required(),
284
+ joi.string().optional(),
285
285
  ).optional(),
286
286
  clientId: joi.string().when( '$userType', {
287
287
  is: 'tango',
@@ -291,7 +291,7 @@ export const emailAlertLogSchema = joi.object( {
291
291
  } ),
292
292
  otherwise: joi.optional(),
293
293
  } ),
294
- cluster: joi.array().items( joi.string().required() ).optional(),
294
+ cluster: joi.array().items( joi.string().optional() ).optional(),
295
295
  isExport: joi.boolean().optional(),
296
296
  searchValue: joi.string().optional().allow( '' ),
297
297
  sortBy: joi.string().optional(),
@@ -44,9 +44,9 @@ export async function sendAlert( req, res, next ) {
44
44
  try {
45
45
  const inputData = req.body;
46
46
  const openSearch = JSON.parse( process.env.OPENSEARCH );
47
- if ( inputData.auditStatus == 'Re-Audited' && inputData.type == 'physical' && inputData?.isReSend == undefined ) {
47
+ if ( inputData.auditStatus == 'Re-Audited' && inputData?.isReSend == undefined ) {
48
48
  const getOne = await getOpenSearchById( openSearch.EyeTestInput, inputData.id );
49
- const id = `${inputData.id}_${getOne?.body?._source?.optumId}_${inputData.fileId}`;
49
+ const id = `${inputData.id}_${getOne?.body?._source?.type === 'physical' ? getOne?.body?._source?.optumId : getOne?.body?._source?.optm_userId}_${inputData.fileId}`;
50
50
  const getId = await getOpenSearchById( openSearch.eyeTestEmailAlert, id );
51
51
  logger.info( { getId: getId, id: id } );
52
52
  const inputUpdatedData = getId?.body;