tango-app-api-audit 3.5.34 → 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.34",
3
+ "version": "3.5.35",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -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': 10000,
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 >= 10000 ? await fetchDeepPage( openSearch.EyeTestInput, search, limit, offset, sortBy, order, inputData?.searchAfter ) : await getOpenSearchData( openSearch.EyeTestInput, searchQuery );
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 >= 10000 ? result : result?.body?.hits?.hits;
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 >= 10000 ) {
328
+ // if ( allHits.length >= 50000 ) {
329
329
  // hasMore = false;
330
330
  // } else {
331
331
  // searchAfter = hits[hits.length - 1].sort;
@@ -776,8 +776,10 @@ export async function save( req, res ) {
776
776
  cluster: inputData.cluster,
777
777
  optumId: inputUpdatedData?._source?.optumId,
778
778
  storeName: inputUpdatedData?._source?.storeName,
779
- complianceScore: inputUpdatedData?._source?.complianceScore,
779
+ complianceScore: inputUpdatedData?._source?.ComplianceScore,
780
780
  trustScore: inputUpdatedData?._source?.trustScore,
781
+ auditedId: inputUpdatedData?._id,
782
+ queueId: inputUpdatedData?._source?.queueId,
781
783
  createdAt: new Date(),
782
784
  updatedAt: new Date(),
783
785
 
@@ -791,8 +793,10 @@ export async function save( req, res ) {
791
793
  cluster: inputData.cluster,
792
794
  optumId: inputUpdatedData?._source?.optumId,
793
795
  storeName: inputUpdatedData?._source?.storeName,
794
- complianceScore: inputUpdatedData?._source?.complianceScore,
796
+ complianceScore: inputUpdatedData?._source?.ComplianceScore,
795
797
  trustScore: inputUpdatedData?._source?.trustScore,
798
+ auditedId: inputUpdatedData?._id,
799
+ queueId: inputUpdatedData?._source?.queueId,
796
800
  createdAt: new Date(),
797
801
  updatedAt: new Date(),
798
802
 
@@ -806,8 +810,10 @@ export async function save( req, res ) {
806
810
  cluster: inputData.cluster,
807
811
  optumId: inputUpdatedData?._source?.optumId,
808
812
  storeName: inputUpdatedData?._source?.storeName,
809
- complianceScore: inputUpdatedData?._source?.complianceScore,
813
+ complianceScore: inputUpdatedData?._source?.ComplianceScore,
810
814
  trustScore: inputUpdatedData?._source?.trustScore,
815
+ auditedId: inputUpdatedData?._id,
816
+ queueId: inputUpdatedData?._source?.queueId,
811
817
  createdAt: new Date(),
812
818
  updatedAt: new Date(),
813
819
 
@@ -821,8 +827,10 @@ export async function save( req, res ) {
821
827
  cluster: inputData.cluster,
822
828
  optumId: inputUpdatedData?._source?.optumId,
823
829
  storeName: inputUpdatedData?._source?.storeName,
824
- complianceScore: inputUpdatedData?._source?.complianceScore,
830
+ complianceScore: inputUpdatedData?._source?.ComplianceScore,
825
831
  trustScore: inputUpdatedData?._source?.trustScore,
832
+ auditedId: inputUpdatedData?._id,
833
+ queueId: inputUpdatedData?._source?.queueId,
826
834
  createdAt: new Date(),
827
835
  updatedAt: new Date(),
828
836
 
@@ -837,8 +845,10 @@ export async function save( req, res ) {
837
845
  cluster: inputData.cluster,
838
846
  optumId: inputUpdatedData?._source?.optumId,
839
847
  storeName: inputUpdatedData?._source?.storeName,
840
- complianceScore: inputUpdatedData?._source?.complianceScore,
848
+ complianceScore: inputUpdatedData?._source?.ComplianceScore,
841
849
  trustScore: inputUpdatedData?._source?.trustScore,
850
+ auditedId: inputUpdatedData?._id,
851
+ queueId: inputUpdatedData?._source?.queueId,
842
852
  createdAt: new Date(),
843
853
  updatedAt: new Date(),
844
854
 
@@ -852,8 +862,10 @@ export async function save( req, res ) {
852
862
  cluster: inputData.cluster,
853
863
  optumId: inputUpdatedData?._source?.optumId,
854
864
  storeName: inputUpdatedData?._source?.storeName,
855
- complianceScore: inputUpdatedData?._source?.complianceScore,
865
+ complianceScore: inputUpdatedData?._source?.ComplianceScore,
856
866
  trustScore: inputUpdatedData?._source?.trustScore,
867
+ auditedId: inputUpdatedData?._id,
868
+ queueId: inputUpdatedData?._source?.queueId,
857
869
  createdAt: new Date(),
858
870
  updatedAt: new Date(),
859
871
  };
@@ -1505,7 +1517,7 @@ export async function summaryList( req, res ) {
1505
1517
  if ( inputData.isExport==true ) {
1506
1518
  searchQuery={
1507
1519
  'from': 0,
1508
- 'size': 10000,
1520
+ 'size': 50000,
1509
1521
  'query': {
1510
1522
  'bool': search,
1511
1523
  },
@@ -1882,53 +1894,22 @@ export async function emailAlertLog( req, res ) {
1882
1894
  try {
1883
1895
  // declare a key for request data
1884
1896
  const inputData = req.body;
1897
+ const offset = inputData.offset ?
1898
+ ( inputData.offset - 1 ) * inputData.limit :
1899
+ 0;
1885
1900
  inputData.sortBy = inputData.sortBy || 'updatedAt';
1886
1901
  inputData.sortOrder = inputData.sortOrder || -1;
1887
1902
  inputData.clientId = req.user.userType == 'tango'? inputData?.clientId : req?.user?.clientId;
1888
1903
  // get openserach name form the env file
1889
1904
  const openSearch = JSON.parse( process.env.OPENSEARCH );
1890
1905
 
1891
- // getting user and cluster information from mongo db
1892
-
1893
- // const getUserListQuery = {
1894
- // clientId: inputData.clientId,
1895
- // configureType: 'user',
1896
- // };
1897
-
1898
- // const getUserList = await findOneEyeTestConfig( getUserListQuery, { userList: 1 } );
1899
- // if ( !getUserList || !getUserList?.userList || getUserList?.userList?.lenght == 0 ) {
1900
- // return res.sendError( 'No records found', 204 );
1901
- // }
1902
- // const userList = getUserList?.map( ( item ) => item.email );
1903
-
1904
- // gettting cluster respective users
1905
- // const clusterQuery =[
1906
- // {
1907
- // $match: {
1908
- // $and: [
1909
- // {
1910
- // 'Teamlead.email': { $in: userList },
1911
- // },
1912
- // ],
1913
- // },
1914
- // },
1915
- // {
1916
- // $project: {
1917
- // email: '$Teamlead.email',
1918
- // clusterName: '$clusterName',
1919
- // clientId: 1,
1920
- // },
1921
- // },
1922
- // ];
1923
- // const getCluster = await aggregateClusters();
1924
- // open search query to get logs
1925
1906
 
1926
1907
  let filter =[
1927
1908
  {
1928
1909
  'range': {
1929
- 'date': {
1930
- 'gte': new Date( inputData.fromDate ),
1931
- 'lte': new Date( inputData.toDate ),
1910
+ 'createdAt': {
1911
+ 'gte': dayjs( inputData.fromDate ),
1912
+ 'lte': dayjs( `${inputData.toDate} ${dayjs().format( 'HH:mm:ss' )}` ),
1932
1913
  },
1933
1914
  },
1934
1915
  },
@@ -1952,7 +1933,8 @@ export async function emailAlertLog( req, res ) {
1952
1933
  } );
1953
1934
  }
1954
1935
  const getQuery = {
1955
- 'size': 100,
1936
+ 'size': inputData.isExport == true? 50000 : inputData?.limit || 10,
1937
+ 'from': offset || 0,
1956
1938
  'query': {
1957
1939
  'bool': {
1958
1940
  'must': filter,
@@ -1963,9 +1945,8 @@ export async function emailAlertLog( req, res ) {
1963
1945
 
1964
1946
  // get query result from the open saerch
1965
1947
  const getData= await getOpenSearchData( openSearch.eyeTestEmailAlert, getQuery );
1966
-
1967
1948
  // throw error if got null or empty array
1968
- if ( getData && getData?.body?.hits?.hits?.length > 0 ) {
1949
+ if ( !getData || getData?.body?.hits?.hits?.length == 0 ) {
1969
1950
  return res.sendError( 'No records found', 204 );
1970
1951
  }
1971
1952
  let response =[];
@@ -1975,10 +1956,36 @@ export async function emailAlertLog( req, res ) {
1975
1956
  cluster: item?._source?.cluster,
1976
1957
  optumId: item?._source?.optumId,
1977
1958
  storeName: item?._source?.storeName,
1978
- complianceScore: item?.source?.complianceScore,
1959
+ complianceScore: item?._source?.complianceScore,
1979
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,
1979
+
1980
+ } );
1981
+ }
1980
1982
 
1983
+ return exportData;
1981
1984
  } );
1985
+ const mappedArrays = await Promise.all( promises );
1986
+ const result = mappedArrays.flat();
1987
+ await download( result, res );
1988
+ return;
1982
1989
  }
1983
1990
 
1984
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 = {