tango-app-api-audit 3.5.32 → 3.5.35
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.5.
|
|
3
|
+
"version": "3.5.35",
|
|
4
4
|
"description": "audit & audit metrics apis",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"mongodb": "^6.7.0",
|
|
27
27
|
"nodemon": "^3.1.3",
|
|
28
28
|
"swagger-ui-express": "^5.0.1",
|
|
29
|
-
"tango-api-schema": "^2.3.
|
|
29
|
+
"tango-api-schema": "^2.3.28",
|
|
30
30
|
"tango-app-api-middleware": "^3.4.4",
|
|
31
31
|
"winston": "^3.13.0",
|
|
32
32
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -190,7 +190,7 @@ export async function getList( req, res ) {
|
|
|
190
190
|
if ( inputData.isExport==true ) {
|
|
191
191
|
searchQuery={
|
|
192
192
|
'from': 0,
|
|
193
|
-
'size':
|
|
193
|
+
'size': 50000,
|
|
194
194
|
'query': {
|
|
195
195
|
'bool': search,
|
|
196
196
|
},
|
|
@@ -206,12 +206,12 @@ export async function getList( req, res ) {
|
|
|
206
206
|
bool: search,
|
|
207
207
|
},
|
|
208
208
|
};
|
|
209
|
-
const result = offset >=
|
|
209
|
+
const result = offset >= 50000 ? await fetchDeepPage( openSearch.EyeTestInput, search, limit, offset, sortBy, order, inputData?.searchAfter ) : await getOpenSearchData( openSearch.EyeTestInput, searchQuery );
|
|
210
210
|
logger.info( { result: result } );
|
|
211
211
|
const getCount = inputData.isExport==true? null:await getOpenSearchCount( openSearch.EyeTestInput, countQuery );
|
|
212
212
|
const count =inputData.isExport==true?null: getCount?.body?.count;
|
|
213
213
|
|
|
214
|
-
const searchValue = offset >=
|
|
214
|
+
const searchValue = offset >= 50000 ? result : result?.body?.hits?.hits;
|
|
215
215
|
logger.info( { searchValue: searchValue } );
|
|
216
216
|
if ( !searchValue || searchValue?.length == 0 ) {
|
|
217
217
|
return res.sendError( 'No data found', 204 );
|
|
@@ -325,7 +325,7 @@ export async function getList( req, res ) {
|
|
|
325
325
|
// i = i+hits.length;
|
|
326
326
|
// logger.info( { index: i, length: hits.length, msg: '........index' } );
|
|
327
327
|
// allHits.push( ...hits );
|
|
328
|
-
// if ( allHits.length >=
|
|
328
|
+
// if ( allHits.length >= 50000 ) {
|
|
329
329
|
// hasMore = false;
|
|
330
330
|
// } else {
|
|
331
331
|
// searchAfter = hits[hits.length - 1].sort;
|
|
@@ -759,82 +759,119 @@ export async function save( req, res ) {
|
|
|
759
759
|
await updateOpenSearchData( openSearch.EyeTestOutput, output?._id, { doc: record } );
|
|
760
760
|
await updateOpenSearchData( openSearch.EyeTestInput, inputData.id, { doc: inputrecord } );
|
|
761
761
|
|
|
762
|
-
const getOne = await
|
|
763
|
-
const inputUpdatedData = getOne?.body
|
|
764
|
-
|
|
765
|
-
|
|
762
|
+
const getOne = await getOpenSearchById( openSearch.EyeTestInput, inputData.id );
|
|
763
|
+
const inputUpdatedData = getOne?.body;
|
|
764
|
+
|
|
765
|
+
const getEyetestConfig = await findOneEyeTestConfig( { clientId: req?.user.userType == 'tango'? inputData?.clientId : req.user.clientId, configureType: 'email' }, { complianceThreshold: 1 } );
|
|
766
|
+
|
|
767
|
+
if ( getEyetestConfig && inputData.auditStatus == 'Audited' && inputUpdatedData ) {
|
|
766
768
|
const trustScore = Math.round( 100-( ( inputData?.overRides / inputData?.steps?.length ) * 100 ) );
|
|
767
|
-
const value = Number( getEyetestConfig?.value?.split( '%' )[0] );
|
|
768
|
-
const condition = getEyetestConfig
|
|
769
|
-
const id= `${inputData?.RMEmail}_${inputData?.cluster}_${inputUpdatedData?.
|
|
769
|
+
const value = Number( getEyetestConfig?.complianceThreshold?.value?.split( '%' )[0] );
|
|
770
|
+
const condition = getEyetestConfig?.complianceThreshold?.condition;
|
|
771
|
+
const id= `${inputData?.RMEmail}_${inputData?.cluster}_${inputUpdatedData?._source?.optumId}_${inputData?.fileId}`;
|
|
770
772
|
switch ( condition ) {
|
|
771
773
|
case '>': if ( trustScore > value ) {
|
|
772
774
|
const record1 = {
|
|
773
775
|
RMEmail: inputData.RMEmail,
|
|
774
776
|
cluster: inputData.cluster,
|
|
775
|
-
optumId: inputUpdatedData?.
|
|
776
|
-
storeName: inputUpdatedData?.
|
|
777
|
-
complianceScore: inputUpdatedData?.
|
|
778
|
-
trustScore: inputUpdatedData?.
|
|
777
|
+
optumId: inputUpdatedData?._source?.optumId,
|
|
778
|
+
storeName: inputUpdatedData?._source?.storeName,
|
|
779
|
+
complianceScore: inputUpdatedData?._source?.ComplianceScore,
|
|
780
|
+
trustScore: inputUpdatedData?._source?.trustScore,
|
|
781
|
+
auditedId: inputUpdatedData?._id,
|
|
782
|
+
queueId: inputUpdatedData?._source?.queueId,
|
|
783
|
+
createdAt: new Date(),
|
|
784
|
+
updatedAt: new Date(),
|
|
785
|
+
|
|
779
786
|
};
|
|
780
787
|
await insertWithId( openSearch.eyeTestEmailAlert, id, record1 );
|
|
781
788
|
}
|
|
789
|
+
break;
|
|
782
790
|
case '<': if ( trustScore < value ) {
|
|
783
791
|
const record2 = {
|
|
784
792
|
RMEmail: inputData.RMEmail,
|
|
785
793
|
cluster: inputData.cluster,
|
|
786
|
-
optumId: inputUpdatedData?.
|
|
787
|
-
storeName: inputUpdatedData?.
|
|
788
|
-
complianceScore: inputUpdatedData?.
|
|
789
|
-
trustScore: inputUpdatedData?.
|
|
794
|
+
optumId: inputUpdatedData?._source?.optumId,
|
|
795
|
+
storeName: inputUpdatedData?._source?.storeName,
|
|
796
|
+
complianceScore: inputUpdatedData?._source?.ComplianceScore,
|
|
797
|
+
trustScore: inputUpdatedData?._source?.trustScore,
|
|
798
|
+
auditedId: inputUpdatedData?._id,
|
|
799
|
+
queueId: inputUpdatedData?._source?.queueId,
|
|
800
|
+
createdAt: new Date(),
|
|
801
|
+
updatedAt: new Date(),
|
|
802
|
+
|
|
790
803
|
};
|
|
791
804
|
await insertWithId( openSearch.eyeTestEmailAlert, id, record2 );
|
|
792
805
|
};
|
|
806
|
+
break;
|
|
793
807
|
case '>=': if ( trustScore >= value ) {
|
|
794
808
|
const record3 = {
|
|
795
809
|
RMEmail: inputData.RMEmail,
|
|
796
810
|
cluster: inputData.cluster,
|
|
797
|
-
optumId: inputUpdatedData?.
|
|
798
|
-
storeName: inputUpdatedData?.
|
|
799
|
-
complianceScore: inputUpdatedData?.
|
|
800
|
-
trustScore: inputUpdatedData?.
|
|
811
|
+
optumId: inputUpdatedData?._source?.optumId,
|
|
812
|
+
storeName: inputUpdatedData?._source?.storeName,
|
|
813
|
+
complianceScore: inputUpdatedData?._source?.ComplianceScore,
|
|
814
|
+
trustScore: inputUpdatedData?._source?.trustScore,
|
|
815
|
+
auditedId: inputUpdatedData?._id,
|
|
816
|
+
queueId: inputUpdatedData?._source?.queueId,
|
|
817
|
+
createdAt: new Date(),
|
|
818
|
+
updatedAt: new Date(),
|
|
819
|
+
|
|
801
820
|
};
|
|
802
821
|
await insertWithId( openSearch.eyeTestEmailAlert, id, record3 );
|
|
803
822
|
}
|
|
823
|
+
break;
|
|
804
824
|
case '<=': if ( trustScore <= value ) {
|
|
805
825
|
const record4 = {
|
|
806
826
|
RMEmail: inputData.RMEmail,
|
|
807
827
|
cluster: inputData.cluster,
|
|
808
|
-
optumId: inputUpdatedData?.
|
|
809
|
-
storeName: inputUpdatedData?.
|
|
810
|
-
complianceScore: inputUpdatedData?.
|
|
811
|
-
trustScore: inputUpdatedData?.
|
|
828
|
+
optumId: inputUpdatedData?._source?.optumId,
|
|
829
|
+
storeName: inputUpdatedData?._source?.storeName,
|
|
830
|
+
complianceScore: inputUpdatedData?._source?.ComplianceScore,
|
|
831
|
+
trustScore: inputUpdatedData?._source?.trustScore,
|
|
832
|
+
auditedId: inputUpdatedData?._id,
|
|
833
|
+
queueId: inputUpdatedData?._source?.queueId,
|
|
834
|
+
createdAt: new Date(),
|
|
835
|
+
updatedAt: new Date(),
|
|
836
|
+
|
|
812
837
|
};
|
|
813
838
|
await insertWithId( openSearch.eyeTestEmailAlert, id, record4 );
|
|
814
839
|
}
|
|
840
|
+
break;
|
|
815
841
|
case '=':
|
|
816
842
|
case '==': if ( trustScore == value ) {
|
|
817
843
|
const record5 = {
|
|
818
844
|
RMEmail: inputData.RMEmail,
|
|
819
845
|
cluster: inputData.cluster,
|
|
820
|
-
optumId: inputUpdatedData?.
|
|
821
|
-
storeName: inputUpdatedData?.
|
|
822
|
-
complianceScore: inputUpdatedData?.
|
|
823
|
-
trustScore: inputUpdatedData?.
|
|
846
|
+
optumId: inputUpdatedData?._source?.optumId,
|
|
847
|
+
storeName: inputUpdatedData?._source?.storeName,
|
|
848
|
+
complianceScore: inputUpdatedData?._source?.ComplianceScore,
|
|
849
|
+
trustScore: inputUpdatedData?._source?.trustScore,
|
|
850
|
+
auditedId: inputUpdatedData?._id,
|
|
851
|
+
queueId: inputUpdatedData?._source?.queueId,
|
|
852
|
+
createdAt: new Date(),
|
|
853
|
+
updatedAt: new Date(),
|
|
854
|
+
|
|
824
855
|
};
|
|
825
856
|
await insertWithId( openSearch.eyeTestEmailAlert, id, record5 );
|
|
826
857
|
}
|
|
858
|
+
break;
|
|
827
859
|
case '===': if ( trustScore === value ) {
|
|
828
860
|
const record6 = {
|
|
829
861
|
RMEmail: inputData.RMEmail,
|
|
830
862
|
cluster: inputData.cluster,
|
|
831
|
-
optumId: inputUpdatedData?.
|
|
832
|
-
storeName: inputUpdatedData?.
|
|
833
|
-
complianceScore: inputUpdatedData?.
|
|
834
|
-
trustScore: inputUpdatedData?.
|
|
863
|
+
optumId: inputUpdatedData?._source?.optumId,
|
|
864
|
+
storeName: inputUpdatedData?._source?.storeName,
|
|
865
|
+
complianceScore: inputUpdatedData?._source?.ComplianceScore,
|
|
866
|
+
trustScore: inputUpdatedData?._source?.trustScore,
|
|
867
|
+
auditedId: inputUpdatedData?._id,
|
|
868
|
+
queueId: inputUpdatedData?._source?.queueId,
|
|
869
|
+
createdAt: new Date(),
|
|
870
|
+
updatedAt: new Date(),
|
|
835
871
|
};
|
|
836
872
|
await insertWithId( openSearch.eyeTestEmailAlert, id, record6 );
|
|
837
873
|
}
|
|
874
|
+
break;
|
|
838
875
|
default: throw new Error( `Unknown condition: ${condition}` );
|
|
839
876
|
}
|
|
840
877
|
}
|
|
@@ -1480,7 +1517,7 @@ export async function summaryList( req, res ) {
|
|
|
1480
1517
|
if ( inputData.isExport==true ) {
|
|
1481
1518
|
searchQuery={
|
|
1482
1519
|
'from': 0,
|
|
1483
|
-
'size':
|
|
1520
|
+
'size': 50000,
|
|
1484
1521
|
'query': {
|
|
1485
1522
|
'bool': search,
|
|
1486
1523
|
},
|
|
@@ -1857,53 +1894,22 @@ export async function emailAlertLog( req, res ) {
|
|
|
1857
1894
|
try {
|
|
1858
1895
|
// declare a key for request data
|
|
1859
1896
|
const inputData = req.body;
|
|
1897
|
+
const offset = inputData.offset ?
|
|
1898
|
+
( inputData.offset - 1 ) * inputData.limit :
|
|
1899
|
+
0;
|
|
1860
1900
|
inputData.sortBy = inputData.sortBy || 'updatedAt';
|
|
1861
1901
|
inputData.sortOrder = inputData.sortOrder || -1;
|
|
1862
1902
|
inputData.clientId = req.user.userType == 'tango'? inputData?.clientId : req?.user?.clientId;
|
|
1863
1903
|
// get openserach name form the env file
|
|
1864
1904
|
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
1865
1905
|
|
|
1866
|
-
// getting user and cluster information from mongo db
|
|
1867
|
-
|
|
1868
|
-
// const getUserListQuery = {
|
|
1869
|
-
// clientId: inputData.clientId,
|
|
1870
|
-
// configureType: 'user',
|
|
1871
|
-
// };
|
|
1872
|
-
|
|
1873
|
-
// const getUserList = await findOneEyeTestConfig( getUserListQuery, { userList: 1 } );
|
|
1874
|
-
// if ( !getUserList || !getUserList?.userList || getUserList?.userList?.lenght == 0 ) {
|
|
1875
|
-
// return res.sendError( 'No records found', 204 );
|
|
1876
|
-
// }
|
|
1877
|
-
// const userList = getUserList?.map( ( item ) => item.email );
|
|
1878
|
-
|
|
1879
|
-
// gettting cluster respective users
|
|
1880
|
-
// const clusterQuery =[
|
|
1881
|
-
// {
|
|
1882
|
-
// $match: {
|
|
1883
|
-
// $and: [
|
|
1884
|
-
// {
|
|
1885
|
-
// 'Teamlead.email': { $in: userList },
|
|
1886
|
-
// },
|
|
1887
|
-
// ],
|
|
1888
|
-
// },
|
|
1889
|
-
// },
|
|
1890
|
-
// {
|
|
1891
|
-
// $project: {
|
|
1892
|
-
// email: '$Teamlead.email',
|
|
1893
|
-
// clusterName: '$clusterName',
|
|
1894
|
-
// clientId: 1,
|
|
1895
|
-
// },
|
|
1896
|
-
// },
|
|
1897
|
-
// ];
|
|
1898
|
-
// const getCluster = await aggregateClusters();
|
|
1899
|
-
// open search query to get logs
|
|
1900
1906
|
|
|
1901
1907
|
let filter =[
|
|
1902
1908
|
{
|
|
1903
1909
|
'range': {
|
|
1904
|
-
'
|
|
1905
|
-
'gte':
|
|
1906
|
-
'lte':
|
|
1910
|
+
'createdAt': {
|
|
1911
|
+
'gte': dayjs( inputData.fromDate ),
|
|
1912
|
+
'lte': dayjs( `${inputData.toDate} ${dayjs().format( 'HH:mm:ss' )}` ),
|
|
1907
1913
|
},
|
|
1908
1914
|
},
|
|
1909
1915
|
},
|
|
@@ -1927,7 +1933,8 @@ export async function emailAlertLog( req, res ) {
|
|
|
1927
1933
|
} );
|
|
1928
1934
|
}
|
|
1929
1935
|
const getQuery = {
|
|
1930
|
-
'size':
|
|
1936
|
+
'size': inputData.isExport == true? 50000 : inputData?.limit || 10,
|
|
1937
|
+
'from': offset || 0,
|
|
1931
1938
|
'query': {
|
|
1932
1939
|
'bool': {
|
|
1933
1940
|
'must': filter,
|
|
@@ -1938,9 +1945,8 @@ export async function emailAlertLog( req, res ) {
|
|
|
1938
1945
|
|
|
1939
1946
|
// get query result from the open saerch
|
|
1940
1947
|
const getData= await getOpenSearchData( openSearch.eyeTestEmailAlert, getQuery );
|
|
1941
|
-
|
|
1942
1948
|
// throw error if got null or empty array
|
|
1943
|
-
if ( getData
|
|
1949
|
+
if ( !getData || getData?.body?.hits?.hits?.length == 0 ) {
|
|
1944
1950
|
return res.sendError( 'No records found', 204 );
|
|
1945
1951
|
}
|
|
1946
1952
|
let response =[];
|
|
@@ -1950,10 +1956,36 @@ export async function emailAlertLog( req, res ) {
|
|
|
1950
1956
|
cluster: item?._source?.cluster,
|
|
1951
1957
|
optumId: item?._source?.optumId,
|
|
1952
1958
|
storeName: item?._source?.storeName,
|
|
1953
|
-
complianceScore: item?.
|
|
1959
|
+
complianceScore: item?._source?.complianceScore,
|
|
1954
1960
|
trustScore: item?._source?.trustScore,
|
|
1961
|
+
auditedId: item?._source?.auditedId,
|
|
1962
|
+
queueId: item?._source?.queueId,
|
|
1963
|
+
|
|
1964
|
+
} );
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
if ( inputData.isExport == true ) {
|
|
1968
|
+
const chunkedMappingData = await chunkArray( response, 10 );
|
|
1969
|
+
const promises = chunkedMappingData.map( async ( chunk ) => {
|
|
1970
|
+
const exportData = [];
|
|
1971
|
+
for ( const element of chunk ) {
|
|
1972
|
+
exportData.push( {
|
|
1973
|
+
'RM Email': element.RMEmail,
|
|
1974
|
+
'Cluster Name': element.cluster,
|
|
1975
|
+
'Optum Id': element.optumId,
|
|
1976
|
+
'Store Name': element.storeName,
|
|
1977
|
+
'Tango Score': element.complianceScore || 0,
|
|
1978
|
+
'Trust Score': element.trustScore || 0,
|
|
1955
1979
|
|
|
1980
|
+
} );
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
return exportData;
|
|
1956
1984
|
} );
|
|
1985
|
+
const mappedArrays = await Promise.all( promises );
|
|
1986
|
+
const result = mappedArrays.flat();
|
|
1987
|
+
await download( result, res );
|
|
1988
|
+
return;
|
|
1957
1989
|
}
|
|
1958
1990
|
|
|
1959
1991
|
|
|
@@ -288,6 +288,8 @@ export const emailAlertLogSchema = joi.object( {
|
|
|
288
288
|
searchValue: joi.string().optional().allow( '' ),
|
|
289
289
|
sortBy: joi.string().optional(),
|
|
290
290
|
sortOrder: joi.number().optional(),
|
|
291
|
+
offset: joi.number().optional(),
|
|
292
|
+
limit: joi.number().optional(),
|
|
291
293
|
} );
|
|
292
294
|
|
|
293
295
|
export const emailAlertLogValid = {
|