tango-app-api-client 3.3.2 → 3.3.3-beta.0

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.3.2",
3
+ "version": "3.3.3-beta.0",
4
4
  "description": "client",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -19,14 +19,16 @@
19
19
  "express": "^4.18.2",
20
20
  "express-fileupload": "^1.4.3",
21
21
  "handlebars": "^4.7.8",
22
+ "i": "^0.3.7",
22
23
  "joi": "^17.12.1",
23
24
  "joi-to-swagger": "^6.2.0",
24
25
  "lodash": "^4.17.21",
25
26
  "mongodb": "^6.3.0",
26
27
  "nodemon": "^3.0.3",
28
+ "npm": "^10.9.1",
27
29
  "swagger-ui-express": "^5.0.0",
28
- "tango-api-schema": "^2.1.59",
29
- "tango-app-api-middleware": "^3.1.45",
30
+ "tango-api-schema": "^2.1.89",
31
+ "tango-app-api-middleware": "^3.1.43-alpha.10",
30
32
  "winston": "^3.11.0",
31
33
  "winston-daily-rotate-file": "^5.0.0"
32
34
  },
@@ -14,7 +14,8 @@ import { countDocumentsGroup, createGroupModel, findOneGroup } from '../service/
14
14
  // import { deleteOneAuthentication } from '../service/authentication.service.js';
15
15
  import { createBilling } from '../service/billing.service.js';
16
16
  import { createPaymentAccount } from '../service/paymentAccount.service.js';
17
-
17
+ import { countDocumentsClusters, createclusterModel } from '../service/cluster.service.js';
18
+ import { countDocumentsTeams } from '../service/teams.service.js';
18
19
 
