tango-app-api-client 3.3.3-beta.16 → 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 +1 -1
- package/src/controllers/client.controllers.js +197 -10
- package/src/docs/client.docs.js +2 -10
package/package.json
CHANGED
|
@@ -1249,7 +1249,7 @@ export async function auditConfiguration( req, res ) {
|
|
|
1249
1249
|
eventType: 'update',
|
|
1250
1250
|
showTo: [ 'tango' ],
|
|
1251
1251
|
changes: [ `Audit config for client id ${req.params?.id}` ],
|
|
1252
|
-
previous: previousClient,
|
|
1252
|
+
previous: previousClient.auditConfigs,
|
|
1253
1253
|
current: {
|
|
1254
1254
|
clientId: req.params?.id,
|
|
1255
1255
|
count: inputData.count,
|
|
@@ -2030,9 +2030,37 @@ export async function detailedClientCount( req, res ) {
|
|
|
2030
2030
|
}
|
|
2031
2031
|
}
|
|
2032
2032
|
|
|
2033
|
-
export async function
|
|
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': [
|
|
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,9 +2147,8 @@ export async function getActivityLogs( req, res ) {
|
|
|
2105
2147
|
const logType =hit?._source?.logType;
|
|
2106
2148
|
|
|
2107
2149
|
const logSubType =hit?._source?.logSubType;
|
|
2108
|
-
respo =
|
|
2150
|
+
respo = findDifferences1( previous, current, logType, logSubType );
|
|
2109
2151
|
hit._source.updatedValue = respo;
|
|
2110
|
-
// Object.keys( respo ).length === 0?null:
|
|
2111
2152
|
temp.push( hit?._source );
|
|
2112
2153
|
hit._source.changes =logSubType === 'ticketConfig'? Object.keys( respo ).map( ( item ) => item ) : hit._source.changes;
|
|
2113
2154
|
} else {
|
|
@@ -2126,7 +2167,7 @@ export async function getActivityLogs( req, res ) {
|
|
|
2126
2167
|
}
|
|
2127
2168
|
|
|
2128
2169
|
|
|
2129
|
-
function
|
|
2170
|
+
function findDifferences1( previous, current, logType, logSubType, path = '' ) {
|
|
2130
2171
|
const dbKeys = JSON.parse( process.env.DB_KEYS );
|
|
2131
2172
|
const ignoredKeys = new Set( [
|
|
2132
2173
|
'_id', 'updatedAt', 'createdAt', 'password', 'clientId',
|
|
@@ -2159,9 +2200,12 @@ function findDifferences( previous, current, logType, logSubType, path = '' ) {
|
|
|
2159
2200
|
differences[`${path}${key}`] = { previous: prevValue.length> 0 ? prevValue.join( ',' ): null, current: currValue.length > 0? currValue.join( ',' ): null } : null;
|
|
2160
2201
|
|
|
2161
2202
|
// differences[`${path}${key}`] = { previous: removed.length> 0 ? prevValue.join( ',' ): prevValue.join( ', ' ) :, current: added.length > 0? addedUsers.join( ', ' ) : currValue.join( ',' ) } : null;
|
|
2203
|
+
} else {
|
|
2204
|
+
const nestedDiffs = findDifferences1( prevValue, currValue, logType, logSubType, `${path}${key}.` );
|
|
2205
|
+
Object.assign( differences, nestedDiffs );
|
|
2162
2206
|
}
|
|
2163
2207
|
} else {
|
|
2164
|
-
const nestedDiffs =
|
|
2208
|
+
const nestedDiffs = findDifferences1( prevValue, currValue, logType, logSubType, `${path}${key}.` );
|
|
2165
2209
|
Object.assign( differences, nestedDiffs );
|
|
2166
2210
|
}
|
|
2167
2211
|
} else if ( prevValue !== currValue ) {
|
|
@@ -2191,7 +2235,7 @@ function findDifferences( previous, current, logType, logSubType, path = '' ) {
|
|
|
2191
2235
|
if ( userFriendlyKey ) {
|
|
2192
2236
|
newKey = userFriendlyKey;
|
|
2193
2237
|
}
|
|
2194
|
-
const binaryKeys = [ 'Two Factor Authentication', 'Mat Enabled', 'Audit', 'Infra Email Alert', 'Ip Whitelist', 'Excluded Area', 'Passer-by data', 'Normalized data during downtime', 'Billing', 'Camera Blurring', 'Footfall Directory', 'Footfall Directory Audit', 'Footfall Directory Limit', 'NOB Status', 'Traffic', 'Trax', 'Zone V1', 'Zone V2', 'Reports', 'Analyze' ];
|
|
2238
|
+
const binaryKeys = [ 'Two Factor Authentication', 'Mat Enabled', 'Audit Status', 'Infra Email Alert', 'Ip Whitelist', 'Excluded Area', 'Passer-by data', 'Normalized data during downtime', 'Billing', 'Camera Blurring', 'Footfall Directory', 'Footfall Directory Audit', 'Footfall Directory Limit', 'NOB Status', 'Traffic', 'Trax', 'Zone V1', 'Zone V2', 'Reports', 'Analyze' ];
|
|
2195
2239
|
if ( binaryKeys.includes( newKey ) ) {
|
|
2196
2240
|
diff.previous = ( diff.previous == true || diff.previous == 'Enabled' ) ? 'Enabled' : 'Disabled';
|
|
2197
2241
|
diff.current = ( diff.current == true || diff.current == 'Enabled' ) ? 'Enabled' : 'Disabled';
|
|
@@ -2257,6 +2301,149 @@ function getUserFriendlyKey( keyPath, mapping ) {
|
|
|
2257
2301
|
return typeof value === 'string' ? value : keyPath; // Return mapped value or original key
|
|
2258
2302
|
}
|
|
2259
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
|
+
|
|
2260
2447
|
async function postApi( url, data ) {
|
|
2261
2448
|
const requestOptions = {
|
|
2262
2449
|
method: 'POST',
|
|
@@ -2327,7 +2514,7 @@ export async function clientCsmAssignAction( req, res ) {
|
|
|
2327
2514
|
|
|
2328
2515
|
function compareArrayObjects( prevArray, currArray ) {
|
|
2329
2516
|
let changes = {};
|
|
2330
|
-
logger.info( { prevArray: prevArray, currArray: currArray } );
|
|
2517
|
+
// logger.info( { prevArray: prevArray, currArray: currArray } );
|
|
2331
2518
|
// Find the longest array length to avoid index mismatch
|
|
2332
2519
|
let maxLength = Math.max( prevArray.length, currArray.length );
|
|
2333
2520
|
|
package/src/docs/client.docs.js
CHANGED
|
@@ -400,20 +400,12 @@ export const clientDocs = {
|
|
|
400
400
|
},
|
|
401
401
|
},
|
|
402
402
|
|
|
403
|
-
'/v3/client/activity-log
|
|
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': {
|