tango-app-api-audit 3.4.8 → 3.4.10

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.4.8",
3
+ "version": "3.4.10",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -2345,12 +2345,21 @@ export async function userMetrics( req, res ) {
2345
2345
  beforeCount: 1,
2346
2346
  afterCount: 1,
2347
2347
  mappingPerc: {
2348
- $round: [
2348
+ $cond: [
2349
+ { $and: [
2350
+ { $gt: [ '$beforeCount', 0 ] },
2351
+ { $gt: [ '$afterCount', 0 ] },
2352
+ ] },
2349
2353
  {
2350
- $multiply: [
2351
- { $divide: [ '$afterCount', '$beforeCount' ] }, 100,
2354
+ $round: [
2355
+ {
2356
+ $multiply: [
2357
+ { $divide: [ '$afterCount', '$beforeCount' ] }, 100,
2358
+ ],
2359
+ }, 2,
2352
2360
  ],
2353
- }, 2,
2361
+ },
2362
+ 0,
2354
2363
  ],
2355
2364
  },
2356
2365
  checkIntime: 1,
@@ -2535,7 +2544,7 @@ export async function userMetrics( req, res ) {
2535
2544
  'Check Intime': '$checkIntime',
2536
2545
  'Check OutTime': '$checkOutTime',
2537
2546
  'Working Hours': '$workingHours',
2538
- 'Audited Date': { $dateToString: { format: '%Y,%b %d', date: '$createdAt' } },
2547
+ 'Audited Date': { $dateToString: { format: '%Y-%m-%d', date: '$createdAt' } },
2539
2548
  },
2540
2549
  },
2541
2550
  );
@@ -4733,6 +4742,7 @@ export async function auditViewLogs( req, res ) {
4733
4742
  return res.sendError( 'Please give valid modueType', 400 );
4734
4743
  }
4735
4744
  }
4745
+ logger.info( { query: logsQuery, message: 'unattended' } );
4736
4746
  const logs = await getOpenSearchData( parsedOpenSearch.auditLog, logsQuery );
4737
4747
  logger.info( { logs: logs.body.hits, inputData: inputData, auditLog: parsedOpenSearch.auditLog } );
4738
4748
  if ( logs.body.hits.hits.length > 0 ) {
@@ -4763,36 +4773,32 @@ export async function auditViewLogs( req, res ) {
4763
4773
  }
4764
4774
  }
4765
4775
 
4766
- export async function convertTimestampToDateTime( timestamp ) {
4767
- // Check if the timestamp is too large (nanoseconds), then convert it to milliseconds
4768
- if ( timestamp > 9999999999999 ) {
4769
- timestamp = Math.floor( timestamp / 1000 ); // Convert to milliseconds if needed
4770
- }
4771
-
4772
- // Add 5 hours and 30 minutes in milliseconds
4773
- const timeOffset = ( 5 * 60 * 60 * 1000 ) + ( 30 * 60 * 1000 );
4774
4776
 
4775
- // Ensure the timestamp is valid by adding the offset correctly
4776
- const adjustedTimestamp = timestamp + timeOffset;
4777
-
4778
- // Create a new Date object using the adjusted timestamp
4779
- const date = new Date( adjustedTimestamp );
4780
-
4781
- // Ensure the date is valid (timestamp may be invalid)
4782
- if ( isNaN( date.getTime() ) ) {
4783
- throw new Error( 'Invalid timestamp provided' );
4777
+ export async function convertTimestampToDateTime( timestamp ) {
4778
+ let date;
4779
+ if ( typeof timestamp === 'string' ) {
4780
+ date = new Date( timestamp );
4781
+ if ( isNaN( date.getTime() ) ) {
4782
+ throw new Error( 'Invalid ISO string timestamp provided' );
4783
+ }
4784
+ } else if ( typeof timestamp === 'number' ) { // Handle Unix timestamp input (e.g., 1727785440597)
4785
+ if ( timestamp.toString().length <= 10 ) {
4786
+ timestamp *= 1000; // Convert seconds to milliseconds
4787
+ }
4788
+ date = new Date( timestamp );
4789
+ } else { // Handle invalid input type
4790
+ throw new Error( 'Invalid input: Timestamp must be a valid ISO string or number' );
4784
4791
  }
4785
-
4786
- // Format the date and time components
4787
- const year = date.getFullYear();
4788
- const month = ( '0' + ( date.getMonth() + 1 ) ).slice( -2 ); // Months are zero-based
4789
- const day = ( '0' + date.getDate() ).slice( -2 );
4790
-
4791
- const hours = ( '0' + date.getHours() ).slice( -2 );
4792
- const minutes = ( '0' + date.getMinutes() ).slice( -2 );
4793
- const seconds = ( '0' + date.getSeconds() ).slice( -2 );
4794
-
4795
- // Return formatted date and time string
4792
+ const timeOffset = ( 5 * 60 * 60 * 1000 ) + ( 30 * 60 * 1000 ); // 5 hours and 30 minutes in milliseconds
4793
+ const adjustedTimestamp = date.getTime() + timeOffset;
4794
+ const adjustedDate = new Date( adjustedTimestamp );
4795
+ const year = adjustedDate.getFullYear();
4796
+ const month = ( '0' + ( adjustedDate.getMonth() + 1 ) ).slice( -2 ); // Months are zero-based
4797
+ const day = ( '0' + adjustedDate.getDate() ).slice( -2 );
4798
+
4799
+ const hours = ( '0' + adjustedDate.getHours() ).slice( -2 );
4800
+ const minutes = ( '0' + adjustedDate.getMinutes() ).slice( -2 );
4801
+ const seconds = ( '0' + adjustedDate.getSeconds() ).slice( -2 );
4796
4802
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
4797
4803
  }
4798
4804
 
@@ -3077,7 +3077,7 @@ export async function userMetrics( req, res ) {
3077
3077
  'Check Intime': '$checkIntime',
3078
3078
  'Check OutTime': '$checkOutTime',
3079
3079
  'Working Hours': '$workingHours',
3080
- 'Audited Date': { $dateToString: { format: '%Y,%b %d', date: '$createdAt' } },
3080
+ 'Audited Date': { $dateToString: { format: '%Y-%m-%d', date: '$createdAt' } },
3081
3081
  // 'Mapping Percentage': '$mappingPerc',
3082
3082
  };
3083
3083
  const YesNo = {
@@ -3089,7 +3089,7 @@ export async function userMetrics( req, res ) {
3089
3089
  'Check Intime': '$checkIntime',
3090
3090
  'Check OutTime': '$checkOutTime',
3091
3091
  'Working Hours': '$workingHours',
3092
- 'Audited Date': { $dateToString: { format: '%Y,%b %d', date: '$createdAt' } },
3092
+ 'Audited Date': { $dateToString: { format: '%Y-%m-%d', date: '$createdAt' } },
3093
3093
  // 'Mapping Percentage': '$mappingPerc',
3094
3094
  };
3095
3095
  [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?