tango-app-api-client 3.0.4 → 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 +3 -3
- package/src/controllers/client.controllers.js +283 -28
- package/src/dtos/client.dtos.js +20 -3
- package/src/routes/client.routes.js +4 -3
- package/src/service/client.service.js +4 -0
- package/src/service/user.service.js +4 -0
- package/src/service/userPermission.service.js +0 -5
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,39 +1,31 @@
|
|
|
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';
|
|
7
7
|
import { findOneStandaredRole } from '../service/standaredRole.service.js';
|
|
8
|
-
import { createUserPermission } from '../service/userPermission.service.js';
|
|
9
8
|
|
|
10
9
|
export async function create( req, res ) {
|
|
11
10
|
try {
|
|
12
11
|
const inputData = req.body;
|
|
13
|
-
const query ={ clientName: inputData.clientName };
|
|
12
|
+
const query = { clientName: inputData.clientName };
|
|
14
13
|
const leadRecord = await findOne( query );
|
|
15
|
-
const tangoId = await getClientCount() +1;
|
|
16
|
-
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, '' );
|
|
17
16
|
const product = leadRecord?.planDetails?.product.map( ( value ) => ( { productName: value } ) );
|
|
18
17
|
const password = await encrypt( leadRecord?.mobileNumber.toString() );
|
|
19
|
-
const
|
|
20
|
-
|
|
18
|
+
const getPermission = await findOneStandaredRole( { roleName: 'superadmin', clientType: 'client' }, { permission: 1 } );
|
|
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,
|
|
24
24
|
role: 'superadmin',
|
|
25
25
|
userType: 'client',
|
|
26
|
-
};
|
|
27
|
-
const user = await createUser( userRecord );
|
|
28
|
-
const getPermission = await findOneStandaredRole( { roleName: 'superadmin', clientType: 'client' }, { permission: 1 } );
|
|
29
|
-
const permissionRecord ={
|
|
30
|
-
userName: user?.userName,
|
|
31
|
-
email: user?.email,
|
|
32
|
-
role: user?.role,
|
|
33
|
-
userType: user?.userType,
|
|
34
26
|
permission: getPermission?.permission,
|
|
35
27
|
};
|
|
36
|
-
await
|
|
28
|
+
const user = await createUser( userRecord );
|
|
37
29
|
const record = {
|
|
38
30
|
'clientName': leadRecord.clientName,
|
|
39
31
|
'clientId': String( tangoId ),
|
|
@@ -54,7 +46,7 @@ export async function create( req, res ) {
|
|
|
54
46
|
const insertClient = await insert( record );
|
|
55
47
|
if ( insertClient ) {
|
|
56
48
|
await createAuditQueue( generatedName );
|
|
57
|
-
return res.sendSuccess( { result:
|
|
49
|
+
return res.sendSuccess( { result: { clientId: String( tangoId ) } } );
|
|
58
50
|
}
|
|
59
51
|
} catch ( error ) {
|
|
60
52
|
logger.info( { error: error, message: req.body, function: 'create' } );
|
|
@@ -68,7 +60,7 @@ export async function changeStatus( req, res, next ) {
|
|
|
68
60
|
const query = {
|
|
69
61
|
clientName: inputData.clientName,
|
|
70
62
|
};
|
|
71
|
-
const record= {
|
|
63
|
+
const record = {
|
|
72
64
|
status: inputData.status,
|
|
73
65
|
};
|
|
74
66
|
const result = await update( query, record );
|
|
@@ -217,8 +209,16 @@ export async function detailedAllClientCount( req, res ) {
|
|
|
217
209
|
}
|
|
218
210
|
}
|
|
219
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
|
+
|
|
220
218
|
export async function updateBrandInfo( req, res ) {
|
|
221
219
|
try {
|
|
220
|
+
let updateKeys = [];
|
|
221
|
+
|
|
222
222
|
if ( req.files?.logo ) {
|
|
223
223
|
const uploadDataParams = {
|
|
224
224
|
Bucket: 'sandbox-tango-client',
|
|
@@ -227,13 +227,37 @@ export async function updateBrandInfo( req, res ) {
|
|
|
227
227
|
ContentType: req.files.logo.mimetype,
|
|
228
228
|
body: req.files.logo.data,
|
|
229
229
|
};
|
|
230
|
+
updateKeys.push( 'Logo' );
|
|
230
231
|
await fileUpload( uploadDataParams );
|
|
231
232
|
}
|
|
232
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
|
+
|
|
233
257
|
const updateAck = await brandInfoUpdate( {
|
|
234
258
|
clientId: req.params?.id, registeredCompanyName: req.body?.registeredCompanyName, industry: req.body?.industry,
|
|
235
259
|
clientType: req.body?.clientType, registeredAddress: req.body?.registeredAddress, headQuarters: req.body?.headQuarters,
|
|
236
|
-
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,
|
|
237
261
|
} );
|
|
238
262
|
if ( updateAck ) {
|
|
239
263
|
res.sendSuccess( { result: 'Updated Successfully' } );
|
|
@@ -246,6 +270,8 @@ export async function updateBrandInfo( req, res ) {
|
|
|
246
270
|
|
|
247
271
|
export async function updateBillingDetails( req, res ) {
|
|
248
272
|
try {
|
|
273
|
+
let updateKeys = [];
|
|
274
|
+
|
|
249
275
|
if ( req.files?.gstCertificate ) {
|
|
250
276
|
const uploadDataParams = {
|
|
251
277
|
Bucket: 'sandbox-tango-client',
|
|
@@ -254,9 +280,31 @@ export async function updateBillingDetails( req, res ) {
|
|
|
254
280
|
ContentType: req.files.gstCertificate.mimetype,
|
|
255
281
|
body: req.files.gstCertificate.data,
|
|
256
282
|
};
|
|
283
|
+
updateKeys.push( 'GST certificate' );
|
|
257
284
|
await fileUpload( uploadDataParams );
|
|
258
285
|
}
|
|
259
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
|
+
|
|
260
308
|
const updateAck = await billingDetailsUpdate( {
|
|
261
309
|
clientId: req.params?.id, tradeName: req.body?.tradeName, gstNumber: req.body?.gstNumber,
|
|
262
310
|
authorityName: req.body?.authorityName, authorityEmail: req.body?.authorityEmail, billingAddress: req.body?.billingAddress,
|
|
@@ -273,6 +321,27 @@ export async function updateBillingDetails( req, res ) {
|
|
|
273
321
|
|
|
274
322
|
export async function updateSignatoryDetails( req, res ) {
|
|
275
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 );
|
|
276
345
|
const updateAck = await signatoryDetailsUpdate( {
|
|
277
346
|
clientId: req.params?.id, name: req.body?.name, email: req.body?.email,
|
|
278
347
|
number: req.body?.number, designation: req.body?.designation,
|
|
@@ -294,6 +363,28 @@ export async function updateTicketConfiguration( req, res ) {
|
|
|
294
363
|
isRefreshAlert: req.body?.isRefreshAlert, isStatusCheckAlert: req.body?.isStatusCheckAlert, rcaTicketAssign: req.body?.rcaTicketAssign, reTrain: req.body?.reTrain,
|
|
295
364
|
refreshAlert: req.body?.refreshAlert, sendToAdmin: req.body?.sendToAdmin, sendToUser: req.body?.sendToUser, statusCheckAlert: req.body?.statusCheckAlert,
|
|
296
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
|
+
|
|
297
388
|
if ( updateAck ) {
|
|
298
389
|
res.sendSuccess( { result: 'Updated Successfully' } );
|
|
299
390
|
}
|
|
@@ -311,6 +402,29 @@ export async function updateFeatureConfiguration( req, res ) {
|
|
|
311
402
|
conversionValue: req.body?.conversionValue, infraAlertCondition: req.body?.infraAlertCondition, infraAlertValue: req.body?.infraAlertValue, isFootfallDirectory: req.body?.isFootfallDirectory,
|
|
312
403
|
isNormalized: req.body?.isNormalized, isPasserByData: req.body?.isPasserByData, missedOpportunityCalculation: req.body?.missedOpportunityCalculation, open: req.body?.open,
|
|
313
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
|
+
|
|
314
428
|
if ( updateAck ) {
|
|
315
429
|
res.sendSuccess( { result: 'Updated Successfully' } );
|
|
316
430
|
}
|
|
@@ -325,6 +439,31 @@ export async function domainDetailsConfiguration( req, res ) {
|
|
|
325
439
|
const updateAck = await domainDetailsConfigurationUpdate( {
|
|
326
440
|
clientId: req.params?.id, domainName: req.body?.domainName, isEnable: req.body?.isEnable,
|
|
327
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 );
|
|
328
467
|
if ( updateAck ) {
|
|
329
468
|
res.sendSuccess( { result: 'Updated Successfully' } );
|
|
330
469
|
}
|
|
@@ -350,6 +489,8 @@ export async function userConfiguration( req, res ) {
|
|
|
350
489
|
|
|
351
490
|
export async function updateDocuments( req, res ) {
|
|
352
491
|
try {
|
|
492
|
+
let updateKeys = [];
|
|
493
|
+
|
|
353
494
|
if ( req.files?.addressDoc ) {
|
|
354
495
|
const uploadDataParams = {
|
|
355
496
|
Bucket: 'sandbox-tango-client',
|
|
@@ -358,6 +499,9 @@ export async function updateDocuments( req, res ) {
|
|
|
358
499
|
ContentType: req.files.addressDoc.mimetype,
|
|
359
500
|
body: req.files.addressDoc.data,
|
|
360
501
|
};
|
|
502
|
+
|
|
503
|
+
updateKeys.push( 'Address certificate' );
|
|
504
|
+
|
|
361
505
|
await fileUpload( uploadDataParams );
|
|
362
506
|
}
|
|
363
507
|
if ( req.files?.gstDoc ) {
|
|
@@ -368,6 +512,9 @@ export async function updateDocuments( req, res ) {
|
|
|
368
512
|
ContentType: req.files.gstDoc.mimetype,
|
|
369
513
|
body: req.files.gstDoc.data,
|
|
370
514
|
};
|
|
515
|
+
|
|
516
|
+
updateKeys.push( 'GST certificate' );
|
|
517
|
+
|
|
371
518
|
await fileUpload( uploadDataParams );
|
|
372
519
|
}
|
|
373
520
|
if ( req.files?.panDoc ) {
|
|
@@ -378,6 +525,9 @@ export async function updateDocuments( req, res ) {
|
|
|
378
525
|
ContentType: req.files.panDoc.mimetype,
|
|
379
526
|
body: req.files.panDoc.data,
|
|
380
527
|
};
|
|
528
|
+
|
|
529
|
+
updateKeys.push( 'PAN certificate' );
|
|
530
|
+
|
|
381
531
|
await fileUpload( uploadDataParams );
|
|
382
532
|
}
|
|
383
533
|
if ( req.files?.cinDoc ) {
|
|
@@ -388,6 +538,9 @@ export async function updateDocuments( req, res ) {
|
|
|
388
538
|
ContentType: req.files.cinDoc.mimetype,
|
|
389
539
|
body: req.files.cinDoc.data,
|
|
390
540
|
};
|
|
541
|
+
|
|
542
|
+
updateKeys.push( 'CIN certificate' );
|
|
543
|
+
|
|
391
544
|
await fileUpload( uploadDataParams );
|
|
392
545
|
}
|
|
393
546
|
|
|
@@ -397,8 +550,31 @@ export async function updateDocuments( req, res ) {
|
|
|
397
550
|
gstDoc: req.files?.gstDoc ? `gstCertificate.${req.files?.gstDoc.name.split( '.' )[1]}` : undefined,
|
|
398
551
|
panDoc: req.files?.panDoc ? `panCertificate.${req.files?.panDoc.name.split( '.' )[1]}` : undefined,
|
|
399
552
|
cinDoc: req.files?.cinDoc ? `cinCertificate.${req.files?.cinDoc.name.split( '.' )[1]}` : undefined,
|
|
400
|
-
|
|
401
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
|
+
|
|
402
578
|
if ( updateAck ) {
|
|
403
579
|
res.sendSuccess( { result: 'Updated Successfully' } );
|
|
404
580
|
}
|
|
@@ -440,6 +616,29 @@ export async function auditConfiguration( req, res ) {
|
|
|
440
616
|
ratio: normalizeNumber( req.body[i].ratio, 0, 100 ),
|
|
441
617
|
} );
|
|
442
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
|
+
|
|
443
642
|
res.sendSuccess( { result: 'Updated Successfully' } );
|
|
444
643
|
} catch ( error ) {
|
|
445
644
|
logger.error( { error: error, message: req.params, function: 'auditConfiguration' } );
|
|
@@ -467,8 +666,8 @@ export async function clientList( req, res ) {
|
|
|
467
666
|
try {
|
|
468
667
|
const inputData = req.body;
|
|
469
668
|
let clientQuery = [];
|
|
470
|
-
const limit =inputData.limit || 10;
|
|
471
|
-
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;
|
|
472
671
|
if ( inputData.filterByPaymentStatus ) {
|
|
473
672
|
clientQuery.push(
|
|
474
673
|
{
|
|
@@ -546,14 +745,14 @@ export async function clientList( req, res ) {
|
|
|
546
745
|
const clientListChunk = await chunkArray( client, 10 );
|
|
547
746
|
const promises = clientListChunk.map( async ( chunk ) => {
|
|
548
747
|
const list = [];
|
|
549
|
-
for ( let i = 0; i< chunk.length; i++ ) {
|
|
748
|
+
for ( let i = 0; i < chunk.length; i++ ) {
|
|
550
749
|
list.push( chunk[i].clientId );
|
|
551
750
|
}
|
|
552
751
|
return list;
|
|
553
752
|
} );
|
|
554
753
|
const clientList = await Promise.all( promises );
|
|
555
754
|
clientList.flat();
|
|
556
|
-
const storeQuery =[
|
|
755
|
+
const storeQuery = [
|
|
557
756
|
{
|
|
558
757
|
$match: {
|
|
559
758
|
$and: [
|
|
@@ -573,7 +772,7 @@ export async function clientList( req, res ) {
|
|
|
573
772
|
},
|
|
574
773
|
];
|
|
575
774
|
|
|
576
|
-
const cameraQuery =[
|
|
775
|
+
const cameraQuery = [
|
|
577
776
|
{
|
|
578
777
|
$match: {
|
|
579
778
|
$and: [
|
|
@@ -595,7 +794,7 @@ export async function clientList( req, res ) {
|
|
|
595
794
|
|
|
596
795
|
const activeStoreCount = await aggregateStore( storeQuery );
|
|
597
796
|
const activeCameraCount = await aggregateCamera( cameraQuery );
|
|
598
|
-
const result =_.values(
|
|
797
|
+
const result = _.values(
|
|
599
798
|
_.merge(
|
|
600
799
|
_.keyBy( client, 'clientId' ),
|
|
601
800
|
_.keyBy( activeStoreCount, 'clientId' ),
|
|
@@ -606,7 +805,7 @@ export async function clientList( req, res ) {
|
|
|
606
805
|
const resultChunk = await chunkArray( result, 10 );
|
|
607
806
|
const promises = resultChunk.map( async ( chunk ) => {
|
|
608
807
|
const list = [];
|
|
609
|
-
for ( let i = 0; i< chunk.length; i++ ) {
|
|
808
|
+
for ( let i = 0; i < chunk.length; i++ ) {
|
|
610
809
|
list.push( {
|
|
611
810
|
'client Name': chunk[i].clientName,
|
|
612
811
|
'client Id': chunk[i].clientId,
|
|
@@ -669,3 +868,59 @@ export async function detailedClientCount( req, res ) {
|
|
|
669
868
|
return res.sendError( error, 500 );
|
|
670
869
|
}
|
|
671
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
|
+
}
|