tango-app-api-client 3.0.44-dev → 3.0.46-dev

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.44-dev",
3
+ "version": "3.0.46-dev",
4
4
  "description": "client",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -25,8 +25,8 @@
25
25
  "mongodb": "^6.3.0",
26
26
  "nodemon": "^3.0.3",
27
27
  "swagger-ui-express": "^5.0.0",
28
- "tango-app-api-middleware": "^1.0.72-test",
29
- "tango-api-schema": "^2.0.103",
28
+ "tango-api-schema": "^2.0.105",
29
+ "tango-app-api-middleware": "^1.0.73-test",
30
30
  "winston": "^3.11.0",
31
31
  "winston-daily-rotate-file": "^5.0.0"
32
32
  },
@@ -1,16 +1,16 @@
1
- import { billingDetailsUpdate, brandInfoUpdate, domainDetailsConfigurationUpdate, featureConfigurationUpdate, getClientData, signatoryDetailsUpdate, ticketConfigurationUpdate, documentsUpdate, getUserData, auditConfigurationUpdate, auditConfigurationGet, CsmUsersGet, OpsUsersGet, userConfigurationUpdate, findClient, aggregateClient, createAuditQueue, findOne, insert, update, findOneClient } 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, insert, update, findOneClient, updateOneClient } from '../service/client.service.js';
2
2
  import { checkFileExist, fileUpload, signedUrl, chunkArray, download, logger, getOpenSearchData, insertOpenSearchData, appConfig, sendEmailWithSES } from 'tango-app-api-middleware';
3
3
  import { countDocumentsUser, findOneAndUpdateUser, findOneUser, getUserNameEmailById, updateManyUser } from '../service/user.service.js';
4
- import { aggregateStore, countDocumentsStore, updateManyStore } from '../service/store.service.js';
4
+ import { aggregateStore, countDocumentsStore, findOneStore, updateManyStore } from '../service/store.service.js';
5
5
  import { aggregateCamera, countDocumentsCamera, updateManyCamera } from '../service/camera.service.js';
6
6
  import _ from 'lodash';
7
7
  import { findOneStandaredRole } from '../service/standaredRole.service.js';
8
- import { aggregateUserAssignedStore } from '../service/userAssignedStore.service.js';
8
+ import { aggregateUserAssignedStore, deleteOneAssignedStore, updateOneUserAssignedStore } from '../service/userAssignedStore.service.js';
9
9
  import { aggregateTickets } from '../service/tangoticket.service.js';
10
10
  import { join } from 'path';
11
11
  import { readFileSync } from 'fs';
12
12
  import handlebars from 'handlebars';
13
- import { countDocumentsGroup } from '../service/group.service.js';
13
+ import { countDocumentsGroup, createGroupModel, findOneGroup } from '../service/group.service.js';
14
14
  import { deleteOneAuthentication } from '../service/authentication.service.js';
15
15
 
16
16
 
