tango-app-api-client 3.0.33-dev → 3.0.34-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
|
@@ -39,7 +39,7 @@ export async function create( req, res ) {
|
|
|
39
39
|
const generatedName = inputData.clientName.replace( /[^A-Z0-9]+/ig, '' );
|
|
40
40
|
const product = leadRecord?.planDetails?.product.map( ( value ) => ( { productName: value } ) );
|
|
41
41
|
const getPermission = await findOneStandaredRole( { roleName: 'superadmin', userType: 'client' }, { permission: 1 } );
|
|
42
|
-
const userQuery={
|
|
42
|
+
const userQuery = {
|
|
43
43
|
email: leadRecord?.corporateEmail,
|
|
44
44
|
};
|
|
45
45
|
const user = await findOneUser( userQuery );
|
|
@@ -71,6 +71,117 @@ export async function create( req, res ) {
|
|
|
71
71
|
|
|
72
72
|
const insertClient = await insert( record );
|
|
73
73
|
|
|
74
|
+
// For old dashboard insert
|
|
75
|
+
|
|
76
|
+
const insertedClientRecord = await findOneClient( { clientId: record.clientId }, {} );
|
|
77
|
+
|
|
78
|
+
const oldBrandInsertData = {
|
|
79
|
+
'_id': insertedClientRecord._id,
|
|
80
|
+
'brandName': insertedClientRecord.clientName,
|
|
81
|
+
'brandIndex': insertedClientRecord.tangoId,
|
|
82
|
+
'client_id': insertedClientRecord.clientId,
|
|
83
|
+
'phone': user.mobileNumber,
|
|
84
|
+
'email': user.email,
|
|
85
|
+
'dialCode': user.countryCode,
|
|
86
|
+
'name': user.userName,
|
|
87
|
+
'cameraCount': insertedClientRecord.planDetails.totalCamera,
|
|
88
|
+
'apiKey': insertedClientRecord.clientApi.apiKey,
|
|
89
|
+
'clientStatus': insertedClientRecord.status,
|
|
90
|
+
'client_type': insertedClientRecord.planDetails.paymentStatus,
|
|
91
|
+
'activeMenu': [
|
|
92
|
+
'reports',
|
|
93
|
+
'birdsEye',
|
|
94
|
+
'tangoZone',
|
|
95
|
+
'tangoTraffic',
|
|
96
|
+
'Support',
|
|
97
|
+
'footFallDirectory',
|
|
98
|
+
'tangoSOP',
|
|
99
|
+
],
|
|
100
|
+
'planType': insertedClientRecord.planDetails.subscriptionPeriod,
|
|
101
|
+
'storeCount': insertedClientRecord.planDetails.totalStores,
|
|
102
|
+
'squareFeet': insertedClientRecord.planDetails.storeSize,
|
|
103
|
+
'subscription': insertedClientRecord.planDetails.subscriptionType,
|
|
104
|
+
'subscription_status': true,
|
|
105
|
+
'subscribed_features': {
|
|
106
|
+
'tango_traffic': false,
|
|
107
|
+
'tango_zone': false,
|
|
108
|
+
'tango_revop': false,
|
|
109
|
+
'tango_storeops': false,
|
|
110
|
+
'controlroom': false,
|
|
111
|
+
'live_data': false,
|
|
112
|
+
'normalization_features': false,
|
|
113
|
+
'actual_features': false,
|
|
114
|
+
},
|
|
115
|
+
'store_added_status': true,
|
|
116
|
+
'terms_conditions': true,
|
|
117
|
+
'otp_verified': true,
|
|
118
|
+
'price': 6510,
|
|
119
|
+
'currency_type': 'rupees',
|
|
120
|
+
'domains': [],
|
|
121
|
+
'store_radius_config': 500,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
insertedClientRecord.planDetails.product.forEach( ( element ) => {
|
|
125
|
+
if ( element.productName === 'tangoTraffic' ) {
|
|
126
|
+
oldBrandInsertData.subscribed_features.tango_traffic = true;
|
|
127
|
+
}
|
|
128
|
+
if ( element.productName === 'tangoZone' ) {
|
|
129
|
+
oldBrandInsertData.subscribed_features.tango_zone = true;
|
|
130
|
+
}
|
|
131
|
+
if ( element.productName === 'prioritySupport' ) {
|
|
132
|
+
oldBrandInsertData.subscribed_features.tango_storeops = true;
|
|
133
|
+
}
|
|
134
|
+
} );
|
|
135
|
+
|
|
136
|
+
switch ( insertedClientRecord.status ) {
|
|
137
|
+
case 'active':
|
|
138
|
+
oldBrandInsertData.clientStatus = 'live';
|
|
139
|
+
break;
|
|
140
|
+
case 'hold':
|
|
141
|
+
oldBrandInsertData.clientStatus = 'hold';
|
|
142
|
+
break;
|
|
143
|
+
case 'suspended':
|
|
144
|
+
oldBrandInsertData.clientStatus = 'suspended';
|
|
145
|
+
break;
|
|
146
|
+
case 'deactive':
|
|
147
|
+
oldBrandInsertData.clientStatus = 'deactivated';
|
|
148
|
+
break;
|
|
149
|
+
default:
|
|
150
|
+
oldBrandInsertData.clientStatus = 'live';
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
switch ( insertedClientRecord.planDetails.paymentStatus ) {
|
|
154
|
+
case 'free':
|
|
155
|
+
oldBrandInsertData.client_type = 'free';
|
|
156
|
+
break;
|
|
157
|
+
case 'trial':
|
|
158
|
+
oldBrandInsertData.client_type = 'trial';
|
|
159
|
+
break;
|
|
160
|
+
case 'paid':
|
|
161
|
+
oldBrandInsertData.client_type = 'paid';
|
|
162
|
+
break;
|
|
163
|
+
default:
|
|
164
|
+
oldBrandInsertData.client_type = 'trial';
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
const oldDefaultRolesInsertData = {
|
|
169
|
+
'_id': user._id,
|
|
170
|
+
'client_id': insertedClientRecord.clientId,
|
|
171
|
+
'brandId': insertedClientRecord._id,
|
|
172
|
+
'name': user.userName,
|
|
173
|
+
'email': user.email,
|
|
174
|
+
'phone': user.mobileNumber,
|
|
175
|
+
'password': user.password,
|
|
176
|
+
'role': 'storesuperadmin',
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
await postApi( `${appConfig.url.oldapidomain}/oldBrandAdd`, oldBrandInsertData );
|
|
181
|
+
|
|
182
|
+
await postApi( `${appConfig.url.oldapidomain}/oldUserAdd`, [ oldDefaultRolesInsertData ] );
|
|
183
|
+
|
|
184
|
+
|
|
74
185
|
if ( insertClient ) {
|
|
75
186
|
const userRecord = {
|
|
76
187
|
role: 'superadmin',
|
|
@@ -130,11 +241,11 @@ export async function changeStatus( req, res, next ) {
|
|
|
130
241
|
export async function getClients( req, res ) {
|
|
131
242
|
try {
|
|
132
243
|
const field = { clientName: 1, clientId: 1 };
|
|
133
|
-
let result =[];
|
|
244
|
+
let result = [];
|
|
134
245
|
if ( req?.user?.role === 'superadmin' ) {
|
|
135
246
|
result = await findClient( {}, field );
|
|
136
247
|
} else {
|
|
137
|
-
const clientQuery =[
|
|
248
|
+
const clientQuery = [
|
|
138
249
|
{
|
|
139
250
|
$match: {
|
|
140
251
|
userEmail: req?.user?.email,
|
|
@@ -377,6 +488,27 @@ export async function updateBrandInfo( req, res ) {
|
|
|
377
488
|
await updateManyUser( { clientId: req.params?.id }, { isActive: false } );
|
|
378
489
|
}
|
|
379
490
|
|
|
491
|
+
const { data } = await getApi( `${appConfig.url.oldapidomain}/oldBrandGet/${req.params?.id}` );
|
|
492
|
+
|
|
493
|
+
switch ( req.body?.status ) {
|
|
494
|
+
case 'active':
|
|
495
|
+
data.clientStatus = 'live';
|
|
496
|
+
break;
|
|
497
|
+
case 'hold':
|
|
498
|
+
data.clientStatus = 'hold';
|
|
499
|
+
break;
|
|
500
|
+
case 'suspended':
|
|
501
|
+
data.clientStatus = 'suspended';
|
|
502
|
+
break;
|
|
503
|
+
case 'deactive':
|
|
504
|
+
data.clientStatus = 'deactivated';
|
|
505
|
+
break;
|
|
506
|
+
default:
|
|
507
|
+
data.clientStatus = 'live';
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
await postApi( `${appConfig.url.oldapidomain}/oldBrandUpdate/${data?._id}`, { clientStatus: data.clientStatus } );
|
|
511
|
+
|
|
380
512
|
if ( updateAck ) {
|
|
381
513
|
res.sendSuccess( { result: 'Updated Successfully' } );
|
|
382
514
|
}
|
|
@@ -531,6 +663,51 @@ export async function updateFeatureConfiguration( req, res ) {
|
|
|
531
663
|
|
|
532
664
|
const user = await getUserNameEmailById( req.userId );
|
|
533
665
|
|
|
666
|
+
const { data } = await getApi( `${appConfig.url.oldapidomain}/oldBrandGet/${req.params?.id}` );
|
|
667
|
+
|
|
668
|
+
if ( req.body?.open ) {
|
|
669
|
+
data.brandConfigs.storeOpenTime = req.body?.open;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
if ( req.body?.close ) {
|
|
673
|
+
data.brandConfigs.storeCloseTime = req.body?.open;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
if ( req.body?.missedOpportunityCalculation ) {
|
|
677
|
+
data.brandConfigs.missedOpportunityCalculate = req.body?.missedOpportunityCalculation;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
if ( req.body?.conversionCalculation ) {
|
|
681
|
+
data.brandConfigs.conversionCalculate = req.body?.conversionCalculation;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
if ( req.body?.billableCalculation ) {
|
|
685
|
+
data.brandConfigs.billableCalculate = req.body?.billableCalculation;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
if ( req.body?.bouncedLimitCondition ) {
|
|
689
|
+
data.brandConfigs.bouncedConfigTime = data.brandConfigs.bouncedConfigTime.replace( /^.+(?=\d)/, req.body?.bouncedLimitCondition );
|
|
690
|
+
data.brandConfigs.missedOpportunityEndTime = data.brandConfigs.missedOpportunityEndTime.replace( /^.+(?=\d)/, req.body?.bouncedLimitCondition );
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
if ( req.body?.bouncedLimitValue ) {
|
|
694
|
+
data.brandConfigs.bouncedConfigTime = data.brandConfigs.bouncedConfigTime.replace( /\d+/, req.body?.bouncedLimitValue );
|
|
695
|
+
data.brandConfigs.missedOpportunityStartTime = data.brandConfigs.missedOpportunityStartTime.replace( /\d+/, req.body?.bouncedLimitValue );
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
if ( req.body?.conversionCondition ) {
|
|
699
|
+
data.brandConfigs.conversionConfigTime = data.brandConfigs.conversionConfigTime.replace( /^.+(?=\d)/, req.body?.conversionCondition );
|
|
700
|
+
data.brandConfigs.missedOpportunityStartTime = data.brandConfigs.missedOpportunityStartTime.replace( /^.+(?=\d)/, req.body?.conversionCondition );
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
if ( req.body?.conversionValue ) {
|
|
704
|
+
data.brandConfigs.conversionConfigTime = data.brandConfigs.conversionConfigTime.replace( /\d+/, req.body?.conversionValue );
|
|
705
|
+
data.brandConfigs.missedOpportunityEndTime = data.brandConfigs.missedOpportunityEndTime.replace( /\d+/, req.body?.conversionValue );
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
await postApi( `${appConfig.url.oldapidomain}/oldBrandUpdate/${data?._id}`, { brandConfigs: data.brandConfigs } );
|
|
709
|
+
|
|
710
|
+
|
|
534
711
|
const logObj = {
|
|
535
712
|
clientId: req.params?.id,
|
|
536
713
|
userName: user?.userName,
|
|
@@ -880,7 +1057,7 @@ export async function clientList( req, res ) {
|
|
|
880
1057
|
);
|
|
881
1058
|
}
|
|
882
1059
|
const client = await aggregateClient( clientQuery );
|
|
883
|
-
for ( let i=0; i < client?.length; i++ ) {
|
|
1060
|
+
for ( let i = 0; i < client?.length; i++ ) {
|
|
884
1061
|
const query = [
|
|
885
1062
|
{
|
|
886
1063
|
$match: {
|
|
@@ -943,9 +1120,9 @@ export async function clientList( req, res ) {
|
|
|
943
1120
|
const storesQuery = [
|
|
944
1121
|
{
|
|
945
1122
|
$match:
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
1123
|
+
{
|
|
1124
|
+
clientId: client[i].clientId,
|
|
1125
|
+
},
|
|
949
1126
|
},
|
|
950
1127
|
{
|
|
951
1128
|
$count:
|
|
@@ -967,7 +1144,7 @@ export async function clientList( req, res ) {
|
|
|
967
1144
|
return list;
|
|
968
1145
|
} );
|
|
969
1146
|
const clientListResult = await Promise.all( promises );
|
|
970
|
-
const clientList= clientListResult.flat();
|
|
1147
|
+
const clientList = clientListResult.flat();
|
|
971
1148
|
const storeQuery = [
|
|
972
1149
|
{
|
|
973
1150
|
$match: {
|
|
@@ -1038,7 +1215,7 @@ export async function clientList( req, res ) {
|
|
|
1038
1215
|
'client Name': chunk[i]?.clientName,
|
|
1039
1216
|
'client Id': chunk[i]?.clientId,
|
|
1040
1217
|
'Active Store': chunk[i]?.activeStoreCount || 0,
|
|
1041
|
-
'Active Camera': chunk[i]?.activeCameraCount && chunk[i]?.activeCameraCount!=undefined? chunk[i]?.activeCameraCount: 0,
|
|
1218
|
+
'Active Camera': chunk[i]?.activeCameraCount && chunk[i]?.activeCameraCount != undefined ? chunk[i]?.activeCameraCount : 0,
|
|
1042
1219
|
'Payment Status': chunk[i]?.paymentStatus,
|
|
1043
1220
|
'Subs Plan': chunk[i]?.subscriptionType,
|
|
1044
1221
|
'Status': chunk[i]?.status,
|
|
@@ -1162,3 +1339,40 @@ export async function getActivityLogs( req, res ) {
|
|
|
1162
1339
|
return res.sendError( error, 500 );
|
|
1163
1340
|
}
|
|
1164
1341
|
}
|
|
1342
|
+
|
|
1343
|
+
async function postApi( url, data ) {
|
|
1344
|
+
const requestOptions = {
|
|
1345
|
+
method: 'POST',
|
|
1346
|
+
headers: {
|
|
1347
|
+
'Content-Type': 'application/json',
|
|
1348
|
+
'Authorization': 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66',
|
|
1349
|
+
},
|
|
1350
|
+
body: JSON.stringify( data ),
|
|
1351
|
+
};
|
|
1352
|
+
|
|
1353
|
+
try {
|
|
1354
|
+
const response = await fetch( url, requestOptions );
|
|
1355
|
+
await response.json();
|
|
1356
|
+
} catch ( error ) {
|
|
1357
|
+
logger.error( { error: error, message: data, function: 'postApi' } );
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
async function getApi( url ) {
|
|
1362
|
+
const requestOptions = {
|
|
1363
|
+
method: 'GET',
|
|
1364
|
+
headers: {
|
|
1365
|
+
'Content-Type': 'application/json',
|
|
1366
|
+
'Authorization': 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66',
|
|
1367
|
+
},
|
|
1368
|
+
};
|
|
1369
|
+
|
|
1370
|
+
try {
|
|
1371
|
+
const response = await fetch( url, requestOptions );
|
|
1372
|
+
const responseData = await response.json();
|
|
1373
|
+
return responseData;
|
|
1374
|
+
} catch ( error ) {
|
|
1375
|
+
logger.error( { error: error, message: 'Error in GET request', function: 'getApi' } );
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
|