tango-app-api-client 3.0.5 → 3.0.6
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.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "client",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"lodash": "^4.17.21",
|
|
24
24
|
"mongodb": "^6.3.0",
|
|
25
25
|
"nodemon": "^3.0.3",
|
|
26
|
-
"tango-api-schema": "^2.0.
|
|
27
|
-
"tango-app-api-middleware": "^1.0.
|
|
26
|
+
"tango-api-schema": "^2.0.44",
|
|
27
|
+
"tango-app-api-middleware": "^1.0.29",
|
|
28
28
|
"winston": "^3.11.0",
|
|
29
29
|
"winston-daily-rotate-file": "^5.0.0"
|
|
30
30
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { billingDetailsUpdate, brandInfoUpdate, domainDetailsConfigurationUpdate, featureConfigurationUpdate, getClientData, signatoryDetailsUpdate, ticketConfigurationUpdate, documentsUpdate, getUserData, auditConfigurationUpdate, auditConfigurationGet, CsmUsersGet, OpsUsersGet, userConfigurationUpdate, findClient, aggregateClient, createAuditQueue, findOne, getClientCount, insert, update } from '../service/client.service.js';
|
|
2
|
-
import { checkFileExist, fileUpload, signedUrl, chunkArray, download, logger, encrypt } from 'tango-app-api-middleware';
|
|
3
|
-
import { countDocumentsUser, createUser, findOneUser } from '../service/user.service.js';
|
|
2
|
+
import { checkFileExist, fileUpload, signedUrl, chunkArray, download, logger, encrypt, getOpenSearchData, insertOpenSearchData } from 'tango-app-api-middleware';
|
|
3
|
+
import { countDocumentsUser, createUser, findOneUser, getUserNameEmailById } from '../service/user.service.js';
|
|
4
4
|
import { aggregateStore, countDocumentsStore } from '../service/store.service.js';
|
|
5
5
|
import { aggregateCamera, countDocumentsCamera } from '../service/camera.service.js';
|
|
6
6
|
import _ from 'lodash';
|
|
@@ -9,15 +9,15 @@ import { findOneStandaredRole } from '../service/standaredRole.service.js';
|
|
|
9
9
|
export async function create( req, res ) {
|
|
10
10
|
try {
|
|
11
11
|
const inputData = req.body;
|
|
12
|
-
const query ={ clientName: inputData.clientName };
|
|
12
|
+
const query = { clientName: inputData.clientName };
|
|
13
13
|
const leadRecord = await findOne( query );
|
|
14
|
-
const tangoId = await getClientCount() +1;
|
|
15
|
-
const generatedName =inputData.clientName.replace( /[^A-Z0-9]+/ig, '' );
|
|
14
|
+
const tangoId = await getClientCount() + 1;
|
|
15
|
+
const generatedName = inputData.clientName.replace( /[^A-Z0-9]+/ig, '' );
|
|
16
16
|
const product = leadRecord?.planDetails?.product.map( ( value ) => ( { productName: value } ) );
|
|
17
17
|
const password = await encrypt( leadRecord?.mobileNumber.toString() );
|
|
18
18
|
const getPermission = await findOneStandaredRole( { roleName: 'superadmin', clientType: 'client' }, { permission: 1 } );
|
|
19
|
-
const userRecord ={
|
|
20
|
-
userName: leadRecord?.lastName
|
|
19
|
+
const userRecord = {
|
|
20
|
+
userName: leadRecord?.lastName ? `${inputData.firstName}${inputData.lastName}` : inputData?.firstName,
|
|
21
21
|
email: leadRecord?.corporateEmail,
|
|
22
22
|
password: password,
|
|
23
23
|
mobileNumber: leadRecord?.mobileNumber,
|
|
@@ -46,7 +46,7 @@ export async function create( req, res ) {
|
|
|
46
46
|
const insertClient = await insert( record );
|
|
47
47
|
if ( insertClient ) {
|
|
48
48
|
await createAuditQueue( generatedName );
|
|
49
|
-
return res.sendSuccess( { result:
|
|
49
|
+
return res.sendSuccess( { result: { clientId: String( tangoId ) } } );
|
|
50
50
|
}
|
|
51
51
|
} catch ( error ) {
|
|
52
52
|
logger.info( { error: error, message: req.body, function: 'create' } );
|
|
@@ -60,7 +60,7 @@ export async function changeStatus( req, res, next ) {
|
|
|
60
60
|
const query = {
|
|
61
61
|
clientName: inputData.clientName,
|
|
62
62
|
};
|
|
63
|
-
const record= {
|
|
63
|
+
const record = {
|
|
64
64
|
status: inputData.status,
|
|
65
65
|
};
|
|
66
66
|
const result = await update( query, record );
|
|
@@ -209,8 +209,16 @@ export async function detailedAllClientCount( req, res ) {
|
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
+
function camelCaseToWords( camelCaseString ) {
|
|
213
|
+
const words = camelCaseString.replace( /([A-Z])/g, ' $1' );
|
|
214
|
+
return words.charAt( 0 ).toUpperCase() + words.slice( 1 ).toLowerCase();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
212
218
|
export async function updateBrandInfo( req, res ) {
|
|
213
219
|
try {
|
|
220
|
+
let updateKeys = [];
|
|
221
|
+
|
|
214
222
|
if ( req.files?.logo ) {
|
|
215
223
|
const uploadDataParams = {
|
|
216
224
|
Bucket: 'sandbox-tango-client',
|
|
@@ -219,13 +227,37 @@ export async function updateBrandInfo( req, res ) {
|
|
|
219
227
|
ContentType: req.files.logo.mimetype,
|
|
220
228
|
body: req.files.logo.data,
|
|
221
229
|
};
|
|
230
|
+
updateKeys.push( 'Logo' );
|
|
222
231
|
await fileUpload( uploadDataParams );
|
|
223
232
|
}
|
|
224
233
|
|
|
234
|
+
if ( Object.keys( req.body ).length > 0 ) {
|
|
235
|
+
Object.keys( req.body ).forEach( ( element ) => {
|
|
236
|
+
updateKeys.push( camelCaseToWords( element ) );
|
|
237
|
+
} );
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const user = await getUserNameEmailById( req.userId );
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
const logObj = {
|
|
244
|
+
clientId: req.params?.id,
|
|
245
|
+
userName: user?.userName,
|
|
246
|
+
email: user?.email,
|
|
247
|
+
date: new Date(),
|
|
248
|
+
logType: 'brandDetails',
|
|
249
|
+
logSubType: 'brandInfo',
|
|
250
|
+
changes: updateKeys,
|
|
251
|
+
eventType: 'update',
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
await insertOpenSearchData( 'tango-retail-activity-logs', logObj );
|
|
255
|
+
|
|
256
|
+
|
|
225
257
|
const updateAck = await brandInfoUpdate( {
|
|
226
258
|
clientId: req.params?.id, registeredCompanyName: req.body?.registeredCompanyName, industry: req.body?.industry,
|
|
227
259
|
clientType: req.body?.clientType, registeredAddress: req.body?.registeredAddress, headQuarters: req.body?.headQuarters,
|
|
228
|
-
website: req.body?.website, status: req.body?.status, logo: req.
|
|
260
|
+
website: req.body?.website, status: req.body?.status, logo: req.files?.logo ? `brandLogo.${req.files.logo.name.split( '.' )[1]}` : undefined,
|
|
229
261
|
} );
|
|
230
262
|
if ( updateAck ) {
|
|
231
263
|
res.sendSuccess( { result: 'Updated Successfully' } );
|
|
@@ -238,6 +270,8 @@ export async function updateBrandInfo( req, res ) {
|
|
|
238
270
|
|
|
239
271
|
export async function updateBillingDetails( req, res ) {
|
|
240
272
|
try {
|
|
273
|
+
let updateKeys = [];
|
|
274
|
+
|
|
241
275
|
if ( req.files?.gstCertificate ) {
|
|
242
276
|
const uploadDataParams = {
|
|
243
277
|
Bucket: 'sandbox-tango-client',
|
|
@@ -246,9 +280,31 @@ export async function updateBillingDetails( req, res ) {
|
|
|
246
280
|
ContentType: req.files.gstCertificate.mimetype,
|
|
247
281
|
body: req.files.gstCertificate.data,
|
|
248
282
|
};
|
|
283
|
+
updateKeys.push( 'GST certificate' );
|
|
249
284
|
await fileUpload( uploadDataParams );
|
|
250
285
|
}
|
|
251
286
|
|
|
287
|
+
if ( Object.keys( req.body ).length > 0 ) {
|
|
288
|
+
Object.keys( req.body ).forEach( ( element ) => {
|
|
289
|
+
updateKeys.push( camelCaseToWords( element ) );
|
|
290
|
+
} );
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const user = await getUserNameEmailById( req.userId );
|
|
294
|
+
|
|
295
|
+
const logObj = {
|
|
296
|
+
clientId: req.params?.id,
|
|
297
|
+
userName: user.userName,
|
|
298
|
+
email: user.email,
|
|
299
|
+
date: new Date(),
|
|
300
|
+
logType: 'brandDetails',
|
|
301
|
+
logSubType: 'billingDetails',
|
|
302
|
+
changes: updateKeys,
|
|
303
|
+
eventType: 'update',
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
await insertOpenSearchData( 'tango-retail-activity-logs', logObj );
|
|
307
|
+
|
|
252
308
|
const updateAck = await billingDetailsUpdate( {
|
|
253
309
|
clientId: req.params?.id, tradeName: req.body?.tradeName, gstNumber: req.body?.gstNumber,
|
|
254
310
|
authorityName: req.body?.authorityName, authorityEmail: req.body?.authorityEmail, billingAddress: req.body?.billingAddress,
|
|
@@ -265,6 +321,27 @@ export async function updateBillingDetails( req, res ) {
|
|
|
265
321
|
|
|
266
322
|
export async function updateSignatoryDetails( req, res ) {
|
|
267
323
|
try {
|
|
324
|
+
let updateKeys = [];
|
|
325
|
+
if ( Object.keys( req.body ).length > 0 ) {
|
|
326
|
+
Object.keys( req.body ).forEach( ( element ) => {
|
|
327
|
+
updateKeys.push( camelCaseToWords( element ) );
|
|
328
|
+
} );
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const user = await getUserNameEmailById( req.userId );
|
|
332
|
+
|
|
333
|
+
const logObj = {
|
|
334
|
+
clientId: req.params?.id,
|
|
335
|
+
userName: user.userName,
|
|
336
|
+
email: user.email,
|
|
337
|
+
date: new Date(),
|
|
338
|
+
logType: 'brandDetails',
|
|
339
|
+
logSubType: 'signatoryDetails',
|
|
340
|
+
changes: updateKeys,
|
|
341
|
+
eventType: 'update',
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
await insertOpenSearchData( 'tango-retail-activity-logs', logObj );
|
|
268
345
|
const updateAck = await signatoryDetailsUpdate( {
|
|
269
346
|
clientId: req.params?.id, name: req.body?.name, email: req.body?.email,
|
|
270
347
|
number: req.body?.number, designation: req.body?.designation,
|
|
@@ -286,6 +363,28 @@ export async function updateTicketConfiguration( req, res ) {
|
|
|
286
363
|
isRefreshAlert: req.body?.isRefreshAlert, isStatusCheckAlert: req.body?.isStatusCheckAlert, rcaTicketAssign: req.body?.rcaTicketAssign, reTrain: req.body?.reTrain,
|
|
287
364
|
refreshAlert: req.body?.refreshAlert, sendToAdmin: req.body?.sendToAdmin, sendToUser: req.body?.sendToUser, statusCheckAlert: req.body?.statusCheckAlert,
|
|
288
365
|
} );
|
|
366
|
+
|
|
367
|
+
let updateKeys = [];
|
|
368
|
+
if ( Object.keys( req.body ).length > 0 ) {
|
|
369
|
+
Object.keys( req.body ).forEach( ( element ) => {
|
|
370
|
+
updateKeys.push( camelCaseToWords( element ) );
|
|
371
|
+
} );
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const user = await getUserNameEmailById( req.userId );
|
|
375
|
+
|
|
376
|
+
const logObj = {
|
|
377
|
+
clientId: req.params?.id,
|
|
378
|
+
userName: user.userName,
|
|
379
|
+
email: user.email,
|
|
380
|
+
date: new Date(),
|
|
381
|
+
logType: 'configuration',
|
|
382
|
+
logSubType: 'ticketConfig',
|
|
383
|
+
changes: updateKeys,
|
|
384
|
+
eventType: 'update',
|
|
385
|
+
};
|
|
386
|
+
await insertOpenSearchData( 'tango-retail-activity-logs', logObj );
|
|
387
|
+
|
|
289
388
|
if ( updateAck ) {
|
|
290
389
|
res.sendSuccess( { result: 'Updated Successfully' } );
|
|
291
390
|
}
|
|
@@ -303,6 +402,29 @@ export async function updateFeatureConfiguration( req, res ) {
|
|
|
303
402
|
conversionValue: req.body?.conversionValue, infraAlertCondition: req.body?.infraAlertCondition, infraAlertValue: req.body?.infraAlertValue, isFootfallDirectory: req.body?.isFootfallDirectory,
|
|
304
403
|
isNormalized: req.body?.isNormalized, isPasserByData: req.body?.isPasserByData, missedOpportunityCalculation: req.body?.missedOpportunityCalculation, open: req.body?.open,
|
|
305
404
|
} );
|
|
405
|
+
|
|
406
|
+
let updateKeys = [];
|
|
407
|
+
|
|
408
|
+
if ( Object.keys( req.body ).length > 0 ) {
|
|
409
|
+
Object.keys( req.body ).forEach( ( element ) => {
|
|
410
|
+
updateKeys.push( camelCaseToWords( element ) );
|
|
411
|
+
} );
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const user = await getUserNameEmailById( req.userId );
|
|
415
|
+
|
|
416
|
+
const logObj = {
|
|
417
|
+
clientId: req.params?.id,
|
|
418
|
+
userName: user?.userName,
|
|
419
|
+
email: user?.email,
|
|
420
|
+
date: new Date(),
|
|
421
|
+
logType: 'configuration',
|
|
422
|
+
logSubType: 'featureConfig',
|
|
423
|
+
changes: updateKeys,
|
|
424
|
+
eventType: 'update',
|
|
425
|
+
};
|
|
426
|
+
await insertOpenSearchData( 'tango-retail-activity-logs', logObj );
|
|
427
|
+
|
|
306
428
|
if ( updateAck ) {
|
|
307
429
|
res.sendSuccess( { result: 'Updated Successfully' } );
|
|
308
430
|
}
|
|
@@ -317,6 +439,31 @@ export async function domainDetailsConfiguration( req, res ) {
|
|
|
317
439
|
const updateAck = await domainDetailsConfigurationUpdate( {
|
|
318
440
|
clientId: req.params?.id, domainName: req.body?.domainName, isEnable: req.body?.isEnable,
|
|
319
441
|
} );
|
|
442
|
+
|
|
443
|
+
let updateKeys = [];
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
if ( Object.keys( req.body ).length > 0 ) {
|
|
447
|
+
Object.keys( req.body ).forEach( ( element ) => {
|
|
448
|
+
updateKeys.push( camelCaseToWords( element ) );
|
|
449
|
+
} );
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const user = await getUserNameEmailById( req.userId );
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
const logObj = {
|
|
456
|
+
clientId: req.params?.id,
|
|
457
|
+
userName: user?.userName,
|
|
458
|
+
email: user?.email,
|
|
459
|
+
date: new Date(),
|
|
460
|
+
logType: 'configuration',
|
|
461
|
+
logSubType: 'domainDetails',
|
|
462
|
+
changes: updateKeys,
|
|
463
|
+
eventType: 'update',
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
await insertOpenSearchData( 'tango-retail-activity-logs', logObj );
|
|
320
467
|
if ( updateAck ) {
|
|
321
468
|
res.sendSuccess( { result: 'Updated Successfully' } );
|
|
322
469
|
}
|
|
@@ -342,6 +489,8 @@ export async function userConfiguration( req, res ) {
|
|
|
342
489
|
|
|
343
490
|
export async function updateDocuments( req, res ) {
|
|
344
491
|
try {
|
|
492
|
+
let updateKeys = [];
|
|
493
|
+
|
|
345
494
|
if ( req.files?.addressDoc ) {
|
|
346
495
|
const uploadDataParams = {
|
|
347
496
|
Bucket: 'sandbox-tango-client',
|
|
@@ -350,6 +499,9 @@ export async function updateDocuments( req, res ) {
|
|
|
350
499
|
ContentType: req.files.addressDoc.mimetype,
|
|
351
500
|
body: req.files.addressDoc.data,
|
|
352
501
|
};
|
|
502
|
+
|
|
503
|
+
updateKeys.push( 'Address certificate' );
|
|
504
|
+
|
|
353
505
|
await fileUpload( uploadDataParams );
|
|
354
506
|
}
|
|
355
507
|
if ( req.files?.gstDoc ) {
|
|
@@ -360,6 +512,9 @@ export async function updateDocuments( req, res ) {
|
|
|
360
512
|
ContentType: req.files.gstDoc.mimetype,
|
|
361
513
|
body: req.files.gstDoc.data,
|
|
362
514
|
};
|
|
515
|
+
|
|
516
|
+
updateKeys.push( 'GST certificate' );
|
|
517
|
+
|
|
363
518
|
await fileUpload( uploadDataParams );
|
|
364
519
|
}
|
|
365
520
|
if ( req.files?.panDoc ) {
|
|
@@ -370,6 +525,9 @@ export async function updateDocuments( req, res ) {
|
|
|
370
525
|
ContentType: req.files.panDoc.mimetype,
|
|
371
526
|
body: req.files.panDoc.data,
|
|
372
527
|
};
|
|
528
|
+
|
|
529
|
+
updateKeys.push( 'PAN certificate' );
|
|
530
|
+
|
|
373
531
|
await fileUpload( uploadDataParams );
|
|
374
532
|
}
|
|
375
533
|
if ( req.files?.cinDoc ) {
|
|
@@ -380,6 +538,9 @@ export async function updateDocuments( req, res ) {
|
|
|
380
538
|
ContentType: req.files.cinDoc.mimetype,
|
|
381
539
|
body: req.files.cinDoc.data,
|
|
382
540
|
};
|
|
541
|
+
|
|
542
|
+
updateKeys.push( 'CIN certificate' );
|
|
543
|
+
|
|
383
544
|
await fileUpload( uploadDataParams );
|
|
384
545
|
}
|
|
385
546
|
|
|
@@ -389,8 +550,31 @@ export async function updateDocuments( req, res ) {
|
|
|
389
550
|
gstDoc: req.files?.gstDoc ? `gstCertificate.${req.files?.gstDoc.name.split( '.' )[1]}` : undefined,
|
|
390
551
|
panDoc: req.files?.panDoc ? `panCertificate.${req.files?.panDoc.name.split( '.' )[1]}` : undefined,
|
|
391
552
|
cinDoc: req.files?.cinDoc ? `cinCertificate.${req.files?.cinDoc.name.split( '.' )[1]}` : undefined,
|
|
392
|
-
|
|
393
553
|
} );
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
if ( Object.keys( req.body ).length > 0 ) {
|
|
557
|
+
Object.keys( req.body ).forEach( ( element ) => {
|
|
558
|
+
updateKeys.push( camelCaseToWords( element ) );
|
|
559
|
+
} );
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
const user = await getUserNameEmailById( req.userId );
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
const logObj = {
|
|
566
|
+
clientId: req.params?.id,
|
|
567
|
+
userName: user?.userName,
|
|
568
|
+
email: user?.email,
|
|
569
|
+
date: new Date(),
|
|
570
|
+
logType: 'documents',
|
|
571
|
+
logSubType: 'documentUpload',
|
|
572
|
+
changes: updateKeys,
|
|
573
|
+
eventType: 'update',
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
await insertOpenSearchData( 'tango-retail-activity-logs', logObj );
|
|
577
|
+
|
|
394
578
|
if ( updateAck ) {
|
|
395
579
|
res.sendSuccess( { result: 'Updated Successfully' } );
|
|
396
580
|
}
|
|
@@ -432,6 +616,29 @@ export async function auditConfiguration( req, res ) {
|
|
|
432
616
|
ratio: normalizeNumber( req.body[i].ratio, 0, 100 ),
|
|
433
617
|
} );
|
|
434
618
|
}
|
|
619
|
+
|
|
620
|
+
const user = await getUserNameEmailById( req.userId );
|
|
621
|
+
|
|
622
|
+
const logObj = {
|
|
623
|
+
clientId: req.params?.id,
|
|
624
|
+
userName: user.userName,
|
|
625
|
+
email: user.email,
|
|
626
|
+
date: new Date(),
|
|
627
|
+
logType: 'configuration',
|
|
628
|
+
logSubType: 'auditConfig',
|
|
629
|
+
eventType: 'update',
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
if ( req.body?.length === 1 ) {
|
|
633
|
+
logObj.changes = [ `Audit config for store id ${req.body[0].storeId}` ];
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if ( req.body?.length > 1 ) {
|
|
637
|
+
logObj.changes = [ `Audit config bulk` ];
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
await insertOpenSearchData( 'tango-retail-activity-logs', logObj );
|
|
641
|
+
|
|
435
642
|
res.sendSuccess( { result: 'Updated Successfully' } );
|
|
436
643
|
} catch ( error ) {
|
|
437
644
|
logger.error( { error: error, message: req.params, function: 'auditConfiguration' } );
|
|
@@ -459,8 +666,8 @@ export async function clientList( req, res ) {
|
|
|
459
666
|
try {
|
|
460
667
|
const inputData = req.body;
|
|
461
668
|
let clientQuery = [];
|
|
462
|
-
const limit =inputData.limit || 10;
|
|
463
|
-
const skip = inputData.offset? ( inputData.offset - 1 ) * limit : 0;
|
|
669
|
+
const limit = inputData.limit || 10;
|
|
670
|
+
const skip = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
|
|
464
671
|
if ( inputData.filterByPaymentStatus ) {
|
|
465
672
|
clientQuery.push(
|
|
466
673
|
{
|
|
@@ -538,14 +745,14 @@ export async function clientList( req, res ) {
|
|
|
538
745
|
const clientListChunk = await chunkArray( client, 10 );
|
|
539
746
|
const promises = clientListChunk.map( async ( chunk ) => {
|
|
540
747
|
const list = [];
|
|
541
|
-
for ( let i = 0; i< chunk.length; i++ ) {
|
|
748
|
+
for ( let i = 0; i < chunk.length; i++ ) {
|
|
542
749
|
list.push( chunk[i].clientId );
|
|
543
750
|
}
|
|
544
751
|
return list;
|
|
545
752
|
} );
|
|
546
753
|
const clientList = await Promise.all( promises );
|
|
547
754
|
clientList.flat();
|
|
548
|
-
const storeQuery =[
|
|
755
|
+
const storeQuery = [
|
|
549
756
|
{
|
|
550
757
|
$match: {
|
|
551
758
|
$and: [
|
|
@@ -565,7 +772,7 @@ export async function clientList( req, res ) {
|
|
|
565
772
|
},
|
|
566
773
|
];
|
|
567
774
|
|
|
568
|
-
const cameraQuery =[
|
|
775
|
+
const cameraQuery = [
|
|
569
776
|
{
|
|
570
777
|
$match: {
|
|
571
778
|
$and: [
|
|
@@ -587,7 +794,7 @@ export async function clientList( req, res ) {
|
|
|
587
794
|
|
|
588
795
|
const activeStoreCount = await aggregateStore( storeQuery );
|
|
589
796
|
const activeCameraCount = await aggregateCamera( cameraQuery );
|
|
590
|
-
const result =_.values(
|
|
797
|
+
const result = _.values(
|
|
591
798
|
_.merge(
|
|
592
799
|
_.keyBy( client, 'clientId' ),
|
|
593
800
|
_.keyBy( activeStoreCount, 'clientId' ),
|
|
@@ -598,7 +805,7 @@ export async function clientList( req, res ) {
|
|
|
598
805
|
const resultChunk = await chunkArray( result, 10 );
|
|
599
806
|
const promises = resultChunk.map( async ( chunk ) => {
|
|
600
807
|
const list = [];
|
|
601
|
-
for ( let i = 0; i< chunk.length; i++ ) {
|
|
808
|
+
for ( let i = 0; i < chunk.length; i++ ) {
|
|
602
809
|
list.push( {
|
|
603
810
|
'client Name': chunk[i].clientName,
|
|
604
811
|
'client Id': chunk[i].clientId,
|
|
@@ -661,3 +868,59 @@ export async function detailedClientCount( req, res ) {
|
|
|
661
868
|
return res.sendError( error, 500 );
|
|
662
869
|
}
|
|
663
870
|
}
|
|
871
|
+
|
|
872
|
+
export async function getActivityLogs( req, res ) {
|
|
873
|
+
try {
|
|
874
|
+
const query = {
|
|
875
|
+
'_source': [ 'userId', 'userName', 'email', 'date', 'logType', 'logSubType', 'changes', 'eventType' ],
|
|
876
|
+
'query': {
|
|
877
|
+
'bool': {
|
|
878
|
+
'must': [
|
|
879
|
+
{
|
|
880
|
+
'terms': {
|
|
881
|
+
'clientId.keyword': [ req.body.clientId ],
|
|
882
|
+
},
|
|
883
|
+
},
|
|
884
|
+
],
|
|
885
|
+
},
|
|
886
|
+
},
|
|
887
|
+
'from': ( req.body.offset - 1 ) * req.body.limit,
|
|
888
|
+
'size': req.body.limit,
|
|
889
|
+
};
|
|
890
|
+
|
|
891
|
+
if ( req.body?.logTypeFilters?.length ) {
|
|
892
|
+
query.query.bool.must.push(
|
|
893
|
+
{
|
|
894
|
+
'terms': {
|
|
895
|
+
'logType.keyword': req.body.logTypeFilters,
|
|
896
|
+
},
|
|
897
|
+
},
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
if ( req.body?.startDate || req.body?.endDate ) {
|
|
902
|
+
query.query.bool.must.push( {
|
|
903
|
+
'range': {
|
|
904
|
+
'date': {
|
|
905
|
+
'gte': req.body?.startDate ? req.body.startDate : '',
|
|
906
|
+
'lte': req.body?.endDate ? req.body.endDate : '',
|
|
907
|
+
},
|
|
908
|
+
},
|
|
909
|
+
} );
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
const logs = await getOpenSearchData( 'tango-retail-activity-logs', query );
|
|
913
|
+
|
|
914
|
+
const hits = logs?.body?.hits?.hits;
|
|
915
|
+
const totalDocuments = logs?.body?.hits?.total?.value;
|
|
916
|
+
if ( totalDocuments ) {
|
|
917
|
+
const dataArray = hits.map( ( hit ) => hit._source );
|
|
918
|
+
res.sendSuccess( { data: dataArray, count: totalDocuments } );
|
|
919
|
+
} else {
|
|
920
|
+
res.sendError( 'No data found', 204 );
|
|
921
|
+
}
|
|
922
|
+
} catch ( error ) {
|
|
923
|
+
logger.error( { error: error, message: req.body, function: 'getActivityLogs' } );
|
|
924
|
+
return res.sendError( error, 500 );
|
|
925
|
+
}
|
|
926
|
+
}
|
package/src/dtos/client.dtos.js
CHANGED
|
@@ -119,8 +119,8 @@ export const featureConfigurationValid = {
|
|
|
119
119
|
|
|
120
120
|
export const domainDetailsSchemaBody = joi.object(
|
|
121
121
|
{
|
|
122
|
-
domainName: joi.array().items( joi.string() ).
|
|
123
|
-
isEnable: joi.boolean().
|
|
122
|
+
domainName: joi.array().items( joi.string() ).optional(),
|
|
123
|
+
isEnable: joi.boolean().optional(),
|
|
124
124
|
},
|
|
125
125
|
);
|
|
126
126
|
|
|
@@ -152,7 +152,6 @@ export const userConfigurationValid = {
|
|
|
152
152
|
export const clientCreationSchema = joi.object( {
|
|
153
153
|
status: joi.string().required(),
|
|
154
154
|
clientName: joi.string().required(),
|
|
155
|
-
csm: joi.string().optional(),
|
|
156
155
|
} );
|
|
157
156
|
|
|
158
157
|
export const clientCreationValid = {
|
|
@@ -210,9 +209,14 @@ export const auditConfigSchemaBody = joi.array().items(
|
|
|
210
209
|
).required(),
|
|
211
210
|
).required();
|
|
212
211
|
|
|
212
|
+
export const auditConfigSchemaParam = joi.object( {
|
|
213
|
+
id: joi.string().required(),
|
|
214
|
+
} );
|
|
215
|
+
|
|
213
216
|
|
|
214
217
|
export const auditConfigValid = {
|
|
215
218
|
body: auditConfigSchemaBody,
|
|
219
|
+
params: auditConfigSchemaParam,
|
|
216
220
|
};
|
|
217
221
|
|
|
218
222
|
|
|
@@ -239,3 +243,16 @@ export const clientListSchema = joi.object( {
|
|
|
239
243
|
export const clientListValid = {
|
|
240
244
|
body: clientListSchema,
|
|
241
245
|
};
|
|
246
|
+
|
|
247
|
+
export const activityLogSchema = joi.object( {
|
|
248
|
+
startDate: joi.string().optional(),
|
|
249
|
+
endDate: joi.string().optional(),
|
|
250
|
+
limit: joi.number().required(),
|
|
251
|
+
offset: joi.number().required(),
|
|
252
|
+
clientId: joi.string().required(),
|
|
253
|
+
logTypeFilters: joi.array().optional(),
|
|
254
|
+
} );
|
|
255
|
+
|
|
256
|
+
export const activityLogValid = {
|
|
257
|
+
body: activityLogSchema,
|
|
258
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import { auditConfigValid, billingDetailsValid, brandInfoValid, clientCreationValid, clientDetailsValid, documentsValid, domainDetailsValid, featureConfigurationValid, getAuditConfigValid, signatoryDetailsValid, ticketConfigurationValid, userConfigurationValid } from '../dtos/client.dtos.js';
|
|
4
|
-
import { auditConfiguration, changeStatus, clientDetails, create, domainDetailsConfiguration, getAuditConfiguration, getClients, getCsmUsers, getOpsUsers, updateBillingDetails, updateBrandInfo, updateDocuments, updateFeatureConfiguration, updateSignatoryDetails, updateTicketConfiguration, userConfiguration } from '../controllers/client.controllers.js';
|
|
3
|
+
import { activityLogValid, auditConfigValid, billingDetailsValid, brandInfoValid, clientCreationValid, clientDetailsValid, documentsValid, domainDetailsValid, featureConfigurationValid, getAuditConfigValid, signatoryDetailsValid, ticketConfigurationValid, userConfigurationValid } from '../dtos/client.dtos.js';
|
|
4
|
+
import { auditConfiguration, changeStatus, clientDetails, create, domainDetailsConfiguration, getActivityLogs, getAuditConfiguration, getClients, getCsmUsers, getOpsUsers, updateBillingDetails, updateBrandInfo, updateDocuments, updateFeatureConfiguration, updateSignatoryDetails, updateTicketConfiguration, userConfiguration } from '../controllers/client.controllers.js';
|
|
5
5
|
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
6
6
|
import { clientListValid, detailedClientCountValid } from '../dtos/client.dtos.js';
|
|
7
7
|
import { isclientIdExists, isclientNameExists } from '../validations/client.validations.js';
|
|
@@ -21,11 +21,12 @@ clientRouter.put( '/domain-details/:id', isAllowedSessionHandler, validate( doma
|
|
|
21
21
|
clientRouter.put( '/user-configuration/:id', isAllowedSessionHandler, validate( userConfigurationValid ), userConfiguration );
|
|
22
22
|
clientRouter.put( '/documents/:id', isAllowedSessionHandler, validate( documentsValid ), updateDocuments );
|
|
23
23
|
clientRouter.get( '/audit-configuration/:id', isAllowedSessionHandler, validate( getAuditConfigValid ), getAuditConfiguration );
|
|
24
|
-
clientRouter.post( '/audit-configuration', isAllowedSessionHandler, validate( auditConfigValid ), auditConfiguration );
|
|
24
|
+
clientRouter.post( '/audit-configuration/:id', isAllowedSessionHandler, validate( auditConfigValid ), auditConfiguration );
|
|
25
25
|
clientRouter.get( '/get-csm-users', isAllowedSessionHandler, getCsmUsers );
|
|
26
26
|
clientRouter.get( '/get-ops-users', isAllowedSessionHandler, getOpsUsers );
|
|
27
27
|
clientRouter.get( '/detailed-all-client-count', isAllowedSessionHandler, detailedAllClientCount );
|
|
28
28
|
clientRouter.post( '/client-list', isAllowedSessionHandler, validate( clientListValid ), clientList );
|
|
29
29
|
clientRouter.get( '/detailed-client-count', isAllowedSessionHandler, validate( detailedClientCountValid ), isclientIdExists, detailedClientCount );
|
|
30
|
+
clientRouter.post( '/activity-log', isAllowedSessionHandler, validate( activityLogValid ), getActivityLogs );
|
|
30
31
|
|
|
31
32
|
|
|
@@ -229,6 +229,8 @@ export function CsmUsersGet( ) {
|
|
|
229
229
|
{
|
|
230
230
|
$project: {
|
|
231
231
|
userName: 1,
|
|
232
|
+
email: 1,
|
|
233
|
+
_id: 0,
|
|
232
234
|
},
|
|
233
235
|
},
|
|
234
236
|
],
|
|
@@ -260,6 +262,8 @@ export function OpsUsersGet( ) {
|
|
|
260
262
|
{
|
|
261
263
|
$project: {
|
|
262
264
|
userName: 1,
|
|
265
|
+
email: 1,
|
|
266
|
+
_id: 0,
|
|
263
267
|
},
|
|
264
268
|
},
|
|
265
269
|
],
|
|
@@ -11,3 +11,7 @@ export function countDocumentsUser( query ) {
|
|
|
11
11
|
export async function createUser( record ) {
|
|
12
12
|
return userModel.create( record );
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
export function getUserNameEmailById( objectId ) {
|
|
16
|
+
return userModel.findOne( { _id: objectId }, { userName: 1, email: 1, _id: 0 } );
|
|
17
|
+
}
|