tango-app-api-audit 3.5.34 → 3.5.36

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/build.js ADDED
@@ -0,0 +1,25 @@
1
+ // build.js
2
+ import fs from 'fs';
3
+
4
+ const type = process.argv[2] || 'patch'; // default to patch
5
+ const file = 'package.json';
6
+
7
+ // Read and parse package.json
8
+ const pkg = JSON.parse( fs.readFileSync( file, 'utf8' ) );
9
+
10
+ // Force "main" to be "index.js"
11
+ pkg.main = 'index.js';
12
+
13
+ // Bump version
14
+ const [ major, minor, patch ] = pkg.version.split( '.' ).map( Number );
15
+
16
+ if ( type === 'patch' ) pkg.version = `${major}.${minor}.${patch + 1}`;
17
+ else if ( type === 'minor' ) pkg.version = `${major}.${minor + 1}.0`;
18
+ else if ( type === 'major' ) pkg.version = `${major + 1}.0.0`;
19
+ else throw new Error( 'Invalid version type. Use patch, minor, or major.' );
20
+
21
+ // Write back to package.json
22
+ fs.writeFileSync( file, JSON.stringify( pkg, null, 2 ) );
23
+
24
+ // console.log( `🔧 Updated version to ${pkg.version} and set "main": "index.js"` );
25
+
package/config.zip ADDED
Binary file
package/package.json CHANGED
@@ -1,42 +1,45 @@
1
- {
2
- "name": "tango-app-api-audit",
3
- "version": "3.5.34",
4
- "description": "audit & audit metrics apis",
5
- "main": "index.js",
6
- "type": "module",
7
- "scripts": {
8
- "start": "nodemon --exec \"eslint --fix . && node app.js\""
9
- },
10
- "engines": {
11
- "node": ">=18.10.0"
12
- },
13
- "author": "praveenraj",
14
- "license": "ISC",
15
- "dependencies": {
16
- "adm-zip": "^0.5.15",
17
- "aws-sdk": "^2.1643.0",
18
- "axios": "^1.7.9",
19
- "dayjs": "^1.11.11",
20
- "dotenv": "^16.4.5",
21
- "express": "^4.19.2",
22
- "form-data": "^4.0.1",
23
- "handlebars": "^4.7.8",
24
- "joi-to-swagger": "^6.2.0",
25
- "lodash": "^4.17.21",
26
- "mongodb": "^6.7.0",
27
- "nodemon": "^3.1.3",
28
- "swagger-ui-express": "^5.0.1",
29
- "tango-api-schema": "^2.3.28",
30
- "tango-app-api-middleware": "^3.4.4",
31
- "winston": "^3.13.0",
32
- "winston-daily-rotate-file": "^5.0.0"
33
- },
34
- "devDependencies": {
35
- "eslint": "^8.57.0",
36
- "eslint-config-google": "^0.14.0",
37
- "eslint-config-semistandard": "^17.0.0",
38
- "eslint-config-standard": "^17.1.0",
39
- "eslint-plugin-import": "^2.29.1",
40
- "eslint-plugin-promise": "^6.2.0"
41
- }
42
- }
1
+ {
2
+ "name": "tango-app-api-audit",
3
+ "version": "3.5.36",
4
+ "description": "audit & audit metrics apis",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "start": "nodemon --exec \"eslint --fix . && node app.js\"",
9
+ "build:patch": "node build.js patch && npm publish",
10
+ "build:minor": "node build.js minor && npm publish",
11
+ "build:major": "node build.js major && npm publish"
12
+ },
13
+ "engines": {
14
+ "node": ">=18.10.0"
15
+ },
16
+ "author": "praveenraj",
17
+ "license": "ISC",
18
+ "dependencies": {
19
+ "adm-zip": "^0.5.15",
20
+ "aws-sdk": "^2.1643.0",
21
+ "axios": "^1.7.9",
22
+ "dayjs": "^1.11.11",
23
+ "dotenv": "^16.4.5",
24
+ "express": "^4.19.2",
25
+ "form-data": "^4.0.1",
26
+ "handlebars": "^4.7.8",
27
+ "joi-to-swagger": "^6.2.0",
28
+ "lodash": "^4.17.21",
29
+ "mongodb": "^6.7.0",
30
+ "nodemon": "^3.1.3",
31
+ "swagger-ui-express": "^5.0.1",
32
+ "tango-api-schema": "^2.3.28",
33
+ "tango-app-api-middleware": "^3.4.4",
34
+ "winston": "^3.13.0",
35
+ "winston-daily-rotate-file": "^5.0.0"
36
+ },
37
+ "devDependencies": {
38
+ "eslint": "^8.57.0",
39
+ "eslint-config-google": "^0.14.0",
40
+ "eslint-config-semistandard": "^17.0.0",
41
+ "eslint-config-standard": "^17.1.0",
42
+ "eslint-plugin-import": "^2.29.1",
43
+ "eslint-plugin-promise": "^6.2.0"
44
+ }
45
+ }
@@ -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
  },
