tango-app-api-audit 3.6.40 → 3.6.42-eyetest-dynamicization.0

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