tango-app-api-client 3.0.1 → 3.0.3

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.1",
3
+ "version": "3.0.3",
4
4
  "description": "client",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -14,14 +14,17 @@
14
14
  "license": "ISC",
15
15
  "dependencies": {
16
16
  "aws-sdk": "^2.1560.0",
17
+ "cors": "^2.8.5",
17
18
  "dotenv": "^16.4.4",
18
19
  "express": "^4.18.2",
20
+ "express-fileupload": "^1.4.3",
19
21
  "handlebars": "^4.7.8",
22
+ "joi": "^17.12.1",
20
23
  "lodash": "^4.17.21",
21
24
  "mongodb": "^6.3.0",
22
25
  "nodemon": "^3.0.3",
23
26
  "tango-api-schema": "^2.0.33",
24
- "tango-app-api-middleware": "^1.0.16",
27
+ "tango-app-api-middleware": "^1.0.24",
25
28
  "winston": "^3.11.0",
26
29
  "winston-daily-rotate-file": "^5.0.0"
27
30
  },
@@ -1,5 +1,5 @@
1
- import { logger } from 'tango-app-api-middleware';
2
- import { createAuditQueue, findOne, getClientCount, insert, update, findClient, aggregateClient } from '../service/client.service.js';
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 } from 'tango-app-api-middleware';
3
3
  import { countDocumentsUser, findOneUser } 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';
@@ -77,6 +77,83 @@ export async function getClients( req, res ) {
77
77
  }
78
78
  }
79
79
 
