tango-app-api-audit 3.6.17 → 3.6.19
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
|
@@ -811,7 +811,6 @@ export async function save( req, res ) {
|
|
|
811
811
|
},
|
|
812
812
|
};
|
|
813
813
|
const getOutput = await getOpenSearchData( openSearch.EyeTestOutput, searchQuery );
|
|
814
|
-
logger.info( { getOutput: getOutput } );
|
|
815
814
|
const output = getOutput?.body?.hits?.hits?.length > 0 ? getOutput?.body?.hits?.hits[0] : null;
|
|
816
815
|
if ( !output ) {
|
|
817
816
|
return res.sendError( 'This file is currently being audited by another user. Any actions you perform will not be saved.', 400 );
|
|
@@ -845,19 +844,27 @@ export async function save( req, res ) {
|
|
|
845
844
|
|
|
846
845
|
const getEyetestConfig = await findOneEyeTestConfig( { clientId: req?.user.userType == 'tango'? inputData?.clientId : req.user.clientId, configureType: 'email' }, { complianceThreshold: 1 } );
|
|
847
846
|
|
|
848
|
-
if ( getEyetestConfig && inputData.auditStatus == 'Audited' && inputUpdatedData ) {
|
|
847
|
+
if ( getEyetestConfig &&( inputData.auditStatus == 'Audited' ||inputData.auditStatus == 'ReAudited' ) && inputUpdatedData && inputData.type === 'physical' && inputData?.isReSend !== false ) {
|
|
849
848
|
const trustScore = Math.round( 100-( ( inputData?.overRides / inputData?.steps?.length ) * 100 ) );
|
|
850
849
|
const value = Number( getEyetestConfig?.complianceThreshold?.value?.split( '%' )[0] );
|
|
851
850
|
const condition = getEyetestConfig?.complianceThreshold?.condition;
|
|
852
|
-
const id=
|
|
851
|
+
const id= inputData?.isReSend === true ?`${inputData.id}_${inputUpdatedData?._source?.optumId}_${inputData?.fileId}_${Date.now()}` : `${inputData.id}_${inputUpdatedData?._source?.optumId}_${inputData?.fileId}`;
|
|
852
|
+
const humanScore = Math.round( ( inputUpdatedData?._source?.auditedSteps /inputUpdatedData?._source?.totalSteps ) * 100 );
|
|
853
|
+
const userName = await findOneUser( { _id: new mongoose.Types.ObjectId( inputUpdatedData?._source?.userId ) }, { userName: 1 } );
|
|
854
|
+
|
|
855
|
+
|
|
853
856
|
switch ( condition ) {
|
|
854
857
|
case '>': if ( trustScore > value ) {
|
|
855
858
|
const record1 = {
|
|
856
859
|
RMEmail: inputData.RMEmail,
|
|
860
|
+
RMName: inputData.RMEmail,
|
|
857
861
|
cluster: inputData.cluster,
|
|
858
862
|
optumId: inputUpdatedData?._source?.optumId,
|
|
863
|
+
optomEmailId: inputUpdatedData?._source?.salesmanEmailId,
|
|
859
864
|
storeName: inputUpdatedData?._source?.storeName,
|
|
860
865
|
complianceScore: inputUpdatedData?._source?.ComplianceScore,
|
|
866
|
+
humanScore: humanScore,
|
|
867
|
+
auditedBy: userName?.userName || '',
|
|
861
868
|
trustScore: inputUpdatedData?._source?.trustScore,
|
|
862
869
|
auditedId: inputUpdatedData?._id,
|
|
863
870
|
queueId: inputUpdatedData?._source?.queueId,
|
|
@@ -871,10 +878,14 @@ export async function save( req, res ) {
|
|
|
871
878
|
case '<': if ( trustScore < value ) {
|
|
872
879
|
const record2 = {
|
|
873
880
|
RMEmail: inputData.RMEmail,
|
|
881
|
+
RMName: inputData.RMEmail,
|
|
874
882
|
cluster: inputData.cluster,
|
|
875
883
|
optumId: inputUpdatedData?._source?.optumId,
|
|
884
|
+
optomEmailId: inputUpdatedData?._source?.salesmanEmailId,
|
|
876
885
|
storeName: inputUpdatedData?._source?.storeName,
|
|
877
886
|
complianceScore: inputUpdatedData?._source?.ComplianceScore,
|
|
887
|
+
humanScore: humanScore,
|
|
888
|
+
auditedBy: userName?.userName || '',
|
|
878
889
|
trustScore: inputUpdatedData?._source?.trustScore,
|
|
879
890
|
auditedId: inputUpdatedData?._id,
|
|
880
891
|
queueId: inputUpdatedData?._source?.queueId,
|
|
@@ -888,10 +899,14 @@ export async function save( req, res ) {
|
|
|
888
899
|
case '>=': if ( trustScore >= value ) {
|
|
889
900
|
const record3 = {
|
|
890
901
|
RMEmail: inputData.RMEmail,
|
|
902
|
+
RMName: inputData.RMEmail,
|
|
891
903
|
cluster: inputData.cluster,
|
|
892
904
|
optumId: inputUpdatedData?._source?.optumId,
|
|
905
|
+
optomEmailId: inputUpdatedData?._source?.salesmanEmailId,
|
|
893
906
|
storeName: inputUpdatedData?._source?.storeName,
|
|
894
907
|
complianceScore: inputUpdatedData?._source?.ComplianceScore,
|
|
908
|
+
humanScore: humanScore,
|
|
909
|
+
auditedBy: userName?.userName || '',
|
|
895
910
|
trustScore: inputUpdatedData?._source?.trustScore,
|
|
896
911
|
auditedId: inputUpdatedData?._id,
|
|
897
912
|
queueId: inputUpdatedData?._source?.queueId,
|
|
@@ -905,10 +920,14 @@ export async function save( req, res ) {
|
|
|
905
920
|
case '<=': if ( trustScore <= value ) {
|
|
906
921
|
const record4 = {
|
|
907
922
|
RMEmail: inputData.RMEmail,
|
|
923
|
+
RMName: inputData.RMEmail,
|
|
908
924
|
cluster: inputData.cluster,
|
|
909
925
|
optumId: inputUpdatedData?._source?.optumId,
|
|
926
|
+
optomEmailId: inputUpdatedData?._source?.salesmanEmailId,
|
|
910
927
|
storeName: inputUpdatedData?._source?.storeName,
|
|
911
928
|
complianceScore: inputUpdatedData?._source?.ComplianceScore,
|
|
929
|
+
humanScore: humanScore,
|
|
930
|
+
auditedBy: userName?.userName || '',
|
|
912
931
|
trustScore: inputUpdatedData?._source?.trustScore,
|
|
913
932
|
auditedId: inputUpdatedData?._id,
|
|
914
933
|
queueId: inputUpdatedData?._source?.queueId,
|
|
@@ -923,10 +942,14 @@ export async function save( req, res ) {
|
|
|
923
942
|
case '==': if ( trustScore == value ) {
|
|
924
943
|
const record5 = {
|
|
925
944
|
RMEmail: inputData.RMEmail,
|
|
945
|
+
RMName: inputData.RMEmail,
|
|
926
946
|
cluster: inputData.cluster,
|
|
927
947
|
optumId: inputUpdatedData?._source?.optumId,
|
|
948
|
+
optomEmailId: inputUpdatedData?._source?.salesmanEmailId,
|
|
928
949
|
storeName: inputUpdatedData?._source?.storeName,
|
|
929
950
|
complianceScore: inputUpdatedData?._source?.ComplianceScore,
|
|
951
|
+
humanScore: humanScore,
|
|
952
|
+
auditedBy: userName?.userName || '',
|
|
930
953
|
trustScore: inputUpdatedData?._source?.trustScore,
|
|
931
954
|
auditedId: inputUpdatedData?._id,
|
|
932
955
|
queueId: inputUpdatedData?._source?.queueId,
|
|
@@ -940,10 +963,14 @@ export async function save( req, res ) {
|
|
|
940
963
|
case '===': if ( trustScore === value ) {
|
|
941
964
|
const record6 = {
|
|
942
965
|
RMEmail: inputData.RMEmail,
|
|
966
|
+
RMName: inputData.RMEmail,
|
|
943
967
|
cluster: inputData.cluster,
|
|
944
968
|
optumId: inputUpdatedData?._source?.optumId,
|
|
969
|
+
optomEmailId: inputUpdatedData?._source?.salesmanEmailId,
|
|
945
970
|
storeName: inputUpdatedData?._source?.storeName,
|
|
946
971
|
complianceScore: inputUpdatedData?._source?.ComplianceScore,
|
|
972
|
+
humanScore: humanScore,
|
|
973
|
+
auditedBy: userName?.userName || '',
|
|
947
974
|
trustScore: inputUpdatedData?._source?.trustScore,
|
|
948
975
|
auditedId: inputUpdatedData?._id,
|
|
949
976
|
queueId: inputUpdatedData?._source?.queueId,
|
|
@@ -956,7 +983,7 @@ export async function save( req, res ) {
|
|
|
956
983
|
default: throw new Error( `Unknown condition: ${condition}` );
|
|
957
984
|
}
|
|
958
985
|
}
|
|
959
|
-
return res.sendSuccess( 'The file has been
|
|
986
|
+
return res.sendSuccess( 'The file has been submitted successfully' );
|
|
960
987
|
} catch ( error ) {
|
|
961
988
|
const err = error.message || 'Internal Server Error';
|
|
962
989
|
logger.error( { message: error, data: req.params, function: 'eyetestAudit-controller-save' } );
|
|
@@ -1198,18 +1225,25 @@ export async function userAuditedData( req, res ) {
|
|
|
1198
1225
|
|
|
1199
1226
|
export async function summaryList( req, res ) {
|
|
1200
1227
|
try {
|
|
1228
|
+
// declare inputData and get request body
|
|
1201
1229
|
const inputData = req.body;
|
|
1230
|
+
|
|
1231
|
+
// throw 204 if client id is not 11
|
|
1202
1232
|
if ( inputData.clientId !== '11' ) {
|
|
1203
1233
|
return res.sendError( 'No data found', 204 );
|
|
1204
1234
|
}
|
|
1205
1235
|
|
|
1236
|
+
// declare openSearch and get data form the .env/secret manager
|
|
1206
1237
|
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
1238
|
+
|
|
1239
|
+
// set limit, offset, sortBy, sortOrder value if not set default value
|
|
1207
1240
|
const limit = inputData.limit || 10;
|
|
1208
1241
|
const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
|
|
1209
1242
|
|
|
1210
1243
|
const sortBy = inputData?.sortBy ? [ 'coveredStepsAI', 'trustScore', 'date', 'ComplianceScore', 'auditedSteps' ].includes( inputData.sortBy ) ? inputData.sortBy :`${inputData.sortBy}.keyword` : 'storeName.keyword';
|
|
1211
1244
|
const order = inputData?.sortOrder || -1;
|
|
1212
1245
|
|
|
1246
|
+
// declare filter and assign range values from inputData
|
|
1213
1247
|
let filter= [
|
|
1214
1248
|
{
|
|
1215
1249
|
'range': {
|
|
@@ -1222,6 +1256,7 @@ export async function summaryList( req, res ) {
|
|
|
1222
1256
|
|
|
1223
1257
|
];
|
|
1224
1258
|
|
|
1259
|
+
// filter by Audit Status if key has minimum one element
|
|
1225
1260
|
if ( inputData?.auditStatus && inputData?.auditStatus?.length > 0 ) {
|
|
1226
1261
|
filter.push( {
|
|
1227
1262
|
'terms': {
|
|
@@ -1229,6 +1264,8 @@ export async function summaryList( req, res ) {
|
|
|
1229
1264
|
},
|
|
1230
1265
|
} );
|
|
1231
1266
|
}
|
|
1267
|
+
|
|
1268
|
+
// filter by Visitors Type if key has minimum one element
|
|
1232
1269
|
if ( inputData?.demographics && inputData?.demographics?.length > 0 ) {
|
|
1233
1270
|
filter.push( {
|
|
1234
1271
|
'terms': {
|
|
@@ -1236,6 +1273,8 @@ export async function summaryList( req, res ) {
|
|
|
1236
1273
|
},
|
|
1237
1274
|
} );
|
|
1238
1275
|
}
|
|
1276
|
+
|
|
1277
|
+
// filter by Eye test Type if key has string value one element
|
|
1239
1278
|
if ( inputData.type && inputData.type!='' ) {
|
|
1240
1279
|
filter.push( {
|
|
1241
1280
|
'term': {
|
|
@@ -1245,6 +1284,17 @@ export async function summaryList( req, res ) {
|
|
|
1245
1284
|
} );
|
|
1246
1285
|
}
|
|
1247
1286
|
|
|
1287
|
+
// filter by near addition if value != "" and eye test must be a physical
|
|
1288
|
+
if ( inputData.nearAddition && inputData.nearAddition!='' && inputData.type ==='physical' ) {
|
|
1289
|
+
filter.push( {
|
|
1290
|
+
'term': {
|
|
1291
|
+
'nearAddition.keyword': inputData.nearAddition,
|
|
1292
|
+
},
|
|
1293
|
+
|
|
1294
|
+
} );
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
// filter by stores if key has minimum one element else throw an error
|
|
1248
1298
|
if ( inputData.storeId && inputData.storeId.length > 0 ) {
|
|
1249
1299
|
filter.push( {
|
|
1250
1300
|
|
|
@@ -1253,15 +1303,20 @@ export async function summaryList( req, res ) {
|
|
|
1253
1303
|
},
|
|
1254
1304
|
|
|
1255
1305
|
} );
|
|
1256
|
-
}
|
|
1306
|
+
}
|
|
1307
|
+
else {
|
|
1257
1308
|
return res.sendError( 'No data found', 204 );
|
|
1258
1309
|
}
|
|
1259
1310
|
|
|
1311
|
+
// Declare mustQuery as an array and include all elements from the filter array
|
|
1260
1312
|
let mustQuery = [
|
|
1261
1313
|
...filter,
|
|
1262
1314
|
];
|
|
1263
1315
|
|
|
1264
|
-
|
|
1316
|
+
// filter by complianceScore/tango score if key has minimum one element
|
|
1317
|
+
if ( inputData.complianceScore && inputData.complianceScore?.length > 0 ) {
|
|
1318
|
+
|
|
1319
|
+
// If the key type is not 'store', split the compliance score ranges
|
|
1265
1320
|
if ( inputData.keyType !== 'store' ) {
|
|
1266
1321
|
const rangeShould = inputData?.complianceScore?.map( ( r ) => {
|
|
1267
1322
|
const [ gte, lte ] = r.split( '-' ).map( Number );
|
|
@@ -1271,7 +1326,7 @@ export async function summaryList( req, res ) {
|
|
|
1271
1326
|
},
|
|
1272
1327
|
};
|
|
1273
1328
|
} );
|
|
1274
|
-
|
|
1329
|
+
// Add the range conditions to mustQuery (any one of the ranges should match)
|
|
1275
1330
|
mustQuery.push(
|
|
1276
1331
|
{
|
|
1277
1332
|
bool: {
|
|
@@ -1280,7 +1335,9 @@ export async function summaryList( req, res ) {
|
|
|
1280
1335
|
},
|
|
1281
1336
|
},
|
|
1282
1337
|
);
|
|
1283
|
-
}
|
|
1338
|
+
}
|
|
1339
|
+
// If-else condition: use 'terms' filter to match records by Compliance Score / Tango Score
|
|
1340
|
+
else {
|
|
1284
1341
|
const values = Array.isArray( inputData.complianceScore ) ?
|
|
1285
1342
|
inputData.complianceScore.map( Number ) :
|
|
1286
1343
|
[ Number( inputData.complianceScore ) ];
|
|
@@ -1293,6 +1350,7 @@ export async function summaryList( req, res ) {
|
|
|
1293
1350
|
}
|
|
1294
1351
|
}
|
|
1295
1352
|
|
|
1353
|
+
// filter by category if key exist allow "fake, genuine" else throw valid category
|
|
1296
1354
|
if ( inputData?.category ) {
|
|
1297
1355
|
switch ( inputData?.category ) {
|
|
1298
1356
|
case 'fake':
|
|
@@ -1516,7 +1574,7 @@ export async function summaryList( req, res ) {
|
|
|
1516
1574
|
return res.sendError( 'No data', 204 );
|
|
1517
1575
|
}
|
|
1518
1576
|
const temp =[];
|
|
1519
|
-
|
|
1577
|
+
let finalTemp =[];
|
|
1520
1578
|
for ( const [ i, cluster ] of getCluster.entries() ) {
|
|
1521
1579
|
temp.push( cluster );
|
|
1522
1580
|
const getClusterQuery= {
|
|
@@ -1550,21 +1608,24 @@ export async function summaryList( req, res ) {
|
|
|
1550
1608
|
},
|
|
1551
1609
|
},
|
|
1552
1610
|
},
|
|
1611
|
+
|
|
1553
1612
|
};
|
|
1554
|
-
logger.info( { getClusterQuery: getClusterQuery } );
|
|
1555
1613
|
const getResponse = await getOpenSearchData( openSearch.EyeTestInput, getClusterQuery );
|
|
1556
|
-
|
|
1614
|
+
logger.info( { getResponse: getResponse } );
|
|
1615
|
+
if ( getResponse?.body?.aggregations && getResponse?.body?.aggregations?.total_count?.value > 0 ) {
|
|
1557
1616
|
delete temp[i].store;
|
|
1558
1617
|
delete temp[i]._id;
|
|
1618
|
+
|
|
1559
1619
|
temp[i].totalFiles = getResponse?.body?.aggregations?.total_count?.value || 0,
|
|
1560
1620
|
temp[i].completedFiles=getResponse?.body?.aggregations?.audited_trustScore?.totalCount?.value || 0;
|
|
1561
1621
|
temp[i].complianceScore = `${ Math.round( getResponse?.body?.aggregations?.avg_complianceScore?.value || 0 )} %`;
|
|
1562
1622
|
temp[i].trustScore = getResponse?.body?.aggregations?.audited_trustScore?.avg_trustScore?.value ==null || getResponse?.body?.aggregations?.audited_trustScore?.avg_trustScore?.value == undefined ?'NA':`${Math.round( getResponse?.body?.aggregations?.audited_trustScore?.avg_trustScore?.value ) + ' %'}`;
|
|
1623
|
+
finalTemp.push( temp[i] );
|
|
1563
1624
|
}
|
|
1564
1625
|
}
|
|
1565
1626
|
|
|
1566
1627
|
if ( inputData.isExport == true ) {
|
|
1567
|
-
const chunkedMappingData = await chunkArray(
|
|
1628
|
+
const chunkedMappingData = await chunkArray( finalTemp, 10 );
|
|
1568
1629
|
const promises = chunkedMappingData.map( async ( chunk ) => {
|
|
1569
1630
|
const exportData = [];
|
|
1570
1631
|
for ( const element of chunk ) {
|
|
@@ -1599,353 +1660,186 @@ export async function summaryList( req, res ) {
|
|
|
1599
1660
|
await download( result, res );
|
|
1600
1661
|
return;
|
|
1601
1662
|
} else {
|
|
1602
|
-
|
|
1663
|
+
if ( finalTemp.length > 0 ) {
|
|
1664
|
+
return res.sendSuccess( { result: finalTemp, count: count || 0 } );
|
|
1665
|
+
} else {
|
|
1666
|
+
return res.sendError( 'no data', 204 );
|
|
1667
|
+
}
|
|
1603
1668
|
}
|
|
1604
|
-
}
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
},
|
|
1669
|
+
}
|
|
1670
|
+
let search ={
|
|
1671
|
+
'must': filter,
|
|
1672
|
+
};
|
|
1673
|
+
if ( inputData.searchValue && inputData.searchValue !== '' ) {
|
|
1674
|
+
if ( inputData.type&&inputData.type==='remote' ) {
|
|
1675
|
+
search ={
|
|
1676
|
+
'must': filter,
|
|
1677
|
+
'should': [
|
|
1678
|
+
{
|
|
1679
|
+
'wildcard': {
|
|
1680
|
+
'storeName.keyword': {
|
|
1681
|
+
'value': `*${inputData.searchValue}*`,
|
|
1618
1682
|
},
|
|
1619
1683
|
},
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
}
|
|
1684
|
+
},
|
|
1685
|
+
{
|
|
1686
|
+
'wildcard': {
|
|
1687
|
+
'storeId.keyword': {
|
|
1688
|
+
'value': `*${inputData.searchValue}*`,
|
|
1625
1689
|
},
|
|
1626
1690
|
},
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
}
|
|
1691
|
+
},
|
|
1692
|
+
{
|
|
1693
|
+
'wildcard': {
|
|
1694
|
+
'engagementId.keyword': {
|
|
1695
|
+
'value': `*${inputData.searchValue}*`,
|
|
1632
1696
|
},
|
|
1633
1697
|
},
|
|
1698
|
+
},
|
|
1634
1699
|
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
},
|
|
1700
|
+
{
|
|
1701
|
+
'wildcard': {
|
|
1702
|
+
'auditStatus.keyword': {
|
|
1703
|
+
'value': `*${inputData.searchValue}*`,
|
|
1640
1704
|
},
|
|
1641
1705
|
},
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
}
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
}
|
|
1706
|
+
},
|
|
1707
|
+
],
|
|
1708
|
+
'minimum_should_match': 1,
|
|
1709
|
+
};
|
|
1710
|
+
} else {
|
|
1711
|
+
search ={
|
|
1712
|
+
'must': filter,
|
|
1713
|
+
'should': [
|
|
1714
|
+
{
|
|
1715
|
+
'wildcard': {
|
|
1716
|
+
'storeName.keyword': {
|
|
1717
|
+
'value': `*${inputData.searchValue}*`,
|
|
1654
1718
|
},
|
|
1655
1719
|
},
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
}
|
|
1720
|
+
},
|
|
1721
|
+
{
|
|
1722
|
+
'wildcard': {
|
|
1723
|
+
'storeId.keyword': {
|
|
1724
|
+
'value': `*${inputData.searchValue}*`,
|
|
1661
1725
|
},
|
|
1662
1726
|
},
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
}
|
|
1727
|
+
},
|
|
1728
|
+
{
|
|
1729
|
+
'wildcard': {
|
|
1730
|
+
'engagementId.keyword': {
|
|
1731
|
+
'value': `*${inputData.searchValue}*`,
|
|
1668
1732
|
},
|
|
1669
1733
|
},
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
}
|
|
1734
|
+
},
|
|
1735
|
+
{
|
|
1736
|
+
'wildcard': {
|
|
1737
|
+
'queueId.keyword': {
|
|
1738
|
+
'value': `*${inputData.searchValue}*`,
|
|
1675
1739
|
},
|
|
1676
1740
|
},
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
}
|
|
1741
|
+
},
|
|
1742
|
+
{
|
|
1743
|
+
'wildcard': {
|
|
1744
|
+
'optumId.keyword': {
|
|
1745
|
+
'value': `*${inputData.searchValue}*`,
|
|
1682
1746
|
},
|
|
1683
1747
|
},
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
}
|
|
1748
|
+
},
|
|
1749
|
+
{
|
|
1750
|
+
'wildcard': {
|
|
1751
|
+
'visitorsType.keyword': {
|
|
1752
|
+
'value': `*${inputData.searchValue}*`,
|
|
1689
1753
|
},
|
|
1690
1754
|
},
|
|
1755
|
+
},
|
|
1691
1756
|
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
},
|
|
1757
|
+
{
|
|
1758
|
+
'wildcard': {
|
|
1759
|
+
'auditStatus.keyword': {
|
|
1760
|
+
'value': `*${inputData.searchValue}*`,
|
|
1697
1761
|
},
|
|
1698
1762
|
},
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
}
|
|
1763
|
+
},
|
|
1764
|
+
],
|
|
1765
|
+
'minimum_should_match': 1,
|
|
1766
|
+
};
|
|
1703
1767
|
}
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
let searchQuery={
|
|
1771
|
+
'from': offset,
|
|
1772
|
+
'size': limit,
|
|
1773
|
+
'query': {
|
|
1774
|
+
'bool': search,
|
|
1775
|
+
},
|
|
1776
|
+
'sort': [
|
|
1777
|
+
{ date: { order: 'desc' } },
|
|
1778
|
+
],
|
|
1779
|
+
};
|
|
1704
1780
|
|
|
1705
|
-
|
|
1781
|
+
if ( sortBy && sortBy !== '' ) {
|
|
1782
|
+
searchQuery={
|
|
1706
1783
|
'from': offset,
|
|
1707
1784
|
'size': limit,
|
|
1708
1785
|
'query': {
|
|
1709
1786
|
'bool': search,
|
|
1710
1787
|
},
|
|
1711
1788
|
'sort': [
|
|
1712
|
-
{
|
|
1789
|
+
{ [sortBy]: { order: order === -1 ?'desc':'asc' } },
|
|
1790
|
+
{ '_id': 'asc' },
|
|
1713
1791
|
],
|
|
1714
1792
|
};
|
|
1793
|
+
}
|
|
1715
1794
|
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
},
|
|
1723
|
-
'sort': [
|
|
1724
|
-
{ [sortBy]: { order: order === -1 ?'desc':'asc' } },
|
|
1725
|
-
{ '_id': 'asc' },
|
|
1726
|
-
],
|
|
1727
|
-
};
|
|
1728
|
-
}
|
|
1729
|
-
|
|
1730
|
-
if ( inputData.isExport==true ) {
|
|
1731
|
-
searchQuery={
|
|
1732
|
-
'from': 0,
|
|
1733
|
-
'size': 50000,
|
|
1734
|
-
'query': {
|
|
1735
|
-
'bool': search,
|
|
1736
|
-
},
|
|
1737
|
-
'sort': [
|
|
1738
|
-
{ [sortBy]: { order: order === -1 ?'desc':'asc' } },
|
|
1739
|
-
{ '_id': 'asc' },
|
|
1740
|
-
],
|
|
1741
|
-
};
|
|
1742
|
-
}
|
|
1743
|
-
|
|
1744
|
-
const countQuery = {
|
|
1745
|
-
query: {
|
|
1746
|
-
bool: search,
|
|
1795
|
+
if ( inputData.isExport==true ) {
|
|
1796
|
+
searchQuery={
|
|
1797
|
+
'from': 0,
|
|
1798
|
+
'size': 50000,
|
|
1799
|
+
'query': {
|
|
1800
|
+
'bool': search,
|
|
1747
1801
|
},
|
|
1802
|
+
'sort': [
|
|
1803
|
+
{ [sortBy]: { order: order === -1 ?'desc':'asc' } },
|
|
1804
|
+
{ '_id': 'asc' },
|
|
1805
|
+
],
|
|
1748
1806
|
};
|
|
1807
|
+
}
|
|
1749
1808
|
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
if ( !searchValue || searchValue?.length == 0 ) {
|
|
1756
|
-
return res.sendError( 'No data found', 204 );
|
|
1757
|
-
}
|
|
1758
|
-
if ( inputData.isExport == true ) {
|
|
1759
|
-
const chunkedMappingData = await chunkArray( searchValue, 10 );
|
|
1760
|
-
const promises = chunkedMappingData.map( async ( chunk ) => {
|
|
1761
|
-
const exportData = [];
|
|
1762
|
-
for ( const element of chunk ) {
|
|
1763
|
-
const testDuration = element?._source?.testDuration;
|
|
1764
|
-
const minutes = Math.floor( testDuration / 60 );
|
|
1765
|
-
const seconds = testDuration % 60;
|
|
1766
|
-
const minutes1 =minutes> 1? `${minutes} mins` : `${minutes} min`;
|
|
1767
|
-
const seconds1 = seconds > 1? `${minutes} secs`: seconds == 1? `${minutes} sec` : '';
|
|
1768
|
-
const duration =`${minutes1} ${seconds1}`;
|
|
1769
|
-
let userName = '';
|
|
1770
|
-
if ( element?._source?.userId&&element?._source?.userId!='' ) {
|
|
1771
|
-
userName = await findOneUser( { _id: element?._source?.userId }, { _id: 0, userName: 1 } );
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1774
|
-
let RMName = '';
|
|
1775
|
-
let RMEmail = '';
|
|
1776
|
-
let clusterName='';
|
|
1777
|
-
if ( element?._source?.storeId&&element?._source?.storeId!='' ) {
|
|
1778
|
-
const rmListQuery =[
|
|
1779
|
-
{
|
|
1780
|
-
$match: {
|
|
1781
|
-
$and: [
|
|
1782
|
-
{
|
|
1783
|
-
clientId: { $eq: inputData?.clientId },
|
|
1784
|
-
},
|
|
1785
|
-
{
|
|
1786
|
-
configureType: { $eq: 'user' },
|
|
1787
|
-
},
|
|
1788
|
-
],
|
|
1789
|
-
},
|
|
1790
|
-
},
|
|
1791
|
-
{
|
|
1792
|
-
$unwind: {
|
|
1793
|
-
path: '$userList', preserveNullAndEmptyArrays: true,
|
|
1794
|
-
},
|
|
1795
|
-
},
|
|
1796
|
-
{
|
|
1797
|
-
$group: {
|
|
1798
|
-
_id: null,
|
|
1799
|
-
list: { $addToSet: '$userList.email' },
|
|
1800
|
-
},
|
|
1801
|
-
},
|
|
1802
|
-
{
|
|
1803
|
-
$project: {
|
|
1804
|
-
_id: 0,
|
|
1805
|
-
list: 1,
|
|
1806
|
-
},
|
|
1807
|
-
},
|
|
1808
|
-
];
|
|
1809
|
-
const getRMList = await aggregateEyeTestConfig( rmListQuery );
|
|
1810
|
-
let getCluster = [];
|
|
1811
|
-
if ( getRMList && getRMList?.length > 0 ) {
|
|
1812
|
-
const getRMQuery = [
|
|
1813
|
-
{
|
|
1814
|
-
$unwind: {
|
|
1815
|
-
path: '$Teamlead', preserveNullAndEmptyArrays: true,
|
|
1816
|
-
},
|
|
1817
|
-
},
|
|
1818
|
-
{
|
|
1819
|
-
$match: {
|
|
1820
|
-
$and: [
|
|
1821
|
-
{ 'stores.storeId': { $eq: element?._source?.storeId } },
|
|
1822
|
-
{
|
|
1823
|
-
'Teamlead.email': { $in: getRMList[0].list },
|
|
1824
|
-
},
|
|
1825
|
-
],
|
|
1826
|
-
},
|
|
1827
|
-
},
|
|
1828
|
-
{
|
|
1829
|
-
$group: {
|
|
1830
|
-
_id: null,
|
|
1831
|
-
clusterName: { $addToSet: '$clusterName' },
|
|
1832
|
-
rmList: { $addToSet: '$Teamlead.email' },
|
|
1833
|
-
},
|
|
1834
|
-
},
|
|
1835
|
-
{
|
|
1836
|
-
$project: {
|
|
1837
|
-
_id: 0,
|
|
1838
|
-
clusterName: 1,
|
|
1839
|
-
rmList: 1,
|
|
1840
|
-
},
|
|
1841
|
-
},
|
|
1842
|
-
];
|
|
1843
|
-
getCluster = await aggregateClusters( getRMQuery );
|
|
1844
|
-
}
|
|
1845
|
-
// const getCluster = await findOneClusters( { 'stores.storeId': element?._source?.storeId }, { Teamlead: 1, clusterName: 1 } );
|
|
1846
|
-
RMEmail =( getCluster && getCluster?.[0]?.rmList?.length > 0 )? getCluster?.[0]?.rmList?.toString() : '';
|
|
1847
|
-
clusterName = ( getCluster && getCluster?.[0]?.clusterName?.length > 0 )? getCluster?.[0]?.clusterName?.toString() : '';
|
|
1848
|
-
if ( RMEmail && RMEmail !== '' ) {
|
|
1849
|
-
const temp = await aggregateUser( [
|
|
1850
|
-
{
|
|
1851
|
-
$match: {
|
|
1852
|
-
$and: [
|
|
1853
|
-
{
|
|
1854
|
-
email: { $in: getCluster?.[0]?.rmList },
|
|
1855
|
-
},
|
|
1856
|
-
{
|
|
1857
|
-
isActive: true,
|
|
1858
|
-
},
|
|
1859
|
-
{
|
|
1860
|
-
role: { $eq: 'admin' },
|
|
1861
|
-
},
|
|
1862
|
-
],
|
|
1863
|
-
},
|
|
1864
|
-
},
|
|
1865
|
-
{
|
|
1866
|
-
$group: {
|
|
1867
|
-
_id: null,
|
|
1868
|
-
user: { $addToSet: '$userName' },
|
|
1869
|
-
},
|
|
1870
|
-
},
|
|
1871
|
-
{
|
|
1872
|
-
$project: {
|
|
1873
|
-
_id: 0,
|
|
1874
|
-
user: 1,
|
|
1875
|
-
},
|
|
1876
|
-
},
|
|
1877
|
-
] );
|
|
1878
|
-
if ( temp && temp?.[0]?.user?.length >0 ) {
|
|
1879
|
-
RMName = temp?.[0]?.user?.toString( '' );
|
|
1880
|
-
}
|
|
1881
|
-
logger.info( { RMEmail: RMEmail } );
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
if ( element?._source?.type == 'physical' ) {
|
|
1885
|
-
exportData.push( {
|
|
1886
|
-
'Date': dayjs( element?._source?.date ).format( 'D MMM, YYYY' ),
|
|
1887
|
-
'Audited Date': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?dayjs( element?._source?.updatedAt ).format( 'D MMM, YYYY' ): 'NA',
|
|
1888
|
-
...( req?.user?.role === 'superadmin' && { 'RM Name': RMName } ),
|
|
1889
|
-
...( req?.user?.role !== 'user' && { 'Cluster Name': clusterName } ),
|
|
1890
|
-
'Store Name': element?._source?.storeName,
|
|
1891
|
-
'Store ID': element?._source?.storeId || 'Un Assigned',
|
|
1892
|
-
'Store Name': element?._source?.storeName ||'Un Assigned',
|
|
1893
|
-
'Optom ID': element?._source?.optumId,
|
|
1894
|
-
'Queue ID': element?._source?.queueId,
|
|
1895
|
-
'Tango Score': `${element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 ): 0} %`,
|
|
1896
|
-
'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
|
|
1897
|
-
'Human Audited Score': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?`${element?._source?.totalSteps>0 ? Math.round( ( element?._source?.auditedSteps/ element?._source?.totalSteps )*100 ): 0} %`:'NA',
|
|
1898
|
-
'Steps Covered By Human': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?element?._source?.auditedSteps :'NA',
|
|
1899
|
-
'Trust Score': element?._source?.trustScore == null || element?._source?.trustScore ==undefined ? 'NA' : `${element?._source?.trustScore} %`,
|
|
1900
|
-
'Visitor Type': element?._source?.visitorsType,
|
|
1901
|
-
'Test Duration': duration || '',
|
|
1902
|
-
'Eye Test Status': element?._source?.comment == 'Possible Fake Video' ? 'Fake':'Genuine',
|
|
1903
|
-
'Comments ': element._source?.subComment || '',
|
|
1904
|
-
'Audit Status': element?._source?.auditStatus || '',
|
|
1905
|
-
'Audited By': userName?.userName || '',
|
|
1906
|
-
|
|
1907
|
-
} );
|
|
1908
|
-
} else {
|
|
1909
|
-
exportData.push( {
|
|
1910
|
-
'Date': dayjs( element?._source?.date ).format( 'D MMM, YYYY' ),
|
|
1911
|
-
'Audited Date': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?dayjs( element?._source?.updatedAt ).format( 'D MMM, YYYY' ): 'NA',
|
|
1912
|
-
...( req?.user?.role === 'superadmin' && { 'RM Name': RMName } ),
|
|
1913
|
-
...( req?.user?.role !== 'user' && { 'Cluster Name': clusterName } ),
|
|
1914
|
-
'Store Name': element?._source?.storeName,
|
|
1915
|
-
'Store Name': element?._source?.storeName,
|
|
1916
|
-
'Store ID': element?._source?.storeId || 'Un Assigned',
|
|
1917
|
-
'Store Name': element?._source?.storeName ||'Un Assigned',
|
|
1918
|
-
'Engagement ID': element?._source?.engagementId,
|
|
1919
|
-
'Tango Score': `${element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 ): 0} %`,
|
|
1920
|
-
'Human Audited Score': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?`${element?._source?.totalSteps>0 ? Math.round( ( element?._source?.auditedSteps/ element?._source?.totalSteps )*100 ): 0} %`:'NA',
|
|
1921
|
-
'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
|
|
1922
|
-
'Steps Covered By Human': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?element?._source?.auditedSteps :'NA',
|
|
1923
|
-
'Trust Score': element?._source?.trustScore == null || element?._source?.trustScore ==undefined ? 'NA' : `${element?._source?.trustScore} %`,
|
|
1924
|
-
'Test Duration': duration || '',
|
|
1925
|
-
'Audit Status': element?._source?.auditStatus || '',
|
|
1926
|
-
'Audited By': userName?.userName || '',
|
|
1809
|
+
const countQuery = {
|
|
1810
|
+
query: {
|
|
1811
|
+
bool: search,
|
|
1812
|
+
},
|
|
1813
|
+
};
|
|
1927
1814
|
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1815
|
+
const result = await getOpenSearchData( openSearch.EyeTestInput, searchQuery );
|
|
1816
|
+
const getCount = inputData.isExport==true? null:await getOpenSearchCount( openSearch.EyeTestInput, countQuery );
|
|
1817
|
+
const count =inputData.isExport==true?null: getCount?.body?.count;
|
|
1818
|
+
const searchValue = result?.body?.hits?.hits;
|
|
1819
|
+
const temp =[];
|
|
1820
|
+
if ( !searchValue || searchValue?.length == 0 ) {
|
|
1821
|
+
return res.sendError( 'No data found', 204 );
|
|
1822
|
+
}
|
|
1823
|
+
if ( inputData.isExport == true ) {
|
|
1824
|
+
const chunkedMappingData = await chunkArray( searchValue, 10 );
|
|
1825
|
+
const promises = chunkedMappingData.map( async ( chunk ) => {
|
|
1826
|
+
const exportData = [];
|
|
1827
|
+
for ( const element of chunk ) {
|
|
1828
|
+
const testDuration = element?._source?.testDuration;
|
|
1829
|
+
const minutes = Math.floor( testDuration / 60 );
|
|
1830
|
+
const seconds = testDuration % 60;
|
|
1831
|
+
const minutes1 =minutes> 1? `${minutes} mins` : `${minutes} min`;
|
|
1832
|
+
const seconds1 = seconds > 1? `${minutes} secs`: seconds == 1? `${minutes} sec` : '';
|
|
1833
|
+
const duration =`${minutes1} ${seconds1}`;
|
|
1834
|
+
let userName = '';
|
|
1835
|
+
if ( element?._source?.userId&&element?._source?.userId!='' ) {
|
|
1836
|
+
userName = await findOneUser( { _id: element?._source?.userId }, { _id: 0, userName: 1 } );
|
|
1944
1837
|
}
|
|
1838
|
+
|
|
1945
1839
|
let RMName = '';
|
|
1946
1840
|
let RMEmail = '';
|
|
1947
1841
|
let clusterName='';
|
|
1948
|
-
if (
|
|
1842
|
+
if ( element?._source?.storeId&&element?._source?.storeId!='' ) {
|
|
1949
1843
|
const rmListQuery =[
|
|
1950
1844
|
{
|
|
1951
1845
|
$match: {
|
|
@@ -1989,7 +1883,7 @@ export async function summaryList( req, res ) {
|
|
|
1989
1883
|
{
|
|
1990
1884
|
$match: {
|
|
1991
1885
|
$and: [
|
|
1992
|
-
{ 'stores.storeId': { $eq:
|
|
1886
|
+
{ 'stores.storeId': { $eq: element?._source?.storeId } },
|
|
1993
1887
|
{
|
|
1994
1888
|
'Teamlead.email': { $in: getRMList[0].list },
|
|
1995
1889
|
},
|
|
@@ -2016,14 +1910,13 @@ export async function summaryList( req, res ) {
|
|
|
2016
1910
|
// const getCluster = await findOneClusters( { 'stores.storeId': element?._source?.storeId }, { Teamlead: 1, clusterName: 1 } );
|
|
2017
1911
|
RMEmail =( getCluster && getCluster?.[0]?.rmList?.length > 0 )? getCluster?.[0]?.rmList?.toString() : '';
|
|
2018
1912
|
clusterName = ( getCluster && getCluster?.[0]?.clusterName?.length > 0 )? getCluster?.[0]?.clusterName?.toString() : '';
|
|
2019
|
-
|
|
2020
1913
|
if ( RMEmail && RMEmail !== '' ) {
|
|
2021
1914
|
const temp = await aggregateUser( [
|
|
2022
1915
|
{
|
|
2023
1916
|
$match: {
|
|
2024
1917
|
$and: [
|
|
2025
1918
|
{
|
|
2026
|
-
email: { $in: getCluster[0]?.rmList },
|
|
1919
|
+
email: { $in: getCluster?.[0]?.rmList },
|
|
2027
1920
|
},
|
|
2028
1921
|
{
|
|
2029
1922
|
isActive: true,
|
|
@@ -2050,30 +1943,200 @@ export async function summaryList( req, res ) {
|
|
|
2050
1943
|
if ( temp && temp?.[0]?.user?.length >0 ) {
|
|
2051
1944
|
RMName = temp?.[0]?.user?.toString( '' );
|
|
2052
1945
|
}
|
|
1946
|
+
logger.info( { RMEmail: RMEmail } );
|
|
2053
1947
|
}
|
|
2054
1948
|
}
|
|
1949
|
+
if ( element?._source?.type == 'physical' ) {
|
|
1950
|
+
exportData.push( {
|
|
1951
|
+
'Date': dayjs( element?._source?.date ).format( 'D MMM, YYYY' ),
|
|
1952
|
+
'Audited Date': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?dayjs( element?._source?.updatedAt ).format( 'D MMM, YYYY' ): 'NA',
|
|
1953
|
+
...( req?.user?.role === 'superadmin' && { 'RM Name': RMName } ),
|
|
1954
|
+
...( req?.user?.role !== 'user' && { 'Cluster Name': clusterName } ),
|
|
1955
|
+
'Store Name': element?._source?.storeName,
|
|
1956
|
+
'Store ID': element?._source?.storeId || 'Un Assigned',
|
|
1957
|
+
'Store Name': element?._source?.storeName ||'Un Assigned',
|
|
1958
|
+
'Optom ID': element?._source?.optumId,
|
|
1959
|
+
'Queue ID': element?._source?.queueId,
|
|
1960
|
+
'Tango Score': `${element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 ): 0} %`,
|
|
1961
|
+
'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
|
|
1962
|
+
'Human Audited Score': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?`${element?._source?.totalSteps>0 ? Math.round( ( element?._source?.auditedSteps/ element?._source?.totalSteps )*100 ): 0} %`:'NA',
|
|
1963
|
+
'Steps Covered By Human': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?element?._source?.auditedSteps :'NA',
|
|
1964
|
+
'Trust Score': element?._source?.trustScore == null || element?._source?.trustScore ==undefined ? 'NA' : `${element?._source?.trustScore} %`,
|
|
1965
|
+
'Visitor Type': element?._source?.visitorsType,
|
|
1966
|
+
'Test Duration': duration || '',
|
|
1967
|
+
'Eye Test Status': element?._source?.comment == 'Possible Fake Video' ? 'Fake':'Genuine',
|
|
1968
|
+
'Comments ': element._source?.subComment || '',
|
|
1969
|
+
'Audit Status': element?._source?.auditStatus || '',
|
|
1970
|
+
'Audited By': userName?.userName || '',
|
|
2055
1971
|
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
1972
|
+
} );
|
|
1973
|
+
} else {
|
|
1974
|
+
exportData.push( {
|
|
1975
|
+
'Date': dayjs( element?._source?.date ).format( 'D MMM, YYYY' ),
|
|
1976
|
+
'Audited Date': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?dayjs( element?._source?.updatedAt ).format( 'D MMM, YYYY' ): 'NA',
|
|
1977
|
+
...( req?.user?.role === 'superadmin' && { 'RM Name': RMName } ),
|
|
1978
|
+
...( req?.user?.role !== 'user' && { 'Cluster Name': clusterName } ),
|
|
1979
|
+
'Store Name': element?._source?.storeName,
|
|
1980
|
+
'Store Name': element?._source?.storeName,
|
|
1981
|
+
'Store ID': element?._source?.storeId || 'Un Assigned',
|
|
1982
|
+
'Store Name': element?._source?.storeName ||'Un Assigned',
|
|
1983
|
+
'Engagement ID': element?._source?.engagementId,
|
|
1984
|
+
'Tango Score': `${element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 ): 0} %`,
|
|
1985
|
+
'Human Audited Score': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?`${element?._source?.totalSteps>0 ? Math.round( ( element?._source?.auditedSteps/ element?._source?.totalSteps )*100 ): 0} %`:'NA',
|
|
1986
|
+
'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
|
|
1987
|
+
'Steps Covered By Human': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?element?._source?.auditedSteps :'NA',
|
|
1988
|
+
'Trust Score': element?._source?.trustScore == null || element?._source?.trustScore ==undefined ? 'NA' : `${element?._source?.trustScore} %`,
|
|
1989
|
+
'Test Duration': duration || '',
|
|
1990
|
+
'Audit Status': element?._source?.auditStatus || '',
|
|
1991
|
+
'Audited By': userName?.userName || '',
|
|
1992
|
+
|
|
1993
|
+
} );
|
|
1994
|
+
}
|
|
2072
1995
|
}
|
|
2073
|
-
|
|
1996
|
+
return exportData;
|
|
1997
|
+
} );
|
|
1998
|
+
const mappedArrays = await Promise.all( promises );
|
|
1999
|
+
const result = mappedArrays.flat();
|
|
2000
|
+
await download( result, res );
|
|
2001
|
+
return;
|
|
2002
|
+
} else {
|
|
2003
|
+
for ( const [ i, item ] of searchValue.entries() ) {
|
|
2004
|
+
temp.push( item?._source );
|
|
2005
|
+
let userName='';
|
|
2006
|
+
if ( item?._source?.userId&&item?._source?.userId!='' ) {
|
|
2007
|
+
userName = await findOneUser( { _id: item?._source?.userId }, { _id: 0, userName: 1 } );
|
|
2008
|
+
}
|
|
2009
|
+
let RMName = '';
|
|
2010
|
+
let RMEmail = '';
|
|
2011
|
+
let clusterName='';
|
|
2012
|
+
if ( item?._source?.storeId&&item?._source?.storeId!='' ) {
|
|
2013
|
+
const rmListQuery =[
|
|
2014
|
+
{
|
|
2015
|
+
$match: {
|
|
2016
|
+
$and: [
|
|
2017
|
+
{
|
|
2018
|
+
clientId: { $eq: inputData?.clientId },
|
|
2019
|
+
},
|
|
2020
|
+
{
|
|
2021
|
+
configureType: { $eq: 'user' },
|
|
2022
|
+
},
|
|
2023
|
+
],
|
|
2024
|
+
},
|
|
2025
|
+
},
|
|
2026
|
+
{
|
|
2027
|
+
$unwind: {
|
|
2028
|
+
path: '$userList', preserveNullAndEmptyArrays: true,
|
|
2029
|
+
},
|
|
2030
|
+
},
|
|
2031
|
+
{
|
|
2032
|
+
$group: {
|
|
2033
|
+
_id: null,
|
|
2034
|
+
list: { $addToSet: '$userList.email' },
|
|
2035
|
+
},
|
|
2036
|
+
},
|
|
2037
|
+
{
|
|
2038
|
+
$project: {
|
|
2039
|
+
_id: 0,
|
|
2040
|
+
list: 1,
|
|
2041
|
+
},
|
|
2042
|
+
},
|
|
2043
|
+
];
|
|
2044
|
+
const getRMList = await aggregateEyeTestConfig( rmListQuery );
|
|
2045
|
+
let getCluster = [];
|
|
2046
|
+
if ( getRMList && getRMList?.length > 0 ) {
|
|
2047
|
+
const getRMQuery = [
|
|
2048
|
+
{
|
|
2049
|
+
$unwind: {
|
|
2050
|
+
path: '$Teamlead', preserveNullAndEmptyArrays: true,
|
|
2051
|
+
},
|
|
2052
|
+
},
|
|
2053
|
+
{
|
|
2054
|
+
$match: {
|
|
2055
|
+
$and: [
|
|
2056
|
+
{ 'stores.storeId': { $eq: item?._source?.storeId } },
|
|
2057
|
+
{
|
|
2058
|
+
'Teamlead.email': { $in: getRMList[0].list },
|
|
2059
|
+
},
|
|
2060
|
+
],
|
|
2061
|
+
},
|
|
2062
|
+
},
|
|
2063
|
+
{
|
|
2064
|
+
$group: {
|
|
2065
|
+
_id: null,
|
|
2066
|
+
clusterName: { $addToSet: '$clusterName' },
|
|
2067
|
+
rmList: { $addToSet: '$Teamlead.email' },
|
|
2068
|
+
},
|
|
2069
|
+
},
|
|
2070
|
+
{
|
|
2071
|
+
$project: {
|
|
2072
|
+
_id: 0,
|
|
2073
|
+
clusterName: 1,
|
|
2074
|
+
rmList: 1,
|
|
2075
|
+
},
|
|
2076
|
+
},
|
|
2077
|
+
];
|
|
2078
|
+
getCluster = await aggregateClusters( getRMQuery );
|
|
2079
|
+
}
|
|
2080
|
+
// const getCluster = await findOneClusters( { 'stores.storeId': element?._source?.storeId }, { Teamlead: 1, clusterName: 1 } );
|
|
2081
|
+
RMEmail =( getCluster && getCluster?.[0]?.rmList?.length > 0 )? getCluster?.[0]?.rmList?.toString() : '';
|
|
2082
|
+
clusterName = ( getCluster && getCluster?.[0]?.clusterName?.length > 0 )? getCluster?.[0]?.clusterName?.toString() : '';
|
|
2074
2083
|
|
|
2075
|
-
|
|
2084
|
+
if ( RMEmail && RMEmail !== '' ) {
|
|
2085
|
+
const temp = await aggregateUser( [
|
|
2086
|
+
{
|
|
2087
|
+
$match: {
|
|
2088
|
+
$and: [
|
|
2089
|
+
{
|
|
2090
|
+
email: { $in: getCluster[0]?.rmList },
|
|
2091
|
+
},
|
|
2092
|
+
{
|
|
2093
|
+
isActive: true,
|
|
2094
|
+
},
|
|
2095
|
+
{
|
|
2096
|
+
role: { $eq: 'admin' },
|
|
2097
|
+
},
|
|
2098
|
+
],
|
|
2099
|
+
},
|
|
2100
|
+
},
|
|
2101
|
+
{
|
|
2102
|
+
$group: {
|
|
2103
|
+
_id: null,
|
|
2104
|
+
user: { $addToSet: '$userName' },
|
|
2105
|
+
},
|
|
2106
|
+
},
|
|
2107
|
+
{
|
|
2108
|
+
$project: {
|
|
2109
|
+
_id: 0,
|
|
2110
|
+
user: 1,
|
|
2111
|
+
},
|
|
2112
|
+
},
|
|
2113
|
+
] );
|
|
2114
|
+
if ( temp && temp?.[0]?.user?.length >0 ) {
|
|
2115
|
+
RMName = temp?.[0]?.user?.toString( '' );
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
const testDuration = item?._source?.testDuration;
|
|
2121
|
+
const minutes = Math.floor( testDuration / 60 );
|
|
2122
|
+
const seconds = testDuration % 60;
|
|
2123
|
+
temp[i].complianceScore = `${item?._source?.totalSteps>0 ? Math.round( ( item?._source?.coveredStepsAI/ item?._source?.totalSteps )*100 ): 0} %`;
|
|
2124
|
+
temp[i].humanComplianceScore = [ 'Re-Audited', 'Audited' ].includes( item?._source?.auditStatus )?`${item?._source?.totalSteps>0 ? Math.round( ( item?._source?.auditedSteps/ item?._source?.totalSteps )*100 ): 0} %`:'NA';
|
|
2125
|
+
temp[i].min = minutes;
|
|
2126
|
+
temp[i].sec = seconds;
|
|
2127
|
+
temp[i].auditedBy = userName?.userName || '';
|
|
2128
|
+
temp[i].date = dayjs( item?._source?.date ).format( 'D MMM, YYYY' );
|
|
2129
|
+
temp[i].auditedDate = [ 'Re-Audited', 'Audited' ].includes( item?._source?.auditStatus )?dayjs( item?._source?.updatedAt ).format( 'D MMM, YYYY' ): 'NA';
|
|
2130
|
+
temp[i].RMName = RMName;
|
|
2131
|
+
temp[i].clusterName =clusterName;
|
|
2132
|
+
temp[i].RMEmail =RMEmail;
|
|
2133
|
+
const trustScore = temp[i].trustScore;
|
|
2134
|
+
temp[i].trustScore = ( trustScore == null || trustScore == undefined ) ? 'NA' :`${trustScore + ' %'}`;
|
|
2135
|
+
temp[i]._id = item?._id;
|
|
2136
|
+
}
|
|
2076
2137
|
}
|
|
2138
|
+
|
|
2139
|
+
return res.sendSuccess( { result: temp, count: count } );
|
|
2077
2140
|
} catch ( error ) {
|
|
2078
2141
|
const err = error.message || 'Internal Server Error';
|
|
2079
2142
|
logger.error( { message: error, data: req.body, function: 'eyetestAudit-controller-summaryList' } );
|
|
@@ -2085,7 +2148,7 @@ export async function summaryCard( req, res ) {
|
|
|
2085
2148
|
try {
|
|
2086
2149
|
const inputData = req.body;
|
|
2087
2150
|
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
2088
|
-
|
|
2151
|
+
|
|
2089
2152
|
let filter =[
|
|
2090
2153
|
{
|
|
2091
2154
|
'range': {
|
|
@@ -2113,6 +2176,15 @@ export async function summaryCard( req, res ) {
|
|
|
2113
2176
|
},
|
|
2114
2177
|
} );
|
|
2115
2178
|
}
|
|
2179
|
+
|
|
2180
|
+
if ( inputData.nearAddition && inputData.nearAddition!='' && inputData.type ==='physical' ) {
|
|
2181
|
+
filter.push( {
|
|
2182
|
+
'term': {
|
|
2183
|
+
'nearAddition.keyword': inputData.nearAddition,
|
|
2184
|
+
},
|
|
2185
|
+
|
|
2186
|
+
} );
|
|
2187
|
+
}
|
|
2116
2188
|
let mustQuery = [
|
|
2117
2189
|
...filter,
|
|
2118
2190
|
];
|
|
@@ -2381,7 +2453,7 @@ export async function emailAlertLog( req, res ) {
|
|
|
2381
2453
|
inputData.clientId = req.user.userType == 'tango'? inputData?.clientId : req?.user?.clientId;
|
|
2382
2454
|
// get openserach name form the env file
|
|
2383
2455
|
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
2384
|
-
|
|
2456
|
+
const sortBy = inputData?.sortBy ? [ 'complianceScore', 'humanScore', 'trustScore', 'updatedAt', 'createdAt' ].includes( inputData.sortBy ) ? inputData.sortBy :`${inputData.sortBy}.keyword` : 'RMName.keyword';
|
|
2385
2457
|
|
|
2386
2458
|
let filter =[
|
|
2387
2459
|
{
|
|
@@ -2394,7 +2466,7 @@ export async function emailAlertLog( req, res ) {
|
|
|
2394
2466
|
},
|
|
2395
2467
|
];
|
|
2396
2468
|
let sort =[
|
|
2397
|
-
{ [
|
|
2469
|
+
{ [sortBy]: { order: inputData.sortOrder === 1 ? 'asc' : 'desc' } },
|
|
2398
2470
|
];
|
|
2399
2471
|
if ( inputData.RmList && inputData.RmList?.lenght > 0 ) {
|
|
2400
2472
|
filter.push( {
|
|
@@ -2411,19 +2483,86 @@ export async function emailAlertLog( req, res ) {
|
|
|
2411
2483
|
},
|
|
2412
2484
|
} );
|
|
2413
2485
|
}
|
|
2486
|
+
let search = {
|
|
2487
|
+
must: filter,
|
|
2488
|
+
};
|
|
2489
|
+
if ( inputData.searchValue && inputData.searchValue !== '' ) {
|
|
2490
|
+
search ={
|
|
2491
|
+
'must': filter,
|
|
2492
|
+
'should': [
|
|
2493
|
+
{
|
|
2494
|
+
'wildcard': {
|
|
2495
|
+
'RMEmail.keyword': {
|
|
2496
|
+
'value': `*${inputData.searchValue}*`,
|
|
2497
|
+
},
|
|
2498
|
+
},
|
|
2499
|
+
},
|
|
2500
|
+
{
|
|
2501
|
+
'wildcard': {
|
|
2502
|
+
'RMName.keyword': {
|
|
2503
|
+
'value': `*${inputData.searchValue}*`,
|
|
2504
|
+
},
|
|
2505
|
+
},
|
|
2506
|
+
},
|
|
2507
|
+
{
|
|
2508
|
+
'wildcard': {
|
|
2509
|
+
'cluster.keyword': {
|
|
2510
|
+
'value': `*${inputData.searchValue}*`,
|
|
2511
|
+
},
|
|
2512
|
+
},
|
|
2513
|
+
},
|
|
2514
|
+
{
|
|
2515
|
+
'wildcard': {
|
|
2516
|
+
'optumId.keyword': {
|
|
2517
|
+
'value': `*${inputData.searchValue}*`,
|
|
2518
|
+
},
|
|
2519
|
+
},
|
|
2520
|
+
},
|
|
2521
|
+
{
|
|
2522
|
+
'wildcard': {
|
|
2523
|
+
'queueId.keyword': {
|
|
2524
|
+
'value': `*${inputData.searchValue}*`,
|
|
2525
|
+
},
|
|
2526
|
+
},
|
|
2527
|
+
},
|
|
2528
|
+
{
|
|
2529
|
+
'wildcard': {
|
|
2530
|
+
'storeName.keyword': {
|
|
2531
|
+
'value': `*${inputData.searchValue}*`,
|
|
2532
|
+
},
|
|
2533
|
+
},
|
|
2534
|
+
},
|
|
2535
|
+
{
|
|
2536
|
+
'wildcard': {
|
|
2537
|
+
'auditedBy.keyword': {
|
|
2538
|
+
'value': `*${inputData.searchValue}*`,
|
|
2539
|
+
},
|
|
2540
|
+
},
|
|
2541
|
+
},
|
|
2542
|
+
{
|
|
2543
|
+
'wildcard': {
|
|
2544
|
+
'optomEmailId.keyword': {
|
|
2545
|
+
'value': `*${inputData.searchValue}*`,
|
|
2546
|
+
},
|
|
2547
|
+
},
|
|
2548
|
+
},
|
|
2549
|
+
],
|
|
2550
|
+
'minimum_should_match': 1,
|
|
2551
|
+
};
|
|
2552
|
+
}
|
|
2414
2553
|
const getQuery = {
|
|
2415
2554
|
'size': inputData.isExport == true? 50000 : inputData?.limit || 10,
|
|
2416
2555
|
'from': offset || 0,
|
|
2417
2556
|
'query': {
|
|
2418
|
-
'bool':
|
|
2419
|
-
'must': filter,
|
|
2420
|
-
},
|
|
2557
|
+
'bool': search,
|
|
2421
2558
|
},
|
|
2422
2559
|
'sort': sort,
|
|
2423
2560
|
};
|
|
2424
2561
|
|
|
2562
|
+
|
|
2425
2563
|
// get query result from the open saerch
|
|
2426
2564
|
const getData= await getOpenSearchData( openSearch.eyeTestEmailAlert, getQuery );
|
|
2565
|
+
const count = getData?.body?.hits?.total?.value;
|
|
2427
2566
|
// throw error if got null or empty array
|
|
2428
2567
|
if ( !getData || getData?.body?.hits?.hits?.length == 0 ) {
|
|
2429
2568
|
return res.sendError( 'No records found', 204 );
|
|
@@ -2472,7 +2611,7 @@ export async function emailAlertLog( req, res ) {
|
|
|
2472
2611
|
|
|
2473
2612
|
|
|
2474
2613
|
logger.info( { inputData: inputData, getData: response } );
|
|
2475
|
-
return res.sendSuccess( { result: response, count:
|
|
2614
|
+
return res.sendSuccess( { result: response, count: count } );
|
|
2476
2615
|
} catch ( error ) {
|
|
2477
2616
|
const err = error.message || 'Internal Server Error';
|
|
2478
2617
|
logger.error( { message: error, data: req.body, function: 'eyetestAudit-controller-emailAlertLog' } );
|
|
@@ -2632,10 +2771,6 @@ export async function getEmailConfig( req, res ) {
|
|
|
2632
2771
|
configureType: 'email',
|
|
2633
2772
|
};
|
|
2634
2773
|
const getOne = await findOneEyeTestConfig( query, { complianceThreshold: 1, _id: 1 } );
|
|
2635
|
-
logger.info( { getOne: getOne, message: 'getEmailConfig' } );
|
|
2636
|
-
// if ( !getOne?.complianceThreshold ) {
|
|
2637
|
-
// return res.sendError( 'No data found', 204 );
|
|
2638
|
-
// }
|
|
2639
2774
|
if ( !getOne ) {
|
|
2640
2775
|
return res.sendError( ' No data found', 204 );
|
|
2641
2776
|
}
|
|
@@ -64,6 +64,7 @@ export const saveSchema = joi.object( {
|
|
|
64
64
|
spokenLanguage: joi.string().optional(),
|
|
65
65
|
cluster: joi.string().required().allow( '' ),
|
|
66
66
|
RMEmail: joi.string().required().allow( '' ),
|
|
67
|
+
isReSend: joi.boolean().optional(),
|
|
67
68
|
} );
|
|
68
69
|
|
|
69
70
|
export const saveValid = {
|
|
@@ -156,7 +157,7 @@ export const summaryListSchema = joi.object( {
|
|
|
156
157
|
).optional(),
|
|
157
158
|
storeId: joi.array().items( joi.string().required() ).required(),
|
|
158
159
|
complianceScore: joi.array().items( joi.string().required() ).optional(),
|
|
159
|
-
nearAddition: joi.string().optional().allow( '' ),
|
|
160
|
+
nearAddition: joi.string().optional().allow( '', 'true', 'false' ),
|
|
160
161
|
isExport: joi.boolean().optional(),
|
|
161
162
|
searchValue: joi.string().optional().allow( '' ),
|
|
162
163
|
sortBy: joi.string().optional(),
|
|
@@ -234,7 +235,7 @@ export const summaryCardSchema = joi.object( {
|
|
|
234
235
|
).optional(),
|
|
235
236
|
storeId: joi.array().items( joi.string().required() ).required(),
|
|
236
237
|
complianceScore: joi.array().items( joi.string().required() ).optional(),
|
|
237
|
-
nearAddition: joi.string().optional().allow( '' ),
|
|
238
|
+
nearAddition: joi.string().optional().allow( '', 'true', 'false' ),
|
|
238
239
|
category: joi.string().optional() .valid( 'fake', 'genuine' ),
|
|
239
240
|
} );
|
|
240
241
|
|
|
@@ -279,12 +280,8 @@ export const emailAlertLogSchema = joi.object( {
|
|
|
279
280
|
|
|
280
281
|
return value;
|
|
281
282
|
} ),
|
|
282
|
-
type: joi.string().required().messages( {
|
|
283
|
-
'any.required': 'Type is required',
|
|
284
|
-
'string.empty': 'Type cannot be empty',
|
|
285
|
-
} ),
|
|
286
283
|
RMList: joi.array().items(
|
|
287
|
-
joi.string().
|
|
284
|
+
joi.string().required(),
|
|
288
285
|
).optional(),
|
|
289
286
|
clientId: joi.string().when( '$userType', {
|
|
290
287
|
is: 'tango',
|
|
@@ -294,7 +291,7 @@ export const emailAlertLogSchema = joi.object( {
|
|
|
294
291
|
} ),
|
|
295
292
|
otherwise: joi.optional(),
|
|
296
293
|
} ),
|
|
297
|
-
cluster: joi.array().items( joi.string().required() ).
|
|
294
|
+
cluster: joi.array().items( joi.string().required() ).optional(),
|
|
298
295
|
isExport: joi.boolean().optional(),
|
|
299
296
|
searchValue: joi.string().optional().allow( '' ),
|
|
300
297
|
sortBy: joi.string().optional(),
|
|
@@ -413,6 +410,7 @@ export const getEmailConfigSchema = joi.object( {
|
|
|
413
410
|
} ),
|
|
414
411
|
otherwise: joi.optional(),
|
|
415
412
|
} ),
|
|
413
|
+
|
|
416
414
|
} );
|
|
417
415
|
|
|
418
416
|
export const getEmailConfigValid = {
|
|
@@ -3,14 +3,14 @@ import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
|
3
3
|
import { accessVerification } from 'tango-app-api-middleware';
|
|
4
4
|
import { cancelValid, clusterListValid, emailAlertLogValid, getEmailConfigValid, getFileHistoryValid, getFileValid, getListValid, getUserConfigValid, rmListValid, saveValid, summaryCardValid, summaryListValid, updateEmailConfigValid, updateUserConfigValid, userAuditedDataValid, viewFileValid } from '../dtos/eyeTestAudit.dtos.js';
|
|
5
5
|
import { addUserConfig, cancel, clusterList, emailAlertLog, getEmailConfig, getFile, getFileHistory, getList, getUserConfig, rmList, save, summaryCard, summaryList, updateEmailConfig, updateEmailConfig1, updateUserConfig, userAuditedData, viewFile } from '../controllers/eyeTestAudit.controllers.js';
|
|
6
|
-
import { isSuperAdmin, roleValidation } from '../validation/eyeTest.validation.js';
|
|
6
|
+
import { isSuperAdmin, roleValidation, sendAlert } from '../validation/eyeTest.validation.js';
|
|
7
7
|
|
|
8
8
|
export const eyeTestAuditRouter = Router();
|
|
9
9
|
|
|
10
10
|
eyeTestAuditRouter.post( '/get-list', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( getListValid ), getList );
|
|
11
11
|
eyeTestAuditRouter.get( '/view-file/:id', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( viewFileValid ), viewFile );
|
|
12
12
|
eyeTestAuditRouter.get( '/get-file/:id', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( getFileValid ), getFile );
|
|
13
|
-
eyeTestAuditRouter.post( '/save', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( saveValid ), save );
|
|
13
|
+
eyeTestAuditRouter.post( '/save', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( saveValid ), sendAlert, save );
|
|
14
14
|
eyeTestAuditRouter.post( '/cancel', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( cancelValid ), cancel );
|
|
15
15
|
eyeTestAuditRouter.get( '/get-file-history/:id/:type', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( getFileHistoryValid ), getFileHistory );
|
|
16
16
|
eyeTestAuditRouter.get( '/user-audited-data/:id', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( userAuditedDataValid ), userAuditedData );
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { logger } from 'tango-app-api-middleware';
|
|
1
|
+
import { getOpenSearchById, logger } from 'tango-app-api-middleware';
|
|
2
2
|
|
|
3
3
|
export async function roleValidation( req, res, next ) {
|
|
4
4
|
try {
|
|
@@ -39,3 +39,26 @@ export async function isSuperAdmin( req, res, next ) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
export async function sendAlert( req, res, next ) {
|
|
43
|
+
try {
|
|
44
|
+
const inputData = req.body;
|
|
45
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
46
|
+
if ( inputData.auditStatus == 'ReAudited' && inputData.type == 'physical' && inputData?.isReSend == undefined ) {
|
|
47
|
+
const getOne = await getOpenSearchById( openSearch.EyeTestInput, inputData.id );
|
|
48
|
+
const id = `${inputData.id}_${getOne?.body?._source?.optumId}_${inputData.fileId}`;
|
|
49
|
+
const getId = await getOpenSearchById( openSearch.eyeTestEmailAlert, id );
|
|
50
|
+
const inputUpdatedData = getId?.body;
|
|
51
|
+
if ( inputUpdatedData ) {
|
|
52
|
+
return res.sendError( 'Do you want resend mail?', 202 );
|
|
53
|
+
} else {
|
|
54
|
+
return next();
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
return next();
|
|
58
|
+
}
|
|
59
|
+
} catch ( error ) {
|
|
60
|
+
const err = error.message;
|
|
61
|
+
return res.sendError( err, 500 );
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|