19
20
  export async function create( req, res ) {
20
21
  try {
@@ -42,7 +43,7 @@ export async function create( req, res ) {
42
43
  const tangoId = count + 1;
43
44
  const generatedName = inputData.clientName.replace( /[^A-Z0-9]+/ig, '' );
44
45
  const product = leadRecord?.planDetails?.product.map( ( value ) => ( { productName: value } ) );
45
- const getPermission = await findOneStandaredRole( { roleName: 'superadmin', userType: 'client' }, { permission: 1 } );
46
+ const getPermission = await findOneStandaredRole( { roleName: 'superadmin', userType: 'client' }, { permission: 1, rolespermission: 1 } );
46
47
  const userQuery = {
47
48
  email: leadRecord?.corporateEmail,
48
49
  };
@@ -78,9 +79,26 @@ export async function create( req, res ) {
78
79
  'auditConfigs.traxQueueName.uniformDetection': `${generatedName}-uniformDetection`,
79
80
  'auditConfigs.traxQueueName.mobileDetection': `${generatedName}-mobileDetection`,
80
81
  'auditConfigs.traxQueueName.cameraAngleChange': `${generatedName}-cameraAngleChange`,
82
+ };
81
83
 
84
+ record.featureConfigs = {};
85
+ if ( product && product.length > 0 ) {
86
+ for ( let data of product ) {
87
+ record.featureConfigs.isNewDashboard = true;
88
+
89
+ if ( data.productName === 'tangoTraffic' ) {
90
+ record.featureConfigs.isNewTraffic = true;
91
+ record.featureConfigs.isNewReports = true;
92
+ }
93
+ if ( data.productName === 'tangoZone' ) {
94
+ record.featureConfigs.isNewZone = true;
95
+ }
96
+ if ( data.productName === 'tangoTrax' ) {
97
+ record.featureConfigs. isTrax= true;
98
+ }
99
+ }
100
+ }
82
101
 
83
- };
84
102
 
85
103
  const insertClient = await insert( record );
86
104
 
@@ -88,8 +106,10 @@ export async function create( req, res ) {
88
106
 
89
107
  const customer = await createCustomer( { name: user.userName, email: user.email, clientId: insertedClientRecord.clientId } );
90
108
 
91
- const virtualAccount = await createVirtualAccount( { receiverTypes: [ 'bank_account' ], description: `Virtual Account for ${insertedClientRecord.clientId}`,
92
- customerId: customer.id, notes: { createdAt: new Date(), createdBy: req.user?.email } } );
109
+ const virtualAccount = await createVirtualAccount( {
110
+ receiverTypes: [ 'bank_account' ], description: `Virtual Account for ${insertedClientRecord.clientId}`,
111
+ customerId: customer.id, notes: { createdAt: new Date(), createdBy: req.user?.email },
112
+ } );
93
113
 
94
114
  const paymentAccount = {
95
115
  clientId: insertedClientRecord.clientId,
@@ -111,6 +131,17 @@ export async function create( req, res ) {
111
131
 
112
132
  await createPaymentAccount( paymentAccount );
113
133
 
134
+ const defaultcluster = {
135
+ 'clusterName': 'All stores',
136
+ 'description': 'Contains all the onboarded stores',
137
+ 'stores': [],
138
+ 'Teamlead': [],
139
+ 'clientId': insertedClientRecord.clientId,
140
+ 'isDefaults': true,
141
+ };
142
+
143
+ await createclusterModel( defaultcluster );
144
+
114
145
 
115
146
  const defaultGroup = {
116
147
  'groupName': 'All stores',
@@ -293,6 +324,7 @@ export async function create( req, res ) {
293
324
  userType: 'client',
294
325
  refreshToken: null,
295
326
  permission: getPermission?.permission,
327
+ rolespermission: getPermission?.rolespermission,
296
328
  clientId: String( tangoId ),
297
329
  };
298
330
  // await deleteOneAuthentication( { user: user?._id, type: 'retail' } );
@@ -515,7 +547,44 @@ export async function clientDetails( req, res ) {
515
547
  }
516
548
  export async function detailedAllClientCount( req, res ) {
517
549
  try {
550
+ const field = { clientName: 1, clientId: 1 };
551
+ let Assinedclient = [];
552
+ if ( req?.user?.role === 'superadmin' ) {
553
+ Assinedclient = await findClient( {}, field );
554
+ Assinedclient = Assinedclient.map( ( data ) => data.clientId );
555
+ } else {
556
+ const clientQuery = [
557
+ {
558
+ $match: {
559
+ userEmail: req?.user?.email,
560
+ assignedType: { $eq: 'client' },
561
+ },
562
+ },
563
+ {
564
+ $group: {
565
+ _id: null,
566
+ clientId: { $addToSet: '$assignedValue' },
567
+ },
568
+ },
569
+ {
570
+ $project: {
571
+ _id: 0,
572
+ clientId: 1,
573
+ },
574
+ },
575
+
576
+ ];
577
+ const clientList = await aggregateUserAssignedStore( clientQuery );
578
+ if ( clientList[0]?.clientId?.length != 0 ) {
579
+ Assinedclient = clientList[0]?.clientId;
580
+ }
581
+ }
518
582
  const query = [
583
+ {
584
+ $match: {
585
+ clientId: { $in: Assinedclient },
586
+ },
587
+ },
519
588
  {
520
589
  $project: {
521
590
  activeClient: { $cond: [ { $eq: [ '$status', 'active' ] }, 1, 0 ] },
@@ -579,11 +648,15 @@ export async function detailedAllClientCount( req, res ) {
579
648
  },
580
649
  ];
581
650
  const result = await aggregateClient( query );
582
- const activeStores = await findStore( { 'status': 'active' }, { storeId: 1 } );
651
+ const activeStores = await findStore( {
652
+ 'clientId': { $in: Assinedclient },
653
+ 'status': 'active',
654
+ }, { storeId: 1 } );
583
655
  let yettoInstallCount = await aggregateTickets( [
584
656
  {
585
657
  $match: {
586
658
  $and: [
659
+ { 'basicDetails.clientId': { $in: Assinedclient } },
587
660
  { issueType: 'installation' },
588
661
  { 'status': { $ne: 'closed' } },
589
662
  ],
@@ -599,7 +672,7 @@ export async function detailedAllClientCount( req, res ) {
599
672
  if ( result.length == 0 ) {
600
673
  return res.sendError( 'No Data Found', 204 );
601
674
  }
602
- result[0].activeStoresCount = activeStores.length-yettoInstallCount.length;
675
+ result[0].activeStoresCount = activeStores.length>0?Math.abs( activeStores.length - yettoInstallCount.length ):0;
603
676
  result[0].activeCameraCount = activeCameras;
604
677
  return res.sendSuccess( { result: result } );
605
678
  } catch ( error ) {
@@ -1112,7 +1185,7 @@ export async function updateDocuments( req, res ) {
1112
1185
 
1113
1186
  export async function getAuditConfiguration( req, res ) {
1114
1187
  try {
1115
- const query ={
1188
+ const query = {
1116
1189
  clientId: req.params?.id,
1117
1190
  };
1118
1191
  const fields = {
@@ -1139,14 +1212,14 @@ export async function auditConfiguration( req, res ) {
1139
1212
  try {
1140
1213
  const inputData = req.body;
1141
1214
  const openSearch = JSON.parse( process.env.OPENSEARCH );
1142
- const query ={
1215
+ const query = {
1143
1216
  clientId: req.params?.id,
1144
1217
  };
1145
- const fields ={
1218
+ const fields = {
1146
1219
  auditConfigs: 1, _id: 0,
1147
1220
  };
1148
1221
  const previousClient = await findOneClient( query, fields );
1149
- const record ={
1222
+ const record = {
1150
1223
  'auditConfigs.count': inputData.count,
1151
1224
  'auditConfigs.audit': inputData.audit,
1152
1225
  'auditConfigs.ratio': Number( normalizeNumber( inputData.ratio, 0, 100 ) ),
@@ -1760,10 +1833,12 @@ export async function clientListV1( req, res ) {
1760
1833
  clientId: { $toInt: '$clientId' },
1761
1834
  onboardedStores: 1,
1762
1835
  installedStore: 1,
1763
- activeStores: { $max: [
1764
- { $subtract: [ '$activeStores', '$installedPending' ] },
1765
- 0,
1766
- ] },
1836
+ activeStores: {
1837
+ $max: [
1838
+ { $subtract: [ '$activeStores', '$installedPending' ] },
1839
+ 0,
1840
+ ],
1841
+ },
1767
1842
  InactiveStores: 1,
1768
1843
  ProcessingStatus: 1,
1769
1844
  clientName: 1,
@@ -1805,8 +1880,8 @@ export async function clientListV1( req, res ) {
1805
1880
  return res.sendError( 'No Data Found', 204 );
1806
1881
  }
1807
1882
 
1808
- if ( inputData.sortColumName&&inputData.sortColumName!=''&& req.body.sortBy&&req.body.sortBy!='' ) {
1809
- if ( inputData.sortColumName==='clientName' ) {
1883
+ if ( inputData.sortColumName && inputData.sortColumName != '' && req.body.sortBy && req.body.sortBy != '' ) {
1884
+ if ( inputData.sortColumName === 'clientName' ) {
1810
1885
  clientQuery.push(
1811
1886
  {
1812
1887
  $project: {
@@ -1858,15 +1933,15 @@ export async function clientListV1( req, res ) {
1858
1933
  exportResult.push( {
1859
1934
  'Brand Name': client.clientName,
1860
1935
  'Brand ID': client.clientId,
1861
- 'Onboarded Stores': client.onboardedStores||0,
1936
+ 'Onboarded Stores': client.onboardedStores || 0,
1862
1937
  'Installed Stores': client.installedStore || 0,
1863
- 'Progress Status': client.ProgressBar||0,
1938
+ 'Progress Status': client.ProgressBar || 0,
1864
1939
  'Active Stores': client.activeStores || 0,
1865
1940
  'In-Active Stores': client.InactiveStores || 0,
1866
1941
  'Pending Configuration': client.installedPending || 0,
1867
- 'Payment Plan': client.PaymentPlan == 'free'?'Lifetime Free':client.PaymentPlan,
1942
+ 'Payment Plan': client.PaymentPlan == 'free' ? 'Lifetime Free' : client.PaymentPlan,
1868
1943
  'Subscription Plan': client.subscriptionPlan,
1869
- 'Processing Status': client.ProcessingStatus=='active'?'Activated':client.ProcessingStatus=='deactive'?'Deactivated':client.ProcessingStatus,
1944
+ 'Processing Status': client.ProcessingStatus == 'active' ? 'Activated' : client.ProcessingStatus == 'deactive' ? 'Deactivated' : client.ProcessingStatus,
1870
1945
  } );
1871
1946
  }
1872
1947
  await download( exportResult, res );
@@ -1903,6 +1978,8 @@ export async function detailedClientCount( req, res ) {
1903
1978
  };
1904
1979
  result['totalStoreCount'] = await countDocumentsStore( { clientId: inputData.clientId } );
1905
1980
  result['totalGroupCount'] = await countDocumentsGroup( { clientId: inputData.clientId, isActive: true } );
1981
+ result['totalclusterCount'] = await countDocumentsClusters( { clientId: inputData.clientId } );
1982
+ result['totalTeamsCount'] = await countDocumentsTeams( { clientId: inputData.clientId } );
1906
1983
  result['totalCameraCount'] = await countDocumentsCamera( { clientId: inputData.clientId } );
1907
1984
  result['totalUserCount'] = await countDocumentsUser( { clientId: inputData.clientId, userType: 'client' } );
1908
1985
 
@@ -1929,7 +2006,7 @@ export async function detailedClientCount( req, res ) {
1929
2006
  },
1930
2007
  ] );
1931
2008
 
1932
- if ( findCsm&&findCsm.length>0 ) {
2009
+ if ( findCsm && findCsm.length > 0 ) {
1933
2010
  let finduser = await findOneUser( { email: findCsm[0].userEmail }, { userName: 1, email: 1, countryCode: 1, mobileNumber: 1 } );
1934
2011
  result['csm'] = finduser;
1935
2012
  }
@@ -0,0 +1,27 @@
1
+ import clusterModel from 'tango-api-schema/schema/cluster.model.js';
2
+
3
+ export async function updateOneCluster( query, record ) {
4
+ return await clusterModel.updateOne( query, { $set: record } );
5
+ };
6
+
7
+ export async function updateCluster( query, record ) {
8
+ return await clusterModel.updateMany( query, record );
9
+ };
10
+
11
+ export async function aggregateCluster( query ) {
12
+ return await clusterModel.aggregate( query );
13
+ };
14
+
15
+ export async function findOneCluster( query ={}, field={} ) {
16
+ return await clusterModel.findOne( query, field );
17
+ };
18
+ export async function deleteCluster( query ={} ) {
19
+ return await clusterModel.deleteOne( query );
20
+ };
21
+
22
+ export async function createclusterModel( data ) {
23
+ return await clusterModel.create( data );
24
+ };
25
+ export function countDocumentsClusters( query ) {
26
+ return clusterModel.countDocuments( query );
27
+ }
@@ -0,0 +1,30 @@
1
+ import teamsModel from 'tango-api-schema/schema/teams.model.js';
2
+
3
+
4
+ export async function createTeamsModel( data ) {
5
+ return await teamsModel.create( data );
6
+ };
7
+ export async function updateOneTeams( query, record ) {
8
+ return await teamsModel.updateOne( query, { $set: record }, { upsert: true } );
9
+ };
10
+
11
+ export async function aggregateTeams( query ) {
12
+ return await teamsModel.aggregate( query );
13
+ };
14
+ export async function deleteTeams( query ={} ) {
15
+ return await teamsModel.deleteOne( query );
16
+ };
17
+
18
+ export async function findOneTeams( query ={}, field={} ) {
19
+ return await teamsModel.findOne( query, field );
20
+ };
21
+ export async function findteams( query ={}, field={} ) {
22
+ return await teamsModel.find( query, field );
23
+ };
24
+
25
+ export async function updateOneTeamModel( query, record ) {
26
+ return await teamsModel.updateOne( query, record );
27
+ }
28
+ export function countDocumentsTeams( query ) {
29
+ return teamsModel.countDocuments( query );
30
+ }