80
+
81
+ export async function clientDetails( req, res ) {
82
+ try {
83
+ const client = await getClientData( { id: req.params.id } );
84
+ if ( client ) {
85
+ const isLogoExist = await checkFileExist( { Bucket: `sandbox-tango-client`, Key: `${client.clientId}/logo/${client.profileDetails?.logo}` } );
86
+ const isGstCertificateExist = await checkFileExist( { Bucket: `sandbox-tango-client`, Key: `${client.clientId}/documents/${client.document?.gst?.path}` } );
87
+ const isAddressCertificateExist = await checkFileExist( { Bucket: `sandbox-tango-client`, Key: `${client.clientId}/documents/${client.document?.addressProof?.path}` } );
88
+ const isPanCertificateExist = await checkFileExist( { Bucket: `sandbox-tango-client`, Key: `${client.clientId}/documents/${client.document?.pan?.path}` } );
89
+ const isCinCertificateExist = await checkFileExist( { Bucket: `sandbox-tango-client`, Key: `${client.clientId}/documents/${client.document?.cin?.path}` } );
90
+ const isContractCertificateExist = await checkFileExist( { Bucket: `sandbox-tango-client`, Key: `documents/contract.pdf` } );
91
+ const isTermsAndConditionsExist = await checkFileExist( { Bucket: `sandbox-tango-client`, Key: `documents/terms&conditions.pdf` } );
92
+
93
+
94
+ if ( isLogoExist ) {
95
+ const signedFilUrl = await signedUrl( { Bucket: 'sandbox-tango-client', file_path: `${client.clientId}/logo/${client.profileDetails?.logo}` } );
96
+ client.profileDetails.logo = signedFilUrl;
97
+ } else {
98
+ client.profileDetails.logo = '';
99
+ }
100
+
101
+ if ( isGstCertificateExist ) {
102
+ const signedFilUrl = await signedUrl( { Bucket: 'sandbox-tango-client', file_path: `${client.clientId}/documents/${client.document?.gst?.path}` } );
103
+ client.document.gst.path = signedFilUrl;
104
+ } else {
105
+ client.document.gst.path = '';
106
+ }
107
+
108
+ if ( isAddressCertificateExist ) {
109
+ const signedFilUrl = await signedUrl( { Bucket: 'sandbox-tango-client', file_path: `${client.clientId}/documents/${client.document?.addressProof?.path}` } );
110
+ client.document.addressProof.path = signedFilUrl;
111
+ } else {
112
+ client.document.addressProof.path = '';
113
+ }
114
+
115
+ if ( isPanCertificateExist ) {
116
+ const signedFilUrl = await signedUrl( { Bucket: 'sandbox-tango-client', file_path: `${client.clientId}/documents/${client.document?.pan?.path}` } );
117
+ client.document.pan.path = signedFilUrl;
118
+ } else {
119
+ client.document.pan.path = '';
120
+ }
121
+
122
+ if ( isCinCertificateExist ) {
123
+ const signedFilUrl = await signedUrl( { Bucket: 'sandbox-tango-client', file_path: `${client.clientId}/documents/${client.document?.cin?.path}` } );
124
+ client.document.cin.path = signedFilUrl;
125
+ } else {
126
+ client.document.cin.path = '';
127
+ }
128
+
129
+ if ( isContractCertificateExist ) {
130
+ const signedFilUrl = await signedUrl( { Bucket: 'sandbox-tango-client', file_path: `documents/contract.pdf` } );
131
+ client._doc.document.contract = signedFilUrl;
132
+ } else {
133
+ client._doc.document.contract = '';
134
+ }
135
+
136
+ if ( isTermsAndConditionsExist ) {
137
+ const signedFilUrl = await signedUrl( { Bucket: 'sandbox-tango-client', file_path: `documents/terms&conditions.pdf` } );
138
+ client._doc.document.termsAndconditions = signedFilUrl;
139
+ } else {
140
+ client._doc.document.termsAndconditions = '';
141
+ }
142
+
143
+ const user = await getUserData( { id: client.userId } );
144
+ const userData = {
145
+ corporateEmail: user?.email,
146
+ countryCode: user?.countryCode,
147
+ mobileNumber: user?.mobileNumber,
148
+ };
149
+ return res.sendSuccess( { userData, ...client._doc } );
150
+ } else {
151
+ return res.sendError( 'Client not found', 404 );
152
+ }
153
+ } catch ( error ) {
154
+ logger.error( { error: error, message: req.params, function: 'clientDetails' } );
155
+ }
156
+ }
80
157
  export async function detailedAllClientCount( req, res ) {
81
158
  try {
82
159
  const query = [
@@ -117,26 +194,298 @@ export async function detailedAllClientCount( req, res ) {
117
194
  }
118
195
  }
119
196
 
197
+ export async function updateBrandInfo( req, res ) {
198
+ try {
199
+ if ( req.files?.logo ) {
200
+ const uploadDataParams = {
201
+ Bucket: 'sandbox-tango-client',
202
+ Key: `${req.params.id}/logo/`,
203
+ fileName: `brandLogo.${req.files.logo.name.split( '.' )[1]}`,
204
+ ContentType: req.files.logo.mimetype,
205
+ body: req.files.logo.data,
206
+ };
207
+ await fileUpload( uploadDataParams );
208
+ }
209
+
210
+ const updateAck = await brandInfoUpdate( {
211
+ clientId: req.params?.id, registeredCompanyName: req.body?.registeredCompanyName, industry: req.body?.industry,
212
+ clientType: req.body?.clientType, registeredAddress: req.body?.registeredAddress, headQuarters: req.body?.headQuarters,
213
+ website: req.body?.website, status: req.body?.status, logo: req.logo?.logo ? `brandLogo.${req.files.logo.name.split( '.' )[1]}` : undefined,
214
+ } );
215
+ if ( updateAck ) {
216
+ res.sendSuccess( { result: 'Updated Successfully' } );
217
+ }
218
+ } catch ( error ) {
219
+ logger.error( { error: error, message: req.params, function: 'updateBrandInfo' } );
220
+ return res.sendError( error, 500 );
221
+ }
222
+ }
223
+
224
+ export async function updateBillingDetails( req, res ) {
225
+ try {
226
+ if ( req.files?.gstCertificate ) {
227
+ const uploadDataParams = {
228
+ Bucket: 'sandbox-tango-client',
229
+ Key: `${req.params.id}/documents/`,
230
+ fileName: `gstCertificate.${req.files.gstCertificate.name.split( '.' )[1]}`,
231
+ ContentType: req.files.gstCertificate.mimetype,
232
+ body: req.files.gstCertificate.data,
233
+ };
234
+ await fileUpload( uploadDataParams );
235
+ }
236
+
237
+ const updateAck = await billingDetailsUpdate( {
238
+ clientId: req.params?.id, tradeName: req.body?.tradeName, gstNumber: req.body?.gstNumber,
239
+ authorityName: req.body?.authorityName, authorityEmail: req.body?.authorityEmail, billingAddress: req.body?.billingAddress,
240
+ gstCertificate: req.files?.gstCertificate ? `gstCertificate.${req.files?.gstCertificate.name.split( '.' )[1]}` : undefined,
241
+ } );
242
+ if ( updateAck ) {
243
+ res.sendSuccess( { result: 'Updated Successfully' } );
244
+ }
245
+ } catch ( error ) {
246
+ logger.error( { error: error, message: req.params, function: 'updateBillingDetails' } );
247
+ return res.sendError( error, 500 );
248
+ }
249
+ }
250
+
251
+ export async function updateSignatoryDetails( req, res ) {
252
+ try {
253
+ const updateAck = await signatoryDetailsUpdate( {
254
+ clientId: req.params?.id, name: req.body?.name, email: req.body?.email,
255
+ number: req.body?.number, designation: req.body?.designation,
256
+ } );
257
+ if ( updateAck ) {
258
+ res.sendSuccess( { result: 'Updated Successfully' } );
259
+ }
260
+ } catch ( error ) {
261
+ logger.error( { error: error, message: req.params, function: 'updateSignatoryDetails' } );
262
+ return res.sendError( error, 500 );
263
+ }
264
+ }
265
+
266
+ export async function updateTicketConfiguration( req, res ) {
267
+ try {
268
+ const updateAck = await ticketConfigurationUpdate( {
269
+ clientId: req.params?.id, MinFilesCount: req.body?.MinFilesCount, accuracyPercentage: req.body?.accuracyPercentage, downTimeType: req.body?.downTimeType,
270
+ infraDownTime: req.body?.infraDownTime, installationReAssign: req.body?.installationReAssign, isRcaTicketAssign: req.body?.isRcaTicketAssign,
271
+ isRefreshAlert: req.body?.isRefreshAlert, isStatusCheckAlert: req.body?.isStatusCheckAlert, rcaTicketAssign: req.body?.rcaTicketAssign, reTrain: req.body?.reTrain,
272
+ refreshAlert: req.body?.refreshAlert, sendToAdmin: req.body?.sendToAdmin, sendToUser: req.body?.sendToUser, statusCheckAlert: req.body?.statusCheckAlert,
273
+ } );
274
+ if ( updateAck ) {
275
+ res.sendSuccess( { result: 'Updated Successfully' } );
276
+ }
277
+ } catch ( error ) {
278
+ logger.error( { error: error, message: req.params, function: 'updateTicketConfiguration' } );
279
+ return res.sendError( error, 500 );
280
+ }
281
+ }
282
+
283
+ export async function updateFeatureConfiguration( req, res ) {
284
+ try {
285
+ const updateAck = await featureConfigurationUpdate( {
286
+ clientId: req.params?.id, billableCalculation: req.body?.billableCalculation, bouncedLimitCondition: req.body?.bouncedLimitCondition, bouncedLimitValue: req.body?.bouncedLimitValue,
287
+ close: req.body?.close, conversionCalculation: req.body?.conversionCalculation, conversionCondition: req.body?.conversionCondition,
288
+ conversionValue: req.body?.conversionValue, infraAlertCondition: req.body?.infraAlertCondition, infraAlertValue: req.body?.infraAlertValue, isFootfallDirectory: req.body?.isFootfallDirectory,
289
+ isNormalized: req.body?.isNormalized, isPasserByData: req.body?.isPasserByData, missedOpportunityCalculation: req.body?.missedOpportunityCalculation, open: req.body?.open,
290
+ } );
291
+ if ( updateAck ) {
292
+ res.sendSuccess( { result: 'Updated Successfully' } );
293
+ }
294
+ } catch ( error ) {
295
+ logger.error( { error: error, message: req.params, function: 'updateTicketConfiguration' } );
296
+ return res.sendError( error, 500 );
297
+ }
298
+ }
299
+
300
+ export async function domainDetailsConfiguration( req, res ) {
301
+ try {
302
+ const updateAck = await domainDetailsConfigurationUpdate( {
303
+ clientId: req.params?.id, domainName: req.body?.domainName, isEnable: req.body?.isEnable,
304
+ } );
305
+ if ( updateAck ) {
306
+ res.sendSuccess( { result: 'Updated Successfully' } );
307
+ }
308
+ } catch ( error ) {
309
+ logger.error( { error: error, message: req.params, function: 'domainDetailsConfiguration' } );
310
+ return res.sendError( error, 500 );
311
+ }
312
+ }
313
+
314
+ export async function userConfiguration( req, res ) {
315
+ try {
316
+ const updateAck = await userConfigurationUpdate( {
317
+ clientId: req.params?.id, csm: req.body?.csm, ops: req.body?.ops,
318
+ } );
319
+ if ( updateAck ) {
320
+ res.sendSuccess( { result: 'Updated Successfully' } );
321
+ }
322
+ } catch ( error ) {
323
+ logger.error( { error: error, message: req.params, function: 'userConfiguration' } );
324
+ return res.sendError( error, 500 );
325
+ }
326
+ }
327
+
328
+ export async function updateDocuments( req, res ) {
329
+ try {
330
+ if ( req.files?.addressDoc ) {
331
+ const uploadDataParams = {
332
+ Bucket: 'sandbox-tango-client',
333
+ Key: `${req.params.id}/documents/`,
334
+ fileName: `addressCertificate.${req.files.addressDoc.name.split( '.' )[1]}`,
335
+ ContentType: req.files.addressDoc.mimetype,
336
+ body: req.files.addressDoc.data,
337
+ };
338
+ await fileUpload( uploadDataParams );
339
+ }
340
+ if ( req.files?.gstDoc ) {
341
+ const uploadDataParams = {
342
+ Bucket: 'sandbox-tango-client',
343
+ Key: `${req.params.id}/documents/`,
344
+ fileName: `gstCertificate.${req.files.gstDoc.name.split( '.' )[1]}`,
345
+ ContentType: req.files.gstDoc.mimetype,
346
+ body: req.files.gstDoc.data,
347
+ };
348
+ await fileUpload( uploadDataParams );
349
+ }
350
+ if ( req.files?.panDoc ) {
351
+ const uploadDataParams = {
352
+ Bucket: 'sandbox-tango-client',
353
+ Key: `${req.params.id}/documents/`,
354
+ fileName: `panCertificate.${req.files.panDoc.name.split( '.' )[1]}`,
355
+ ContentType: req.files.panDoc.mimetype,
356
+ body: req.files.panDoc.data,
357
+ };
358
+ await fileUpload( uploadDataParams );
359
+ }
360
+ if ( req.files?.cinDoc ) {
361
+ const uploadDataParams = {
362
+ Bucket: 'sandbox-tango-client',
363
+ Key: `${req.params.id}/documents/`,
364
+ fileName: `cinCertificate.${req.files.cinDoc.name.split( '.' )[1]}`,
365
+ ContentType: req.files.cinDoc.mimetype,
366
+ body: req.files.cinDoc.data,
367
+ };
368
+ await fileUpload( uploadDataParams );
369
+ }
370
+
371
+ const updateAck = await documentsUpdate( {
372
+ clientId: req.params?.id, gstNumber: req.body.gstNumber, panNumber: req.body.panNumber, cinNumber: req.body.cinNumber,
373
+ addressDoc: req.files?.addressDoc ? `addressCertificate.${req.files?.addressDoc.name.split( '.' )[1]}` : undefined,
374
+ gstDoc: req.files?.gstDoc ? `gstCertificate.${req.files?.gstDoc.name.split( '.' )[1]}` : undefined,
375
+ panDoc: req.files?.panDoc ? `panCertificate.${req.files?.panDoc.name.split( '.' )[1]}` : undefined,
376
+ cinDoc: req.files?.cinDoc ? `cinCertificate.${req.files?.cinDoc.name.split( '.' )[1]}` : undefined,
377
+
378
+ } );
379
+ if ( updateAck ) {
380
+ res.sendSuccess( { result: 'Updated Successfully' } );
381
+ }
382
+ } catch ( error ) {
383
+ logger.error( { error: error, message: req.params, function: 'updateBillingDetails' } );
384
+ return res.sendError( error, 500 );
385
+ }
386
+ }
387
+
388
+ export async function getAuditConfiguration( req, res ) {
389
+ try {
390
+ const auditConfig = await auditConfigurationGet( { storeId: req.params?.id } );
391
+ if ( auditConfig ) {
392
+ const isDocExist = await checkFileExist( { Bucket: `sandbox-tango-client`, Key: `templates/audit_bulk_update.xlsx` } );
393
+ if ( isDocExist ) {
394
+ const signedFilUrl = await signedUrl( { Bucket: 'sandbox-tango-client', file_path: `templates/audit_bulk_update.xlsx` } );
395
+ auditConfig._doc.templateUrl = signedFilUrl;
396
+ } else {
397
+ auditConfig._doc.templateUrl = '';
398
+ }
399
+ res.sendSuccess( auditConfig );
400
+ } else {
401
+ res.sendError( { error: 'Store not found' }, 404 );
402
+ }
403
+ } catch ( error ) {
404
+ logger.error( { error: error, message: req.params, function: 'getAuditConfiguration' } );
405
+ return res.sendError( error, 500 );
406
+ }
407
+ }
408
+
409
+
410
+ export async function auditConfiguration( req, res ) {
411
+ try {
412
+ for ( let i = 0; i < req.body?.length; i++ ) {
413
+ await auditConfigurationUpdate( {
414
+ storeId: req.body[i].storeId,
415
+ count: req.body[i].count,
416
+ iteration: req.body[i].iteration,
417
+ ratio: normalizeNumber( req.body[i].ratio, 0, 100 ),
418
+ } );
419
+ }
420
+ res.sendSuccess( { result: 'Updated Successfully' } );
421
+ } catch ( error ) {
422
+ logger.error( { error: error, message: req.params, function: 'auditConfiguration' } );
423
+ return res.sendError( error, 500 );
424
+ }
425
+ }
426
+
427
+ function normalizeNumber( num, min, max ) {
428
+ return ( ( num - min ) / ( max - min ) ).toFixed( 2 );
429
+ }
430
+
431
+ export async function getCsmUsers( req, res ) {
432
+ try {
433
+ const users = await CsmUsersGet();
434
+ if ( users?.length ) {
435
+ res.sendSuccess( users );
436
+ } else {
437
+ res.sendError( 'No users found', 404 );
438
+ }
439
+ } catch ( error ) {
440
+ logger.error( { error: error, message: req.params, function: 'getAuditConfiguration' } );
441
+ }
442
+ }
120
443
  export async function clientList( req, res ) {
121
444
  try {
122
445
  const inputData = req.body;
446
+ let clientQuery = [];
123
447
  const limit =inputData.limit || 10;
124
448
  const skip = inputData.offset? ( inputData.offset - 1 ) * limit : 0;
125
- let clientQuery = [
126
- {
127
- $project: {
128
- status: 1,
129
- clientName: 1,
130
- clientId: 1,
131
- subscriptionType: 1,
132
- },
133
- },
134
- ];
135
- const clientCount = await aggregateClient( clientQuery );
136
- if ( clientCount.length == 0 ) {
137
- return res.sendError( { error: 'No Data Found' }, 204 );
449
+ if ( inputData.filterByPaymentStatus ) {
450
+ clientQuery.push(
451
+ {
452
+ $match: {
453
+ 'planDetails.paymentStatus': { $in: inputData.filterByPaymentStatus },
454
+ },
455
+ },
456
+ );
457
+ }
458
+ if ( inputData.filterBySubscription ) {
459
+ clientQuery.push(
460
+ {
461
+ $match: {
462
+ 'planDetails.subscriptionType': { $in: inputData.filterBySubscription },
463
+ },
464
+ },
465
+ );
466
+ }
467
+ if ( inputData.filterByStatus ) {
468
+ clientQuery.push(
469
+ {
470
+ $match: {
471
+ status: { $in: inputData.filterByStatus },
472
+ },
473
+ },
474
+ );
138
475
  }
139
476
 
477
+ clientQuery.push(
478
+ {
479
+ $project: {
480
+ status: 1,
481
+ clientName: 1,
482
+ clientId: 1,
483
+ subscriptionType: '$planDetails.subscriptionType',
484
+ paymentStatus: '$planDetails.paymentStatus',
485
+ },
486
+ },
487
+ );
488
+
140
489
  if ( inputData.searchValue ) {
141
490
  clientQuery.push( {
142
491
  $match: {
@@ -150,19 +499,37 @@ export async function clientList( req, res ) {
150
499
  },
151
500
  } );
152
501
  }
502
+ const clientCount = await aggregateClient( clientQuery );
503
+ if ( clientCount.length == 0 ) {
504
+ return res.sendError( { error: 'No Data Found' }, 204 );
505
+ }
153
506
 
154
507
  if ( inputData.sortColumName ) {
155
508
  clientQuery.push( {
156
509
  $sort: { [inputData.sortColumName]: inputData.sortBy || -1 },
157
510
  } );
158
511
  }
159
-
160
- clientQuery.push(
161
- { $skip: skip },
162
- { $limit: limit },
163
- );
512
+ if ( inputData.isExport ) {
513
+ clientQuery.push( {
514
+ $limit: 10000,
515
+ } );
516
+ } else {
517
+ clientQuery.push(
518
+ { $skip: skip },
519
+ { $limit: limit },
520
+ );
521
+ }
164
522
  const client = await aggregateClient( clientQuery );
165
- const clientList = client.map( ( item ) => item.clientId );
523
+ const clientListChunk = await chunkArray( client, 10 );
524
+ const promises = clientListChunk.map( async ( chunk ) => {
525
+ const list = [];
526
+ for ( let i = 0; i< chunk.length; i++ ) {
527
+ list.push( chunk[i].clientId );
528
+ }
529
+ return list;
530
+ } );
531
+ const clientList = await Promise.all( promises );
532
+ clientList.flat();
166
533
  const storeQuery =[
167
534
  {
168
535
  $match: {
@@ -212,6 +579,28 @@ export async function clientList( req, res ) {
212
579
  _.keyBy( activeCameraCount, 'clientId' ),
213
580
  ),
214
581
  );
582
+ if ( inputData.isExport ) {
583
+ const resultChunk = await chunkArray( result, 10 );
584
+ const promises = resultChunk.map( async ( chunk ) => {
585
+ const list = [];
586
+ for ( let i = 0; i< chunk.length; i++ ) {
587
+ list.push( {
588
+ 'client Name': chunk[i].clientName,
589
+ 'client Id': chunk[i].clientId,
590
+ 'Active Store': chunk[i].activeStoreCount,
591
+ 'Active Camera': chunk[i].activeCameraCount,
592
+ 'Payment Status': chunk[i].paymentStatus,
593
+ 'Subs Plan': chunk[i].subscriptionType,
594
+ 'Status': chunk[i].status,
595
+ } );
596
+ }
597
+ return list;
598
+ } );
599
+ const exportResult = await Promise.all( promises );
600
+ exportResult.flat();
601
+ await download( exportResult, res );
602
+ return;
603
+ }
215
604
  return res.sendSuccess( { result: result, count: clientCount.length } );
216
605
  } catch ( error ) {
217
606
  logger.error( { error: error, function: 'clientList' } );
@@ -219,6 +608,21 @@ export async function clientList( req, res ) {
219
608
  }
220
609
  }
221
610
 
611
+ export async function getOpsUsers( req, res ) {
612
+ try {
613
+ const users = await OpsUsersGet();
614
+ if ( users?.length ) {
615
+ res.sendSuccess( users );
616
+ } else {
617
+ res.sendError( 'No users found', 404 );
618
+ }
619
+ } catch ( error ) {
620
+ logger.error( { error: error, message: req.params, function: 'getOpsUsers' } );
621
+ return res.sendError( error, 500 );
622
+ }
623
+ }
624
+
625
+
222
626
  export async function detailedClientCount( req, res ) {
223
627
  try {
224
628
  const inputData = req.query;
@@ -1,14 +1,221 @@
1
1
  import joi from 'joi';
2
2
 
3
+ export const clientDetailsSchema = joi.object( {
4
+ id: joi.string().required(),
5
+ } );
6
+
7
+ export const clientDetailsValid = {
8
+ params: clientDetailsSchema,
9
+ };
10
+
11
+ export const brandInfoSchemaBody = joi.object( {
12
+ registeredCompanyName: joi.string().optional(),
13
+ industry: joi.string().optional(),
14
+ clientType: joi.string().optional(),
15
+ registeredAddress: joi.string().optional(),
16
+ headQuarters: joi.string().optional(),
17
+ website: joi.string().optional(),
18
+ status: joi.string().optional(),
19
+ logo: joi.string().optional().allow( '' ),
20
+ clientId: joi.string().optional(),
21
+ } );
22
+
23
+ export const brandInfoSchemaParam = joi.object( {
24
+ id: joi.string().required(),
25
+ } );
26
+
27
+ export const brandInfoValid = {
28
+ params: brandInfoSchemaParam,
29
+ body: brandInfoSchemaBody,
30
+ };
31
+
32
+ export const billingDetailsSchemaBody = joi.object( {
33
+ tradeName: joi.string().optional(),
34
+ gstNumber: joi.string().optional(),
35
+ authorityName: joi.string().optional(),
36
+ authorityEmail: joi.string().optional(),
37
+ billingAddress: joi.string().optional(),
38
+ gstCertificate: joi.string().optional().allow( '' ),
39
+ } );
40
+
41
+ export const billingDetailsSchemaParam = joi.object( {
42
+ id: joi.string().required(),
43
+ } );
44
+
45
+ export const billingDetailsValid = {
46
+ params: billingDetailsSchemaParam,
47
+ body: billingDetailsSchemaBody,
48
+ };
49
+
50
+ export const signatoryDetailsSchemaBody = joi.object( {
51
+ name: joi.string().optional(),
52
+ email: joi.string().email().optional(),
53
+ number: joi.string().optional(),
54
+ designation: joi.string().optional(),
55
+ } );
56
+
57
+ export const signatoryDetailsSchemaParam = joi.object( {
58
+ id: joi.string().required(),
59
+ } );
60
+
61
+ export const signatoryDetailsValid = {
62
+ params: signatoryDetailsSchemaParam,
63
+ body: signatoryDetailsSchemaBody,
64
+ };
65
+
66
+ export const ticketConfigurationSchemaBody = joi.object( {
67
+ installationReAssign: joi.number().optional(),
68
+ sendToAdmin: joi.boolean().optional(),
69
+ sendToUser: joi.boolean().optional(),
70
+ downTimeType: joi.number().optional(),
71
+ infraDownTime: joi.number().optional(),
72
+ MinFilesCount: joi.number().optional(),
73
+ isRcaTicketAssign: joi.boolean().optional(),
74
+ rcaTicketAssign: joi.number().optional(),
75
+ isRefreshAlert: joi.boolean().optional(),
76
+ refreshAlert: joi.number().optional(),
77
+ isStatusCheckAlert: joi.boolean().optional(),
78
+ statusCheckAlert: joi.number().optional(),
79
+ accuracyPercentage: joi.number().optional(),
80
+ reTrain: joi.number().optional(),
81
+ } );
82
+
83
+ export const ticketConfigurationSchemaParam = joi.object( {
84
+ id: joi.string().required(),
85
+ } );
86
+
87
+ export const ticketConfigurationValid = {
88
+ params: ticketConfigurationSchemaParam,
89
+ body: ticketConfigurationSchemaBody,
90
+ };
91
+
92
+ export const featureConfigurationSchemaBody = joi.object(
93
+ {
94
+ open: joi.string().optional(),
95
+ close: joi.string().optional(),
96
+ infraAlertCondition: joi.string().optional(),
97
+ infraAlertValue: joi.number().optional(),
98
+ bouncedLimitCondition: joi.string().optional(),
99
+ bouncedLimitValue: joi.number().optional(),
100
+ conversionCondition: joi.string().optional(),
101
+ conversionValue: joi.number().optional(),
102
+ billableCalculation: joi.string().optional(),
103
+ missedOpportunityCalculation: joi.string().optional(),
104
+ conversionCalculation: joi.string().optional(),
105
+ isNormalized: joi.boolean().optional(),
106
+ isPasserByData: joi.boolean().optional(),
107
+ isFootfallDirectory: joi.boolean().optional(),
108
+ },
109
+ );
110
+
111
+ export const featureConfigurationSchemaParam = joi.object( {
112
+ id: joi.string().required(),
113
+ } );
114
+
115
+ export const featureConfigurationValid = {
116
+ params: featureConfigurationSchemaParam,
117
+ body: featureConfigurationSchemaBody,
118
+ };
119
+
120
+ export const domainDetailsSchemaBody = joi.object(
121
+ {
122
+ domainName: joi.array().items( joi.string() ).required(),
123
+ isEnable: joi.boolean().required(),
124
+ },
125
+ );
126
+
127
+ export const domainDetailsSchemaParam = joi.object( {
128
+ id: joi.string().required(),
129
+ } );
130
+
131
+ export const domainDetailsValid = {
132
+ params: domainDetailsSchemaParam,
133
+ body: domainDetailsSchemaBody,
134
+ };
135
+
136
+ export const userConfigurationSchemaBody = joi.object(
137
+ {
138
+ csm: joi.object( { userName: joi.string().required(), _id: joi.string().required() } ).required(),
139
+ ops: joi.array().items( joi.object( { userName: joi.string().required(), _id: joi.string().required() } ).required() ).required(),
140
+ },
141
+ );
142
+
143
+ export const userConfigurationSchemaParam = joi.object( {
144
+ id: joi.string().required(),
145
+ } );
146
+
147
+ export const userConfigurationValid = {
148
+ params: userConfigurationSchemaParam,
149
+ body: userConfigurationSchemaBody,
150
+ };
151
+
3
152
  export const clientCreationSchema = joi.object( {
4
153
  status: joi.string().required(),
5
154
  clientName: joi.string().required(),
155
+ csm: joi.string().optional(),
6
156
  } );
7
157
 
8
158
  export const clientCreationValid = {
9
159
  body: clientCreationSchema,
10
160
  };
11
161
 
162
+ export const documentsSchemaBody = joi.object(
163
+ {
164
+ gstNumber: joi.string().optional(),
165
+ panNumber: joi.string().optional(),
166
+ cinNumber: joi.string().optional(),
167
+ addressDoc: joi.string().optional().allow( '' ),
168
+ gstDoc: joi.string().optional().allow( '' ),
169
+ panDoc: joi.string().optional().allow( '' ),
170
+ cinDoc: joi.string().optional().allow( '' ),
171
+ },
172
+ );
173
+
174
+ export const documentsSchemaParam = joi.object( {
175
+ id: joi.string().required(),
176
+ } );
177
+
178
+ export const documentsSchemaFiles = joi.object(
179
+ {
180
+ addressDoc: joi.object().optional(),
181
+ gstDoc: joi.object().optional(),
182
+ panDoc: joi.object().optional(),
183
+ cinDoc: joi.object().optional(),
184
+ },
185
+ );
186
+
187
+ export const documentsValid = {
188
+ params: documentsSchemaParam,
189
+ body: documentsSchemaBody,
190
+ files: documentsSchemaFiles,
191
+ };
192
+
193
+ export const getAuditConfigSchemaParam = joi.object( {
194
+ id: joi.string().required(),
195
+ } );
196
+
197
+ export const getAuditConfigValid = {
198
+ params: getAuditConfigSchemaParam,
199
+ };
200
+
201
+
202
+ export const auditConfigSchemaBody = joi.array().items(
203
+ joi.object(
204
+ {
205
+ ratio: joi.number().required(),
206
+ count: joi.number().required(),
207
+ iteration: joi.number().required(),
208
+ storeId: joi.string().required(),
209
+ },
210
+ ).required(),
211
+ ).required();
212
+
213
+
214
+ export const auditConfigValid = {
215
+ body: auditConfigSchemaBody,
216
+ };
217
+
218
+
12
219
  export const detailedClientCountSchema = joi.object( {
13
220
  clientId: joi.string().required(),
14
221
  } );
@@ -22,6 +229,9 @@ export const clientListSchema = joi.object( {
22
229
  searchValue: joi.string().optional(),
23
230
  sortColumName: joi.string().optional(),
24
231
  sortBy: joi.number().optional(),
232
+ filterByPaymentStatus: joi.array().optional(),
233
+ filterBySubscription: joi.array().optional(),
234
+ filterByStatus: joi.array().optional(),
25
235
  limit: joi.number().optional(),
26
236
  offset: joi.number().optional(),
27
237
  } );
@@ -1,16 +1,31 @@
1
1
 
2
2
  import express from 'express';
3
- import { validate } from 'tango-app-api-middleware';
4
- import { clientCreationValid, clientListValid, detailedClientCountValid } from '../dtos/client.dtos.js';
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';
5
+ import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
6
+ import { clientListValid, detailedClientCountValid } from '../dtos/client.dtos.js';
5
7
  import { isclientIdExists, isclientNameExists } from '../validations/client.validations.js';
6
- import { changeStatus, create, getClients, detailedAllClientCount, detailedClientCount, clientList } from '../controllers/client.controllers.js';
8
+ import { detailedAllClientCount, detailedClientCount, clientList } from '../controllers/client.controllers.js';
7
9
 
8
10
  export const clientRouter = express.Router();
9
11
 
10
- clientRouter.post( '/create', validate( clientCreationValid ), isclientNameExists, changeStatus, create );
11
- clientRouter.get( '/get-clients', getClients );
12
- clientRouter.get( '/detailed-all-client-count', detailedAllClientCount );
13
- clientRouter.post( '/client-list', validate( clientListValid ), clientList );
14
- clientRouter.get( '/detailed-client-count', validate( detailedClientCountValid ), isclientIdExists, detailedClientCount );
12
+ clientRouter.post( '/create', isAllowedSessionHandler, validate( clientCreationValid ), isclientNameExists, changeStatus, create );
13
+ clientRouter.get( '/get-clients', isAllowedSessionHandler, getClients );
14
+ clientRouter.get( '/client-details/:id', isAllowedSessionHandler, validate( clientDetailsValid ), clientDetails );
15
+ clientRouter.put( '/brand-info/:id', isAllowedSessionHandler, validate( brandInfoValid ), updateBrandInfo );
16
+ clientRouter.put( '/billing-details/:id', isAllowedSessionHandler, validate( billingDetailsValid ), updateBillingDetails );
17
+ clientRouter.put( '/signatory-details/:id', isAllowedSessionHandler, validate( signatoryDetailsValid ), updateSignatoryDetails );
18
+ clientRouter.put( '/ticket-configuration/:id', isAllowedSessionHandler, validate( ticketConfigurationValid ), updateTicketConfiguration );
19
+ clientRouter.put( '/feature-configuration/:id', isAllowedSessionHandler, validate( featureConfigurationValid ), updateFeatureConfiguration );
20
+ clientRouter.put( '/domain-details/:id', isAllowedSessionHandler, validate( domainDetailsValid ), domainDetailsConfiguration );
21
+ clientRouter.put( '/user-configuration/:id', isAllowedSessionHandler, validate( userConfigurationValid ), userConfiguration );
22
+ clientRouter.put( '/documents/:id', isAllowedSessionHandler, validate( documentsValid ), updateDocuments );
23
+ clientRouter.get( '/audit-configuration/:id', isAllowedSessionHandler, validate( getAuditConfigValid ), getAuditConfiguration );
24
+ clientRouter.post( '/audit-configuration', isAllowedSessionHandler, validate( auditConfigValid ), auditConfiguration );
25
+ clientRouter.get( '/get-csm-users', isAllowedSessionHandler, getCsmUsers );
26
+ clientRouter.get( '/get-ops-users', isAllowedSessionHandler, getOpsUsers );
27
+ clientRouter.get( '/detailed-all-client-count', isAllowedSessionHandler, detailedAllClientCount );
28
+ clientRouter.post( '/client-list', isAllowedSessionHandler, validate( clientListValid ), clientList );
29
+ clientRouter.get( '/detailed-client-count', isAllowedSessionHandler, validate( detailedClientCountValid ), isclientIdExists, detailedClientCount );
15
30
 
16
31
 
@@ -1,24 +1,28 @@
1
- import model from 'tango-api-schema';
1
+ import clientModel from 'tango-api-schema/schema/client.model.js';
2
+ import leadModel from 'tango-api-schema/schema/lead.model.js';
3
+ import storeModel from 'tango-api-schema/schema/store.model.js';
4
+ import userModel from 'tango-api-schema/schema/user.model.js';
2
5
  // import { createQueue, getQueueUrl } from 'tango-app-api-middleware';
3
6
 
7
+
4
8
  export function update( query, record ) {
5
- return model.leadModel.updateMany( query, { $set: record } );
9
+ return leadModel.updateMany( query, { $set: record } );
6
10
  }
7
11
 
8
12
  export function findOne( query, field ) {
9
- return model.leadModel.findOne( query, field );
13
+ return leadModel.findOne( query, field );
10
14
  }
11
15
 
12
16
  export function getClientCount( query ) {
13
- return model.clientModel.countDocuments( query );
17
+ return clientModel.countDocuments( query );
14
18
  }
15
19
 
16
20
  export function insert( record ) {
17
- return model.clientModel.insertMany( record );
21
+ return clientModel.insertMany( record );
18
22
  }
19
23
 
20
24
  export function findClient( query, field ) {
21
- return model.clientModel.find( query, field );
25
+ return clientModel.find( query, field );
22
26
  }
23
27
 
24
28
  export async function createAuditQueue( queueName ) {
@@ -39,16 +43,235 @@ export async function createAuditQueue( queueName ) {
39
43
  // }
40
44
  return true;
41
45
  } catch ( error ) {
42
- return false;
43
46
  logger.error( { error: error, message: queueName, function: 'createAuditQueue' } );
47
+ return false;
44
48
  }
45
49
  }
46
50
 
51
+
52
+ export function getClientData( { id } ) {
53
+ return clientModel.findOne( { clientId: id } );
54
+ }
55
+
56
+ export function getUserData( { id } ) {
57
+ return userModel.findOne( { _id: id }, { email: 1, countryCode: 1, mobileNumber: 1 } );
58
+ }
59
+
60
+ export function brandInfoUpdate( { clientId, registeredCompanyName, industry, clientType, registeredAddress, headQuarters, website, status, logo } ) {
61
+ return clientModel.updateOne( { clientId: clientId },
62
+ {
63
+ $set: {
64
+ 'profileDetails.registeredCompanyName': registeredCompanyName,
65
+ 'profileDetails.industry': industry,
66
+ 'profileDetails.clientType': clientType,
67
+ 'profileDetails.registeredAddress': registeredAddress,
68
+ 'profileDetails.headQuarters': headQuarters,
69
+ 'profileDetails.website': website,
70
+ 'profileDetails.logo': logo,
71
+ 'status': status,
72
+ },
73
+ } );
74
+ }
75
+
76
+ export function billingDetailsUpdate( { clientId, tradeName, gstNumber, authorityName, authorityEmail, billingAddress, gstCertificate } ) {
77
+ return clientModel.updateOne( { clientId: clientId },
78
+ {
79
+ $set: {
80
+ 'billingDetails.tradeName': tradeName,
81
+ 'billingDetails.gstNumber': gstNumber,
82
+ 'billingDetails.authorityName': authorityName,
83
+ 'billingDetails.authorityEmail': authorityEmail,
84
+ 'billingDetails.billingAddress': billingAddress,
85
+ 'document.gst.number': gstNumber,
86
+ 'document.gst.path': gstCertificate,
87
+ },
88
+ } );
89
+ }
90
+
91
+ export function signatoryDetailsUpdate( { clientId, name, email, number, designation } ) {
92
+ return clientModel.updateOne( { clientId: clientId },
93
+ {
94
+ $set: {
95
+ 'signatoryDetail.name': name,
96
+ 'signatoryDetail.email': email,
97
+ 'signatoryDetail.number': number,
98
+ 'signatoryDetail.designation': designation,
99
+ },
100
+ } );
101
+ }
102
+
103
+ export function ticketConfigurationUpdate( {
104
+ clientId, MinFilesCount, accuracyPercentage, downTimeType, infraDownTime, installationReAssign, isRcaTicketAssign,
105
+ isRefreshAlert, isStatusCheckAlert, rcaTicketAssign, reTrain, refreshAlert, sendToAdmin, sendToUser, statusCheckAlert,
106
+ } ) {
107
+ return clientModel.updateOne( { clientId: clientId },
108
+ {
109
+ $set: {
110
+ 'ticketConfigs.installationReAssign': installationReAssign,
111
+ 'ticketConfigs.alertSentTo.admin': sendToAdmin,
112
+ 'ticketConfigs.alertSentTo.user': sendToUser,
113
+ 'ticketConfigs.downTimeType': downTimeType,
114
+ 'ticketConfigs.infraDownTime': infraDownTime,
115
+ 'ticketConfigs.MinFilesCount': MinFilesCount,
116
+ 'ticketConfigs.isRcaTicketAssign': isRcaTicketAssign,
117
+ 'ticketConfigs.rcaTicketAssign': rcaTicketAssign,
118
+ 'ticketConfigs.isRefreshAlert': isRefreshAlert,
119
+ 'ticketConfigs.refreshAlert': refreshAlert,
120
+ 'ticketConfigs.isStatusCheckAlert': isStatusCheckAlert,
121
+ 'ticketConfigs.statusCheckAlert': statusCheckAlert,
122
+ 'ticketConfigs.reTrain': reTrain,
123
+ 'ticketConfigs.accuracyPercentage': accuracyPercentage,
124
+ },
125
+ } );
126
+ }
127
+
128
+ export function featureConfigurationUpdate( {
129
+ clientId, billableCalculation, bouncedLimitCondition, bouncedLimitValue,
130
+ close, conversionCalculation, conversionCondition,
131
+ conversionValue, infraAlertCondition, infraAlertValue, isFootfallDirectory,
132
+ isNormalized, isPasserByData, missedOpportunityCalculation, open,
133
+ } ) {
134
+ return clientModel.updateOne( { clientId: clientId },
135
+ {
136
+ $set: {
137
+ 'featureConfigs.open': open,
138
+ 'featureConfigs.close': close,
139
+ 'featureConfigs.infraAlert.condition': infraAlertCondition,
140
+ 'featureConfigs.infraAlert.value': infraAlertValue,
141
+ 'featureConfigs.bouncedLimit.condition': bouncedLimitCondition,
142
+ 'featureConfigs.bouncedLimit.value': bouncedLimitValue,
143
+ 'featureConfigs.conversion.condition': conversionCondition,
144
+ 'featureConfigs.conversion.value': conversionValue,
145
+ 'featureConfigs.billableCalculation': billableCalculation,
146
+ 'featureConfigs.missedOpportunityCalculation': missedOpportunityCalculation,
147
+ 'featureConfigs.conversionCalculation': conversionCalculation,
148
+ 'featureConfigs.isNormalized': isNormalized,
149
+ 'featureConfigs.isPasserByData': isPasserByData,
150
+ 'featureConfigs.isFootfallDirectory': isFootfallDirectory,
151
+ },
152
+ } );
153
+ }
154
+
155
+ export function domainDetailsConfigurationUpdate( { clientId, domainName, isEnable } ) {
156
+ return clientModel.updateOne( { clientId: clientId },
157
+ {
158
+ $set: {
159
+ 'ssoLogin.domainName': domainName,
160
+ 'ssoLogin.isEnable': isEnable,
161
+ },
162
+ } );
163
+ }
164
+
165
+ export function userConfigurationUpdate( { clientId, csm, ops } ) {
166
+ return clientModel.updateOne( { clientId: clientId },
167
+ {
168
+ $set: {
169
+ 'assignedUsers.csm': csm,
170
+ 'assignedUsers.ops': ops,
171
+ },
172
+ } );
173
+ }
174
+
175
+ export function documentsUpdate( { clientId, gstNumber, panNumber, cinNumber, addressDoc, gstDoc, panDoc, cinDoc } ) {
176
+ return clientModel.updateOne( { clientId: clientId },
177
+ {
178
+ $set: {
179
+ 'document.addressProof.path': addressDoc,
180
+ 'document.gst.number': gstNumber,
181
+ 'document.gst.path': gstDoc,
182
+ 'document.pan.number': panNumber,
183
+ 'document.pan.path': panDoc,
184
+ 'document.pan.number': panNumber,
185
+ 'document.pan.path': panDoc,
186
+ 'document.cin.number': cinNumber,
187
+ 'document.cin.path': cinDoc,
188
+ },
189
+ } );
190
+ }
191
+
192
+ export function auditConfigurationGet( { storeId } ) {
193
+ return storeModel.findOne( { storeId: storeId },
194
+ {
195
+ 'auditConfigs.count': 1,
196
+ 'auditConfigs.iteration': 1,
197
+ 'auditConfigs.ratio': 1,
198
+ 'storeId': 1,
199
+ '_id': 0,
200
+ } );
201
+ }
202
+
203
+ export function auditConfigurationUpdate( { storeId, count, iteration, ratio } ) {
204
+ return storeModel.updateOne( { storeId: storeId },
205
+ {
206
+ $set: {
207
+ 'auditConfigs.count': count,
208
+ 'auditConfigs.iteration': iteration,
209
+ 'auditConfigs.ratio': ratio,
210
+ },
211
+ } );
212
+ }
213
+
214
+ export function CsmUsersGet( ) {
215
+ return userModel.aggregate(
216
+ [
217
+ {
218
+ $match: {
219
+ $and: [
220
+ {
221
+ role: 'admin',
222
+ },
223
+ {
224
+ userType: 'tango',
225
+ },
226
+ ],
227
+ },
228
+ },
229
+ {
230
+ $project: {
231
+ userName: 1,
232
+ },
233
+ },
234
+ ],
235
+ );
236
+ }
237
+
238
+ export function OpsUsersGet( ) {
239
+ return userModel.aggregate(
240
+ [
241
+ {
242
+ $match: {
243
+ $and: [
244
+ {
245
+ $or: [
246
+ {
247
+ role: 'user',
248
+ },
249
+ {
250
+ role: 'admin',
251
+ },
252
+ ],
253
+ },
254
+ {
255
+ userType: 'tango',
256
+ },
257
+ ],
258
+ },
259
+ },
260
+ {
261
+ $project: {
262
+ userName: 1,
263
+ },
264
+ },
265
+ ],
266
+ );
267
+ }
268
+
269
+
47
270
  export function aggregateClient( query ) {
48
- return model.clientModel.aggregate( query );
271
+ return clientModel.aggregate( query );
49
272
  }
50
273
 
51
274
  export function findOneClient( query, field ) {
52
- return model.clientModel.findOne( query, field );
275
+ return clientModel.findOne( query, field );
53
276
  }
54
277
 
@@ -0,0 +1,263 @@
1
+ import clientModel from 'tango-api-schema/schema/client.model.js';
2
+ import leadModel from 'tango-api-schema/schema/lead.model.js';
3
+ import storeModel from 'tango-api-schema/schema/store.model.js';
4
+ import userModel from 'tango-api-schema/schema/user.model.js';
5
+ // import { createQueue, getQueueUrl } from 'tango-app-api-middleware';
6
+
7
+
8
+ export function update( query, record ) {
9
+ return leadModel.updateMany( query, { $set: record } );
10
+ }
11
+
12
+ export function findOne( query, field ) {
13
+ return leadModel.findOne( query, field );
14
+ }
15
+
16
+ export function getClientCount( query ) {
17
+ return clientModel.countDocuments( query );
18
+ }
19
+
20
+ export function insert( record ) {
21
+ return clientModel.insertMany( record );
22
+ }
23
+
24
+ export function find( query, field ) {
25
+ return clientModel.find( query, field );
26
+ }
27
+
28
+ export async function createAuditQueue( queueName ) {
29
+ try {
30
+ // const isExist = await getQueueUrl( `${queueName}${config.aws.sqs.queueType}` );
31
+ // if ( isExist.statusCode ) {
32
+ // const addQueue = await createQueue( `${queueName}${config.aws.sqs.queueType}` );
33
+ // if ( addQueue.QueueUrl ) {
34
+ // logger.info(
35
+ // 'Queueue Created'
36
+ // , { queueName: addQueue.QueueUrl, addQueue },
37
+ // );
38
+ // } else {
39
+ // logger.error( { error: 'Queue creation failed', function: 'createAuditQueue' } );
40
+ // }
41
+ // } else {
42
+ // logger.error( { error: 'Queue already exisit', message: queueName, function: 'createAuditQueue' } );
43
+ // }
44
+ return true;
45
+ } catch ( error ) {
46
+ return false;
47
+ logger.error( { error: error, message: queueName, function: 'createAuditQueue' } );
48
+ }
49
+ }
50
+
51
+
52
+ export function getClientData( { id } ) {
53
+ return clientModel.findOne( { clientId: id } );
54
+ }
55
+
56
+ export function getUserData( { id } ) {
57
+ return userModel.findOne( { _id: id }, { email: 1, countryCode: 1, mobileNumber: 1 } );
58
+ }
59
+
60
+ export function brandInfoUpdate( { clientId, registeredCompanyName, industry, clientType, registeredAddress, headQuarters, website, status, logo } ) {
61
+ return clientModel.updateOne( { clientId: clientId },
62
+ {
63
+ $set: {
64
+ 'profileDetails.registeredCompanyName': registeredCompanyName,
65
+ 'profileDetails.industry': industry,
66
+ 'profileDetails.clientType': clientType,
67
+ 'profileDetails.registeredAddress': registeredAddress,
68
+ 'profileDetails.headQuarters': headQuarters,
69
+ 'profileDetails.website': website,
70
+ 'profileDetails.logo': logo,
71
+ 'status': status,
72
+ },
73
+ } );
74
+ }
75
+
76
+ export function billingDetailsUpdate( { clientId, tradeName, gstNumber, authorityName, authorityEmail, billingAddress, gstCertificate } ) {
77
+ return clientModel.updateOne( { clientId: clientId },
78
+ {
79
+ $set: {
80
+ 'billingDetails.tradeName': tradeName,
81
+ 'billingDetails.gstNumber': gstNumber,
82
+ 'billingDetails.authorityName': authorityName,
83
+ 'billingDetails.authorityEmail': authorityEmail,
84
+ 'billingDetails.billingAddress': billingAddress,
85
+ 'document.gst.number': gstNumber,
86
+ 'document.gst.path': gstCertificate,
87
+ },
88
+ } );
89
+ }
90
+
91
+ export function signatoryDetailsUpdate( { clientId, name, email, number, designation } ) {
92
+ return clientModel.updateOne( { clientId: clientId },
93
+ {
94
+ $set: {
95
+ 'signatoryDetail.name': name,
96
+ 'signatoryDetail.email': email,
97
+ 'signatoryDetail.number': number,
98
+ 'signatoryDetail.designation': designation,
99
+ },
100
+ } );
101
+ }
102
+
103
+ export function ticketConfigurationUpdate( {
104
+ clientId, MinFilesCount, accuracyPercentage, downTimeType, infraDownTime, installationReAssign, isRcaTicketAssign,
105
+ isRefreshAlert, isStatusCheckAlert, rcaTicketAssign, reTrain, refreshAlert, sendToAdmin, sendToUser, statusCheckAlert,
106
+ } ) {
107
+ return clientModel.updateOne( { clientId: clientId },
108
+ {
109
+ $set: {
110
+ 'ticketConfigs.installationReAssign': installationReAssign,
111
+ 'ticketConfigs.alertSentTo.admin': sendToAdmin,
112
+ 'ticketConfigs.alertSentTo.user': sendToUser,
113
+ 'ticketConfigs.downTimeType': downTimeType,
114
+ 'ticketConfigs.infraDownTime': infraDownTime,
115
+ 'ticketConfigs.MinFilesCount': MinFilesCount,
116
+ 'ticketConfigs.isRcaTicketAssign': isRcaTicketAssign,
117
+ 'ticketConfigs.rcaTicketAssign': rcaTicketAssign,
118
+ 'ticketConfigs.isRefreshAlert': isRefreshAlert,
119
+ 'ticketConfigs.refreshAlert': refreshAlert,
120
+ 'ticketConfigs.isStatusCheckAlert': isStatusCheckAlert,
121
+ 'ticketConfigs.statusCheckAlert': statusCheckAlert,
122
+ 'ticketConfigs.reTrain': reTrain,
123
+ 'ticketConfigs.accuracyPercentage': accuracyPercentage,
124
+ },
125
+ } );
126
+ }
127
+
128
+ export function featureConfigurationUpdate( {
129
+ clientId, billableCalculation, bouncedLimitCondition, bouncedLimitValue,
130
+ close, conversionCalculation, conversionCondition,
131
+ conversionValue, infraAlertCondition, infraAlertValue, isFootfallDirectory,
132
+ isNormalized, isPasserByData, missedOpportunityCalculation, open,
133
+ } ) {
134
+ return clientModel.updateOne( { clientId: clientId },
135
+ {
136
+ $set: {
137
+ 'featureConfigs.open': open,
138
+ 'featureConfigs.close': close,
139
+ 'featureConfigs.infraAlert.condition': infraAlertCondition,
140
+ 'featureConfigs.infraAlert.value': infraAlertValue,
141
+ 'featureConfigs.bouncedLimit.condition': bouncedLimitCondition,
142
+ 'featureConfigs.bouncedLimit.value': bouncedLimitValue,
143
+ 'featureConfigs.conversion.condition': conversionCondition,
144
+ 'featureConfigs.conversion.value': conversionValue,
145
+ 'featureConfigs.billableCalculation': billableCalculation,
146
+ 'featureConfigs.missedOpportunityCalculation': missedOpportunityCalculation,
147
+ 'featureConfigs.conversionCalculation': conversionCalculation,
148
+ 'featureConfigs.isNormalized': isNormalized,
149
+ 'featureConfigs.isPasserByData': isPasserByData,
150
+ 'featureConfigs.isFootfallDirectory': isFootfallDirectory,
151
+ },
152
+ } );
153
+ }
154
+
155
+ export function domainDetailsConfigurationUpdate( { clientId, domainName, isEnable } ) {
156
+ return clientModel.updateOne( { clientId: clientId },
157
+ {
158
+ $set: {
159
+ 'ssoLogin.domainName': domainName,
160
+ 'ssoLogin.isEnable': isEnable,
161
+ },
162
+ } );
163
+ }
164
+
165
+ export function userConfigurationUpdate( { clientId, csm, ops } ) {
166
+ return clientModel.updateOne( { clientId: clientId },
167
+ {
168
+ $set: {
169
+ 'assignedUsers.csm': csm,
170
+ 'assignedUsers.ops': ops,
171
+ },
172
+ } );
173
+ }
174
+
175
+ export function documentsUpdate( { clientId, gstNumber, panNumber, cinNumber, addressDoc, gstDoc, panDoc, cinDoc } ) {
176
+ return clientModel.updateOne( { clientId: clientId },
177
+ {
178
+ $set: {
179
+ 'document.addressProof.path': addressDoc,
180
+ 'document.gst.number': gstNumber,
181
+ 'document.gst.path': gstDoc,
182
+ 'document.pan.number': panNumber,
183
+ 'document.pan.path': panDoc,
184
+ 'document.pan.number': panNumber,
185
+ 'document.pan.path': panDoc,
186
+ 'document.cin.number': cinNumber,
187
+ 'document.cin.path': cinDoc,
188
+ },
189
+ } );
190
+ }
191
+
192
+ export function auditConfigurationGet( { storeId } ) {
193
+ return storeModel.findOne( { storeId: storeId },
194
+ {
195
+ 'auditConfigs.count': 1,
196
+ 'auditConfigs.iteration': 1,
197
+ 'auditConfigs.ratio': 1,
198
+ 'storeId': 1,
199
+ '_id': 0,
200
+ } );
201
+ }
202
+
203
+ export function auditConfigurationUpdate( { storeId, count, iteration, ratio } ) {
204
+ return storeModel.updateOne( { storeId: storeId },
205
+ {
206
+ $set: {
207
+ 'auditConfigs.count': count,
208
+ 'auditConfigs.iteration': iteration,
209
+ 'auditConfigs.ratio': ratio,
210
+ },
211
+ } );
212
+ }
213
+
214
+ export function CsmUsersGet( ) {
215
+ return userModel.aggregate( [
216
+ {
217
+ $match: {
218
+ $and: [
219
+ {
220
+ $or: [
221
+ {
222
+ role: 'user',
223
+ },
224
+ {
225
+ role: 'admin',
226
+ },
227
+ ],
228
+ },
229
+ {
230
+ userType: 'tango',
231
+ },
232
+ ],
233
+ },
234
+ },
235
+ {
236
+ $project: {
237
+ userName: 1,
238
+ },
239
+ },
240
+ ] );
241
+ }
242
+
243
+ export function OpsUsersGet( ) {
244
+ return userModel.aggregate( [
245
+ {
246
+ $match: {
247
+ $and: [
248
+ {
249
+ role: 'user',
250
+ },
251
+ {
252
+ userType: 'tango',
253
+ },
254
+ ],
255
+ },
256
+ },
257
+ {
258
+ $project: {
259
+ userName: 1,
260
+ },
261
+ },
262
+ ] );
263
+ }