@@ -1623,6 +1635,7 @@ export async function summaryList( req, res ) {
1623
1635
  temp[i].date = dayjs( item?._source?.date ).format( 'D MMM, YYYY' );
1624
1636
  temp[i].RMName = RMName;
1625
1637
  temp[i].clusterName =clusterName;
1638
+ temp[i]._id = item?._id;
1626
1639
  }
1627
1640
  logger.info( { temp: temp } );
1628
1641
  }
@@ -1882,53 +1895,22 @@ export async function emailAlertLog( req, res ) {
1882
1895
  try {
1883
1896
  // declare a key for request data
1884
1897
  const inputData = req.body;
1898
+ const offset = inputData.offset ?
1899
+ ( inputData.offset - 1 ) * inputData.limit :
1900
+ 0;
1885
1901
  inputData.sortBy = inputData.sortBy || 'updatedAt';
1886
1902
  inputData.sortOrder = inputData.sortOrder || -1;
1887
1903
  inputData.clientId = req.user.userType == 'tango'? inputData?.clientId : req?.user?.clientId;
1888
1904
  // get openserach name form the env file
1889
1905
  const openSearch = JSON.parse( process.env.OPENSEARCH );
1890
1906
 
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
1907
 
1926
1908
  let filter =[
1927
1909
  {
1928
1910
  'range': {
1929
- 'date': {
1930
- 'gte': new Date( inputData.fromDate ),
1931
- 'lte': new Date( inputData.toDate ),
1911
+ 'createdAt': {
1912
+ 'gte': dayjs( inputData.fromDate ),
1913
+ 'lte': dayjs( `${inputData.toDate} ${dayjs().format( 'HH:mm:ss' )}` ),
1932
1914
  },
1933
1915
  },
1934
1916
  },
@@ -1952,7 +1934,8 @@ export async function emailAlertLog( req, res ) {
1952
1934
  } );
1953
1935
  }
1954
1936
  const getQuery = {
1955
- 'size': 100,
1937
+ 'size': inputData.isExport == true? 50000 : inputData?.limit || 10,
1938
+ 'from': offset || 0,
1956
1939
  'query': {
1957
1940
  'bool': {
1958
1941
  'must': filter,
@@ -1963,9 +1946,8 @@ export async function emailAlertLog( req, res ) {
1963
1946
 
1964
1947
  // get query result from the open saerch
1965
1948
  const getData= await getOpenSearchData( openSearch.eyeTestEmailAlert, getQuery );
1966
-
1967
1949
  // throw error if got null or empty array
1968
- if ( getData && getData?.body?.hits?.hits?.length > 0 ) {
1950
+ if ( !getData || getData?.body?.hits?.hits?.length == 0 ) {
1969
1951
  return res.sendError( 'No records found', 204 );
1970
1952
  }
1971
1953
  let response =[];
@@ -1975,10 +1957,36 @@ export async function emailAlertLog( req, res ) {
1975
1957
  cluster: item?._source?.cluster,
1976
1958
  optumId: item?._source?.optumId,
1977
1959
  storeName: item?._source?.storeName,
1978
- complianceScore: item?.source?.complianceScore,
1960
+ complianceScore: item?._source?.complianceScore,
1979
1961
  trustScore: item?._source?.trustScore,
1962
+ auditedId: item?._source?.auditedId,
1963
+ queueId: item?._source?.queueId,
1964
+
1965
+ } );
1966
+ }
1967
+
1968
+ if ( inputData.isExport == true ) {
1969
+ const chunkedMappingData = await chunkArray( response, 10 );
1970
+ const promises = chunkedMappingData.map( async ( chunk ) => {
1971
+ const exportData = [];
1972
+ for ( const element of chunk ) {
1973
+ exportData.push( {
1974
+ 'RM Email': element.RMEmail,
1975
+ 'Cluster Name': element.cluster,
1976
+ 'Optum Id': element.optumId,
1977
+ 'Store Name': element.storeName,
1978
+ 'Tango Score': element.complianceScore || 0,
1979
+ 'Trust Score': element.trustScore || 0,
1980
+
1981
+ } );
1982
+ }
1980
1983
 
1984
+ return exportData;
1981
1985
  } );
1986
+ const mappedArrays = await Promise.all( promises );
1987
+ const result = mappedArrays.flat();
1988
+ await download( result, res );
1989
+ return;
1982
1990
  }
1983
1991
 
1984
1992
 
@@ -1986,7 +1994,7 @@ export async function emailAlertLog( req, res ) {
1986
1994
 
1987
1995
 
1988
1996
  logger.info( { inputData: inputData, getData: response } );
1989
- return res.sendSuccess( { result: response } );
1997
+ return res.sendSuccess( { result: response, count: response.length } );
1990
1998
  } catch ( error ) {
1991
1999
  const err = error.message || 'Internal Server Error';
1992
2000
  logger.error( { message: error, data: req.body, function: 'eyetestAudit-controller-emailAlertLog' } );
@@ -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 = {