@@ -71,9 +71,33 @@ export async function create( req, res ) {
71
71
 
72
72
  const insertClient = await insert( record );
73
73
 
74
+ const insertedClientRecord = await findOneClient( { clientId: record.clientId }, {} );
75
+
76
+ const defaultGroup = {
77
+ 'groupName': 'All stores',
78
+ 'description': 'Contains all the onboarded stores',
79
+ 'storeList': [],
80
+ 'clientId': insertedClientRecord.clientId,
81
+ 'isDefault': true,
82
+ };
83
+
84
+ await createGroupModel( defaultGroup );
85
+
86
+ const createdGroup = await findOneGroup( { clientId: insertedClientRecord.clientId, isDefault: true }, { } );
87
+
88
+ let oldGroup = {
89
+ '_id': createdGroup._id,
90
+ 'client_id': createdGroup.clientId,
91
+ 'groupName': createdGroup.groupName,
92
+ 'description': createdGroup.description,
93
+ 'storeList': createdGroup.storeList,
94
+ };
95
+
96
+
97
+ await postApi( `${appConfig.url.oldapidomain}/oldGroupAdd`, [ oldGroup ] );
98
+
74
99
  // For old dashboard insert
75
100
 
76
- const insertedClientRecord = await findOneClient( { clientId: record.clientId }, {} );
77
101
 
78
102
  const oldBrandInsertData = {
79
103
  '_id': insertedClientRecord._id,
@@ -93,9 +117,7 @@ export async function create( req, res ) {
93
117
  'birdsEye',
94
118
  'tangoZone',
95
119
  'tangoTraffic',
96
- 'Support',
97
- 'footFallDirectory',
98
- 'tangoSOP',
120
+ 'support',
99
121
  ],
100
122
  'planType': insertedClientRecord.planDetails.subscriptionPeriod,
101
123
  'storeCount': insertedClientRecord.planDetails.totalStores,
@@ -188,7 +210,9 @@ export async function create( req, res ) {
188
210
  logType: 'brandDetails',
189
211
  logSubType: 'brandApproval',
190
212
  changes: [ insertedClientRecord.clientName ],
213
+ showTo: [],
191
214
  eventType: 'approve',
215
+ showTo: [ 'client', 'tango' ],
192
216
  };
193
217
 
194
218
  await insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
@@ -210,6 +234,7 @@ export async function create( req, res ) {
210
234
  date: new Date(),
211
235
  changes: [ `${convertTitleCase( leadRecord?.planDetails?.product[index] )} trial started` ],
212
236
  eventType: '',
237
+ showTo: [ 'client', 'tango' ],
213
238
  };
214
239
 
215
240
  await insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
@@ -291,6 +316,16 @@ export async function getClients( req, res ) {
291
316
  $match: {
292
317
  userEmail: req?.user?.email,
293
318
  assignedType: { $eq: 'client' },
319
+ $expr: {
320
+ $cond: {
321
+ if: { $and: [
322
+ { $eq: [ '$userType', 'tango' ] },
323
+ { $eq: [ '$tangoUserType', 'csm' ] },
324
+ ] },
325
+ then: { $eq: [ '$isClientApproved', true ] },
326
+ else: true,
327
+ },
328
+ },
294
329
  },
295
330
  },
296
331
  {
@@ -472,7 +507,7 @@ export async function detailedAllClientCount( req, res ) {
472
507
  },
473
508
  ];
474
509
  const result = await aggregateClient( query );
475
- const activeStores = await countDocumentsStore( { status: 'active' } );
510
+ const activeStores = await countDocumentsStore( { 'status': 'active', 'edge.firstFile': true } );
476
511
  const activeCameras = await countDocumentsCamera( { isUp: true, isActivated: true } );
477
512
  if ( result.length == 0 ) {
478
513
  return res.sendError( 'No Data Found', 204 );
@@ -526,6 +561,7 @@ export async function updateBrandInfo( req, res ) {
526
561
  logSubType: 'brandInfo',
527
562
  changes: updateKeys,
528
563
  eventType: 'update',
564
+ showTo: [ 'client', 'tango' ],
529
565
  };
530
566
 
531
567
  if ( updateKeys.length ) {
@@ -622,6 +658,7 @@ export async function updateBillingDetails( req, res ) {
622
658
  logSubType: 'billingDetails',
623
659
  changes: updateKeys,
624
660
  eventType: 'update',
661
+ showTo: [ 'client', 'tango' ],
625
662
  };
626
663
 
627
664
  if ( updateKeys.length ) {
@@ -663,6 +700,7 @@ export async function updateSignatoryDetails( req, res ) {
663
700
  logSubType: 'signatoryDetails',
664
701
  changes: updateKeys,
665
702
  eventType: 'update',
703
+ showTo: [ 'client', 'tango' ],
666
704
  };
667
705
 
668
706
  if ( updateKeys.length ) {
@@ -709,6 +747,7 @@ export async function updateTicketConfiguration( req, res ) {
709
747
  logSubType: 'ticketConfig',
710
748
  changes: updateKeys,
711
749
  eventType: 'update',
750
+ showTo: [ 'tango' ],
712
751
  };
713
752
 
714
753
  if ( updateKeys.length ) {
@@ -797,6 +836,7 @@ export async function updateFeatureConfiguration( req, res ) {
797
836
  logSubType: 'featureConfig',
798
837
  changes: updateKeys,
799
838
  eventType: 'update',
839
+ showTo: [ 'client', 'tango' ],
800
840
  };
801
841
  if ( updateKeys.length ) {
802
842
  await insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
@@ -838,6 +878,7 @@ export async function domainDetailsConfiguration( req, res ) {
838
878
  logSubType: 'domainDetails',
839
879
  changes: updateKeys,
840
880
  eventType: 'update',
881
+ showTo: [ 'client', 'tango' ],
841
882
  };
842
883
 
843
884
  if ( updateKeys.length ) {
@@ -951,6 +992,7 @@ export async function updateDocuments( req, res ) {
951
992
  logSubType: 'documentUpload',
952
993
  changes: updateKeys,
953
994
  eventType: 'update',
995
+ showTo: [ 'client', 'tango' ],
954
996
  };
955
997
 
956
998
  if ( updateKeys.length ) {
@@ -991,35 +1033,37 @@ export async function getAuditConfiguration( req, res ) {
991
1033
  export async function auditConfiguration( req, res ) {
992
1034
  try {
993
1035
  for ( let i = 0; i < req.body?.length; i++ ) {
1036
+ const previousStore = await findOneStore( { storeId: req.body[i].storeId }, { auditConfigs: 1, _id: 0 } );
994
1037
  await auditConfigurationUpdate( {
995
1038
  storeId: req.body[i].storeId,
996
1039
  count: req.body[i].count,
997
1040
  iteration: req.body[i].iteration,
998
1041
  ratio: normalizeNumber( req.body[i].ratio, 0, 100 ),
999
1042
  } );
1000
- }
1001
-
1002
- const user = await getUserNameEmailById( req.userId );
1003
1043
 
1004
- const logObj = {
1005
- clientId: req.params?.id,
1006
- userName: user.userName,
1007
- email: user.email,
1008
- date: new Date(),
1009
- logType: 'configuration',
1010
- logSubType: 'auditConfig',
1011
- eventType: 'update',
1012
- };
1013
-
1014
- if ( req.body?.length === 1 ) {
1015
- logObj.changes = [ `Audit config for store id ${req.body[0].storeId}` ];
1016
- }
1044
+ const logObj = {
1045
+ clientId: req.params?.id,
1046
+ userName: req.user?.userName,
1047
+ email: req.user?.email,
1048
+ date: new Date(),
1049
+ logType: 'configuration',
1050
+ logSubType: 'auditConfig',
1051
+ eventType: 'update',
1052
+ showTo: [ 'tango' ],
1053
+ changes: [ `Audit config for store id ${req.body[i].storeId}` ],
1054
+ storeId: req.body[i].storeId,
1055
+ previous: previousStore,
1056
+ current: {
1057
+ storeId: req.body[i].storeId,
1058
+ count: req.body[i].count,
1059
+ iteration: req.body[i].iteration,
1060
+ ratio: normalizeNumber( req.body[i].ratio, 0, 100 ),
1061
+ },
1062
+ };
1017
1063
 
1018
- if ( req.body?.length > 1 ) {
1019
- logObj.changes = [ `Audit config bulk` ];
1064
+ await insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
1020
1065
  }
1021
1066
 
1022
- await insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
1023
1067
 
1024
1068
  res.sendSuccess( { result: 'Updated Successfully' } );
1025
1069
  } catch ( error ) {
@@ -1057,6 +1101,15 @@ export async function clientList( req, res ) {
1057
1101
  $match: {
1058
1102
  userEmail: { $eq: req?.user?.email },
1059
1103
  userType: 'tango',
1104
+ $expr: {
1105
+ $cond: {
1106
+ if: { $and: [
1107
+ { $eq: [ '$tangoUserType', 'csm' ] },
1108
+ ] },
1109
+ then: { $eq: [ '$isClientApproved', true ] },
1110
+ else: true,
1111
+ },
1112
+ },
1060
1113
 
1061
1114
  },
1062
1115
  }, {
@@ -1461,6 +1514,14 @@ export async function getActivityLogs( req, res ) {
1461
1514
  } );
1462
1515
  }
1463
1516
 
1517
+ query.query.bool.must.push(
1518
+ {
1519
+ 'terms': {
1520
+ 'showTo.keyword': [ req.user.userType ],
1521
+ },
1522
+ },
1523
+ );
1524
+
1464
1525
  const logs = await getOpenSearchData( appConfig.opensearch.activityLog, query );
1465
1526
 
1466
1527
  const hits = logs?.body?.hits?.hits;
@@ -1514,3 +1575,34 @@ async function getApi( url ) {
1514
1575
  }
1515
1576
  }
1516
1577
 
1578
+
1579
+ export async function csmAssignConfirmation( req, res ) {
1580
+ try {
1581
+ const client = await findOneClient( { clientId: req.query.clientId }, { notifyCsmAssign: 1, _id: 0 } );
1582
+ if ( !client ) {
1583
+ res.sendError( 'No data found', 204 );
1584
+ }
1585
+ res.sendSuccess( client );
1586
+ } catch ( error ) {
1587
+ logger.error( { error: error, message: req.params, function: 'csmAssignConfirmation' } );
1588
+ return res.sendError( 'Internal Server Error', 500 );
1589
+ }
1590
+ }
1591
+
1592
+ export async function clientCsmAssignAction( req, res ) {
1593
+ try {
1594
+ await updateOneClient( { clientId: req.query.clientId }, { notifyCsmAssign: false } );
1595
+ if ( req.body.action === 'approve' ) {
1596
+ await updateOneUserAssignedStore( { clientId: req.query.clientId, tangoUserType: 'csm', assignedType: 'client' }, { isClientApproved: true } );
1597
+ }
1598
+
1599
+ if ( req.body.action === 'decline' ) {
1600
+ await deleteOneAssignedStore( { clientId: req.query.clientId, tangoUserType: 'csm', assignedType: 'client' } );
1601
+ }
1602
+
1603
+ res.sendSuccess( 'Updated Succesfully' );
1604
+ } catch ( error ) {
1605
+ logger.error( { error: error, message: req.params, function: 'csmAssignConfirmation' } );
1606
+ return res.sendError( 'Internal Server Error', 500 );
1607
+ }
1608
+ }
@@ -261,3 +261,24 @@ export const activityLogSchema = joi.object( {
261
261
  export const activityLogValid = {
262
262
  body: activityLogSchema,
263
263
  };
264
+
265
+ export const getAssignedClientSchama = joi.object( {
266
+ clientId: joi.string().required(),
267
+ } );
268
+
269
+ export const getAssignedClientValid = {
270
+ query: getAssignedClientSchama,
271
+ };
272
+
273
+ export const postClientCamApprovalSchamaQuery = joi.object( {
274
+ clientId: joi.string().required(),
275
+ } );
276
+
277
+ export const postClientCamApprovalSchamaBody = joi.object( {
278
+ action: joi.string().required(),
279
+ } );
280
+
281
+ export const postClientCamApprovalValid = {
282
+ query: postClientCamApprovalSchamaQuery,
283
+ body: postClientCamApprovalSchamaBody,
284
+ };
@@ -1,7 +1,7 @@
1
1
 
2
2
  import express from 'express';
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';
3
+ import { activityLogValid, auditConfigValid, billingDetailsValid, brandInfoValid, clientCreationValid, clientDetailsValid, documentsValid, domainDetailsValid, featureConfigurationValid, getAssignedClientValid, getAuditConfigValid, postClientCamApprovalValid, signatoryDetailsValid, ticketConfigurationValid, userConfigurationValid } from '../dtos/client.dtos.js';
4
+ import { auditConfiguration, changeStatus, clientCsmAssignAction, clientDetails, create, csmAssignConfirmation, domainDetailsConfiguration, getActivityLogs, getAuditConfiguration, getClients, getCsmUsers, getOpsUsers, updateBillingDetails, updateBrandInfo, updateDocuments, updateFeatureConfiguration, updateSignatoryDetails, updateTicketConfiguration, userConfiguration } from '../controllers/client.controllers.js';
5
5
  import { authorize, 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';
@@ -93,4 +93,10 @@ clientRouter.post( '/activity-log', isAllowedSessionHandler, authorize(
93
93
  { featureName: 'settings', name: 'activityLog', permissions: [ 'isView' ] } ] } ),
94
94
  validate( activityLogValid ), getActivityLogs );
95
95
 
96
+ clientRouter.get( '/show-csm-assign-confirmation', isAllowedSessionHandler,
97
+ validate( getAssignedClientValid ), csmAssignConfirmation );
98
+
99
+ clientRouter.post( '/client-csm-assign-action', isAllowedSessionHandler,
100
+ validate( postClientCamApprovalValid ), clientCsmAssignAction );
101
+
96
102
 
@@ -285,3 +285,12 @@ export function findOneClient( query, field ) {
285
285
  return clientModel.findOne( query, field );
286
286
  }
287
287
 
288
+ export async function updateOneClient( query, record ) {
289
+ return clientModel.updateOne(
290
+ query,
291
+ {
292
+ $set: record,
293
+ },
294
+ );
295
+ }
296
+
@@ -3,3 +3,11 @@ import groupModel from 'tango-api-schema/schema/group.model.js';
3
3
  export function countDocumentsGroup( query ) {
4
4
  return groupModel.countDocuments( query );
5
5
  }
6
+
7
+ export async function createGroupModel( query ={}, field={} ) {
8
+ return await groupModel.create( query, field );
9
+ };
10
+
11
+ export async function findOneGroup( query ={}, field={} ) {
12
+ return await groupModel.findOne( query, field );
13
+ };
@@ -11,3 +11,7 @@ export function aggregateStore( query ) {
11
11
  export function updateManyStore( query, record ) {
12
12
  return storeModel.updateMany( query, { $set: record } );
13
13
  }
14
+
15
+ export function findOneStore( query, field ) {
16
+ return storeModel.findOne( query, field );
17
+ }
@@ -4,3 +4,16 @@ import userAssignedStoreModel from 'tango-api-schema/schema/userAssignedStore.mo
4
4
  export async function aggregateUserAssignedStore( query ) {
5
5
  return await userAssignedStoreModel.aggregate( query );
6
6
  };
7
+
8
+ export async function updateOneUserAssignedStore( query, record ) {
9
+ return userAssignedStoreModel.updateOne(
10
+ query,
11
+ {
12
+ $set: record,
13
+ },
14
+ );
15
+ }
16
+
17
+ export async function deleteOneAssignedStore( query ) {
18
+ return userAssignedStoreModel.deleteOne( query );
19
+ }