tango-app-api-client 3.3.3-beta.6 → 3.3.3-beta.7

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-client",
3
- "version": "3.3.3-beta.6",
3
+ "version": "3.3.3-beta.7",
4
4
  "description": "client",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -2015,7 +2015,7 @@ export async function getActivityLogs( req, res ) {
2015
2015
  const query = {
2016
2016
  '_source': [
2017
2017
  'userId', 'userName', 'email', 'date', 'logType', 'logSubType',
2018
- 'changes', 'eventType',
2018
+ 'changes', 'eventType', 'previous', 'current',
2019
2019
  ],
2020
2020
  'query': {
2021
2021
  'bool': {
@@ -2072,9 +2072,36 @@ export async function getActivityLogs( req, res ) {
2072
2072
 
2073
2073
  const hits = logs?.body?.hits?.hits;
2074
2074
  const totalDocuments = logs?.body?.hits?.total?.value;
2075
+ let temp = [];
2075
2076
  if ( totalDocuments ) {
2076
- const dataArray = hits.map( ( hit ) => hit._source );
2077
- res.sendSuccess( { data: dataArray, count: totalDocuments } );
2077
+ hits.map( ( hit, i ) => {
2078
+ temp.push( hit?._source );
2079
+ if ( ( ( hit?._source?.eventType ).match( /update/ ) || ( hit?._source?.eventType ).match( /edit/ ) )&& hit?._source?.previous ) {
2080
+ const previous = removeIndexedKeysAndFlatten( hit?._source?.previous );
2081
+ const current=removeIndexedKeysAndFlatten( hit?._source?.current );
2082
+ delete previous?._id;
2083
+ delete current?._id;
2084
+ delete previous?.updatedAt;
2085
+ delete current?.updatedAt;
2086
+ delete current?.createdAt;
2087
+
2088
+ logger.info( { previous2: hit?._source?.previous, previous: previous, current: hit?._source?.current, current: current } );
2089
+ const diff = Object.entries( current )
2090
+ .reduce( ( acc, [ key, value ] ) => {
2091
+ if ( value !== previous[key] & typeof previous[key] === 'string' ) {
2092
+ acc[key] = { previous: previous[key], current: value };
2093
+ }
2094
+
2095
+ return acc;
2096
+ }, {} );
2097
+ logger.info( { diff: diff } );
2098
+ temp[i].updatedValue = diff;
2099
+ } else {
2100
+ temp.push( hit?._source );
2101
+ }
2102
+ },
2103
+ );
2104
+ res.sendSuccess( { data: temp, count: totalDocuments } );
2078
2105
  } else {
2079
2106
  res.sendError( 'No data found', 204 );
2080
2107
  }
@@ -2083,6 +2110,24 @@ export async function getActivityLogs( req, res ) {
2083
2110
  return res.sendError( 'Internal Server Error', 500 );
2084
2111
  }
2085
2112
  }
2113
+ function removeIndexedKeysAndFlatten( obj ) {
2114
+ const result = {};
2115
+
2116
+ for ( const [ key, value ] of Object.entries( obj ) ) {
2117
+ // Skip numeric keys and preserve arrays intact
2118
+ if ( /^\d+$/.test( key ) ) continue;
2119
+
2120
+ if ( Array.isArray( value ) ) {
2121
+ result[key] = value;
2122
+ } else if ( typeof value === 'object' && value !== null ) {
2123
+ Object.assign( result, removeIndexedKeysAndFlatten( value ) );
2124
+ } else {
2125
+ result[key] = value;
2126
+ }
2127
+ }
2128
+
2129
+ return result;
2130
+ }
2086
2131
 
2087
2132
 
2088
2133
  async function postApi( url, data ) {