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