tango-app-api-client 3.3.3-beta.17 → 3.3.3-beta.18

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.17",
3
+ "version": "3.3.3-beta.18",
4
4
  "description": "client",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -2030,9 +2030,37 @@ export async function detailedClientCount( req, res ) {
2030
2030
  }
2031
2031
  }
2032
2032
 
2033
- export async function getActivityLogs( req, res ) {
2033
+ export async function getActivityLogs1( req, res ) {
2034
2034
  try {
2035
+ const inputData = req.body;
2035
2036
  const openSearch = JSON.parse( process.env.OPENSEARCH );
2037
+ const clientQuery =[
2038
+ {
2039
+ $match: {
2040
+ $and: [
2041
+ {
2042
+ clientId: { $in: inputData },
2043
+ },
2044
+ ],
2045
+ },
2046
+ },
2047
+ {
2048
+ $group: {
2049
+ _id: null,
2050
+ clientName: { $push: '$clientName' },
2051
+ },
2052
+ },
2053
+ {
2054
+ $project: {
2055
+ _id: 0,
2056
+ clientName: 1,
2057
+ },
2058
+ },
2059
+ ];
2060
+ const getClientName = await aggregateClient( clientQuery );
2061
+ if ( getClientName?.length == 0 || getClientName[0]?.clientName?.length ===0 ) {
2062
+ return res.sendError( 'No Data Found', 204 );
2063
+ }
2036
2064
  const query = {
2037
2065
  '_source': [
2038
2066
  'userId', 'userName', 'email', 'date', 'logType', 'logSubType',
@@ -2040,13 +2068,27 @@ export async function getActivityLogs( req, res ) {
2040
2068
  ],
2041
2069
  'query': {
2042
2070
  'bool': {
2043
- 'must': [
2071
+ // 'must': [
2072
+ // {
2073
+ // 'terms': {
2074
+ // 'clientId.keyword': [ req.body.clientId ],
2075
+ // },
2076
+ // },
2077
+ // ],
2078
+
2079
+ 'should': [
2044
2080
  {
2045
2081
  'terms': {
2046
- 'clientId.keyword': [ req.body.clientId ],
2082
+ 'clientId.keyword': [ inputData.clientId ],
2083
+ },
2084
+ },
2085
+ {
2086
+ 'terms': {
2087
+ 'clientName.keyword': [ getClientName[0].clientName ], // Add clientName condition
2047
2088
  },
2048
2089
  },
2049
2090
  ],
2091
+ 'minimum_should_match': 1, // Ensures at least one condition must match
2050
2092
  },
2051
2093
  },
2052
2094
  'from': ( req.body.offset - 1 ) * req.body.limit,
@@ -2105,7 +2147,7 @@ export async function getActivityLogs( req, res ) {
2105
2147
  const logType =hit?._source?.logType;
2106
2148
 
2107
2149
  const logSubType =hit?._source?.logSubType;
2108
- respo = findDifferences( previous, current, logType, logSubType );
2150
+ respo = findDifferences1( previous, current, logType, logSubType );
2109
2151
  hit._source.updatedValue = respo;
2110
2152
  temp.push( hit?._source );
2111
2153
  hit._source.changes =logSubType === 'ticketConfig'? Object.keys( respo ).map( ( item ) => item ) : hit._source.changes;
@@ -2125,7 +2167,7 @@ export async function getActivityLogs( req, res ) {
2125
2167
  }
2126
2168
 
2127
2169
 
2128
- function findDifferences( previous, current, logType, logSubType, path = '' ) {
2170
+ function findDifferences1( previous, current, logType, logSubType, path = '' ) {
2129
2171
  const dbKeys = JSON.parse( process.env.DB_KEYS );
2130
2172
  const ignoredKeys = new Set( [
2131
2173
  '_id', 'updatedAt', 'createdAt', 'password', 'clientId',
@@ -2159,11 +2201,11 @@ function findDifferences( previous, current, logType, logSubType, path = '' ) {
2159
2201
 
2160
2202
  // differences[`${path}${key}`] = { previous: removed.length> 0 ? prevValue.join( ',' ): prevValue.join( ', ' ) :, current: added.length > 0? addedUsers.join( ', ' ) : currValue.join( ',' ) } : null;
2161
2203
  } else {
2162
- const nestedDiffs = findDifferences( prevValue, currValue, logType, logSubType, `${path}${key}.` );
2204
+ const nestedDiffs = findDifferences1( prevValue, currValue, logType, logSubType, `${path}${key}.` );
2163
2205
  Object.assign( differences, nestedDiffs );
2164
2206
  }
2165
2207
  } else {
2166
- const nestedDiffs = findDifferences( prevValue, currValue, logType, logSubType, `${path}${key}.` );
2208
+ const nestedDiffs = findDifferences1( prevValue, currValue, logType, logSubType, `${path}${key}.` );
2167
2209
  Object.assign( differences, nestedDiffs );
2168
2210
  }
2169
2211
  } else if ( prevValue !== currValue ) {
@@ -2259,6 +2301,149 @@ function getUserFriendlyKey( keyPath, mapping ) {
2259
2301
  return typeof value === 'string' ? value : keyPath; // Return mapped value or original key
2260
2302
  }
2261
2303
 
2304
+ export async function getActivityLogs( req, res ) {
2305
+ try {
2306
+ const inputData = req.body;
2307
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
2308
+ const clientQuery =[
2309
+ {
2310
+ $match: {
2311
+ $and: [
2312
+ {
2313
+ clientId: { $eq: inputData.clientId },
2314
+ },
2315
+ ],
2316
+ },
2317
+ },
2318
+ {
2319
+ $group: {
2320
+ _id: null,
2321
+ clientName: { $push: '$clientName' },
2322
+ },
2323
+ },
2324
+ {
2325
+ $project: {
2326
+ _id: 0,
2327
+ clientName: 1,
2328
+ },
2329
+ },
2330
+ ];
2331
+ const getClientName = await aggregateClient( clientQuery );
2332
+ if ( getClientName?.length == 0 || getClientName[0]?.clientName?.length ===0 ) {
2333
+ return res.sendError( 'No Data Found', 204 );
2334
+ }
2335
+ const query = {
2336
+ '_source': [
2337
+ 'userId', 'userName', 'email', 'date', 'logType', 'logSubType',
2338
+ 'changes', 'eventType', 'previous', 'current', 'oldData', 'newData',
2339
+ ],
2340
+ 'query': {
2341
+ 'bool': {
2342
+ 'must': [
2343
+ {
2344
+ 'terms': {
2345
+ 'clientId.keyword': [ inputData.clientId ],
2346
+ },
2347
+ },
2348
+
2349
+ ],
2350
+ 'should': [
2351
+ {
2352
+ 'terms': {
2353
+ 'clientName.keyword': getClientName[0].clientName, // Add clientName condition
2354
+ },
2355
+ },
2356
+ ],
2357
+ },
2358
+ },
2359
+ 'from': ( req.body.offset - 1 ) * req.body.limit,
2360
+ 'size': req.body.limit,
2361
+ 'sort': [
2362
+ {
2363
+ 'date': {
2364
+ 'order': 'desc',
2365
+ },
2366
+ },
2367
+ ],
2368
+ };
2369
+
2370
+ if ( req.body?.logTypeFilters?.length ) {
2371
+ query.query.bool.must.push(
2372
+ {
2373
+ 'terms': {
2374
+ 'logType.keyword': req.body.logTypeFilters,
2375
+ },
2376
+ },
2377
+ );
2378
+ }
2379
+
2380
+ if ( req.body?.startDate || req.body?.endDate ) {
2381
+ query.query.bool.must.push( {
2382
+ 'range': {
2383
+ 'date': {
2384
+ 'gte': req.body?.startDate ? req.body.startDate : '',
2385
+ 'lte': req.body?.endDate ? req.body.endDate : '',
2386
+ },
2387
+ },
2388
+ } );
2389
+ }
2390
+
2391
+ query.query.bool.must.push(
2392
+ {
2393
+ 'terms': {
2394
+ 'showTo.keyword': [ req.user.userType ],
2395
+ },
2396
+ },
2397
+ );
2398
+
2399
+ const logs = await getOpenSearchData( openSearch.activityLog, query );
2400
+
2401
+ const hits = logs?.body?.hits?.hits;
2402
+ const totalDocuments = logs?.body?.hits?.total?.value;
2403
+
2404
+ let temp = [];
2405
+ if ( totalDocuments ) {
2406
+ hits.map( ( hit, i ) => {
2407
+ let respo ={};
2408
+ hit._source.logSubType = hit._source.logSubType === 'documentUpload'? 'documentsUpload': hit._source.logSubType === 'domainDetails'? 'securityFeatures': hit?._source?.logSubType;
2409
+ if ( ( ( hit?._source?.eventType ).match( /update/ ) || ( hit?._source?.eventType ).match( /edit/ ) )&& hit?._source?.previous ) {
2410
+ const previous = hit?._source?.oldData;
2411
+ const current=hit?._source?.newData;
2412
+ respo = findDifferences( previous, current );
2413
+ hit._source.updatedValue = respo;
2414
+ temp.push( hit?._source );
2415
+ // hit._source.changes =logSubType === 'ticketConfig'? Object.keys( respo ).map( ( item ) => item ) : hit._source.changes;
2416
+ } else {
2417
+ temp.push( hit?._source );
2418
+ }
2419
+ },
2420
+ );
2421
+ res.sendSuccess( { data: temp, count: totalDocuments } );
2422
+ } else {
2423
+ res.sendError( 'No data found', 204 );
2424
+ }
2425
+ } catch ( error ) {
2426
+ logger.error( { error: error, message: req.body, function: 'getActivityLogs' } );
2427
+ return res.sendError( 'Internal Server Error', 500 );
2428
+ }
2429
+ }
2430
+
2431
+ function findDifferences( obj1, obj2 ) {
2432
+ let differences = {};
2433
+
2434
+ for ( let key in obj1 ) {
2435
+ if ( obj1[key] !== obj2[key] ) {
2436
+ differences[splitCamelCase( key )] = { oldValue: obj1[key], newValue: obj2[key] };
2437
+ }
2438
+ }
2439
+
2440
+ return differences;
2441
+ }
2442
+
2443
+ function splitCamelCase( text ) {
2444
+ return text.replace( /([a-z])([A-Z])/g, '$1 $2' );
2445
+ }
2446
+
2262
2447
  async function postApi( url, data ) {
2263
2448
  const requestOptions = {
2264
2449
  method: 'POST',
@@ -400,20 +400,12 @@ export const clientDocs = {
400
400
  },
401
401
  },
402
402
 
403
- '/v3/client/activity-log/{id}': {
403
+ '/v3/client/activity-log': {
404
404
  post: {
405
405
  tags: [ 'Client' ],
406
406
  description: 'Activity log',
407
407
  operationId: 'activity-log',
408
- parameters: [ {
409
- in: 'path',
410
- name: 'id',
411
- required: true,
412
- description: 'The ID of the client.',
413
- schema: {
414
- type: 'string',
415
- },
416
- } ],
408
+ parameters: [],
417
409
  requestBody: {
418
410
  content: {
419
411
  'application/json': {