tango-app-api-analysis-traffic 3.0.0-alpha.12 → 3.0.0-alpha.14

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-analysis-traffic",
3
- "version": "3.0.0-alpha.12",
3
+ "version": "3.0.0-alpha.14",
4
4
  "description": "Traffic Analysis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -2,6 +2,7 @@ import { logger, download } from 'tango-app-api-middleware';
2
2
  import * as clientService from '../services/clients.services.js';
3
3
  import {
4
4
  aggregateStore,
5
+ findOneStore,
5
6
  } from '../services/stores.service.js';
6
7
  import { aggregateUserAssignedStore, findOneUserAssignedStore } from '../services/userAssignedStore.service.js';
7
8
  import { aggregateGroup } from '../services/group.service.js';
@@ -27,8 +28,8 @@ async function LamdaServiceCall( url, data ) {
27
28
  const json = await response.json();
28
29
  return json;
29
30
  } catch ( error ) {
30
- console.log( 'error =>', error );
31
31
  logger.error( { error: error, message: data, function: 'LamdaServiceCall' } );
32
+ return false;
32
33
  }
33
34
  }
34
35
 
@@ -499,7 +500,6 @@ export const storesMapV1 = async ( req, res ) => {
499
500
  }
500
501
  }
501
502
  } catch ( error ) {
502
- console.log( 'storesMapV1 error =>', error );
503
503
  logger.error( { error: error, message: req.query, function: 'storesMapV1' } );
504
504
  return res.sendError( { error: error }, 500 );
505
505
  }
@@ -625,8 +625,7 @@ export const headerGroupsV1 = async ( req, res ) => {
625
625
  return res.sendError( 'No Group', 400 );
626
626
  }
627
627
  } catch ( error ) {
628
- console.log( 'error =>', error );
629
- logger.error( { error: error, message: req.query, function: 'trafficCards' } );
628
+ logger.error( { error: error, message: req.query, function: 'headerGroupsV1' } );
630
629
  return res.sendError( { error: error }, 500 );
631
630
  }
632
631
  };
@@ -730,7 +729,6 @@ export const headerStoresV1 = async ( req, res ) => {
730
729
  return res.sendError( 'No Stores', 400 );
731
730
  }
732
731
  } catch ( error ) {
733
- console.log( 'headerStoresV1 =>', error );
734
732
  logger.error( { error: error, message: req.query, function: 'headerStoresV1' } );
735
733
  return res.sendError( { error: error }, 500 );
736
734
  }
@@ -795,7 +793,6 @@ async function getAllStores( getUserEmail, getClientId, getUserType, getRole ) {
795
793
  return false;
796
794
  }
797
795
  } catch ( error ) {
798
- console.log( 'getAllStores =>', error );
799
796
  logger.error( { error: error, message: req.query, function: 'getAllStores' } );
800
797
  }
801
798
  };
@@ -831,8 +828,8 @@ async function getAssignedStores( clientId, userEmail, assignedType ) {
831
828
  return false;
832
829
  }
833
830
  } catch ( error ) {
834
- console.log( 'getAssignedStores error =>', error );
835
831
  logger.error( { error: error, message: data, function: 'getAssignedStores' } );
832
+ return false;
836
833
  }
837
834
  }
838
835
 
@@ -898,8 +895,8 @@ async function getAssignedGroupStores( clientId, userEmail, assignedType ) {
898
895
  return false;
899
896
  }
900
897
  } catch ( error ) {
901
- console.log( 'getAssignedGroupStores error =>', error );
902
898
  logger.error( { error: error, message: data, function: 'getAssignedGroupStores' } );
899
+ return false;
903
900
  }
904
901
  }
905
902
 
@@ -933,8 +930,8 @@ async function getAssignedAllStores( userClientId ) {
933
930
  return false;
934
931
  }
935
932
  } catch ( error ) {
936
- console.log( 'getAssignedAllStores error =>', error );
937
933
  logger.error( { error: error, message: data, function: 'getAssignedAllStores' } );
934
+ return false;
938
935
  }
939
936
  }
940
937
 
@@ -973,8 +970,8 @@ async function getGroupStores( userClientId, groupList ) {
973
970
  return false;
974
971
  }
975
972
  } catch ( error ) {
976
- console.log( 'getGroupStores error =>', error );
977
973
  logger.error( { error: error, message: data, function: 'getGroupStores' } );
974
+ return false;
978
975
  }
979
976
  }
980
977
 
@@ -1014,8 +1011,8 @@ async function getLocationStores( userClientId, cityList ) {
1014
1011
  return false;
1015
1012
  }
1016
1013
  } catch ( error ) {
1017
- console.log( 'getLocationStores error =>', error );
1018
1014
  logger.error( { error: error, message: data, function: 'getLocationStores' } );
1015
+ return false;
1019
1016
  }
1020
1017
  }
1021
1018
 
@@ -1048,8 +1045,8 @@ async function getGroupIds( userClientId ) {
1048
1045
  return false;
1049
1046
  }
1050
1047
  } catch ( error ) {
1051
- console.log( 'getGroupIds error =>', error );
1052
1048
  logger.error( { error: error, message: data, function: 'getGroupIds' } );
1049
+ return false;
1053
1050
  }
1054
1051
  }
1055
1052
 
@@ -1088,8 +1085,8 @@ async function getAssignedGroupIds( userClientId, getUserEmail ) {
1088
1085
  return false;
1089
1086
  }
1090
1087
  } catch ( error ) {
1091
- console.log( 'getAssignedGroupIds error =>', error );
1092
1088
  logger.error( { error: error, message: data, function: 'getAssignedGroupIds' } );
1089
+ return false;
1093
1090
  }
1094
1091
  }
1095
1092
 
@@ -1111,8 +1108,8 @@ async function getCityStores( userClientId, getUserEmail, getRole, requestCity,
1111
1108
  return false;
1112
1109
  }
1113
1110
  } catch ( error ) {
1114
- console.log( 'getAssignedGroupIds error =>', error );
1115
1111
  logger.error( { error: error, message: data, function: 'getAssignedGroupIds' } );
1112
+ return false;
1116
1113
  }
1117
1114
  }
1118
1115
 
@@ -1211,8 +1208,8 @@ async function getGroupStoresIds( userClientId, storeIds, getRole, getUserType,
1211
1208
  return false;
1212
1209
  }
1213
1210
  } catch ( error ) {
1214
- console.log( 'getGroupIds error =>', error );
1215
1211
  logger.error( { error: error, message: data, function: 'getGroupIds' } );
1212
+ return false;
1216
1213
  }
1217
1214
  }
1218
1215
 
@@ -1254,6 +1251,73 @@ export async function isAllowedClient( req, res, next ) {
1254
1251
  }
1255
1252
  }
1256
1253
 
1254
+ export const getMySubscription = async ( req, res ) => {
1255
+ try {
1256
+ let reqestData = req.body;
1257
+ let getClientData = await clientService.findOne( { clientId: reqestData.clientId }, { planDetails: 1 } );
1258
+ if ( getClientData ) {
1259
+ if ( getClientData.planDetails && getClientData.planDetails.product && getClientData.planDetails.product.length>0 ) {
1260
+ let clientSubscription = {};
1261
+ let clientProducts = {
1262
+ tangoTraffic: false,
1263
+ tangoZone: false,
1264
+ tangoTrax: false,
1265
+ };
1266
+ clientSubscription.subscriptionType = getClientData.planDetails.subscriptionType;
1267
+ let actualProduct = getClientData.planDetails.product;
1268
+ for ( let clientIndex = 0; clientIndex < actualProduct.length; clientIndex++ ) {
1269
+ if ( actualProduct[clientIndex].productName == 'tangoTraffic' ) {
1270
+ clientProducts.tangoTraffic = true;
1271
+ }
1272
+ if ( actualProduct[clientIndex].productName == 'tangoZone' ) {
1273
+ clientProducts.tangoZone = true;
1274
+ }
1275
+ if ( actualProduct[clientIndex].tangoTrax == 'tangoTrax' ) {
1276
+ clientProducts.tangoTrax = true;
1277
+ }
1278
+ }
1279
+ clientSubscription.product = clientProducts;
1280
+ let storeSubscription = {};
1281
+ let storeProducts = {
1282
+ tangoTraffic: false,
1283
+ tangoZone: false,
1284
+ tangoTrax: false,
1285
+ };
1286
+ if ( reqestData.storeId && reqestData.storeId.length>0 ) {
1287
+ let getStoreData = await findOneStore( { clientId: reqestData.clientId, storeId: { $in: reqestData.storeId[0] } }, { product: 1 } );
1288
+ if ( getStoreData ) {
1289
+ for ( let storeIndex = 0; storeIndex < getStoreData.product.length; storeIndex++ ) {
1290
+ if ( getStoreData.product[storeIndex] == 'tangoTraffic' ) {
1291
+ storeProducts.tangoTraffic = true;
1292
+ }
1293
+ if ( getStoreData.product[storeIndex] == 'tangoZone' ) {
1294
+ storeProducts.tangoZone = true;
1295
+ }
1296
+ if ( getStoreData.product[storeIndex] == 'tangoTrax' ) {
1297
+ storeProducts.tangoTrax = true;
1298
+ }
1299
+ }
1300
+ storeSubscription.product = storeProducts;
1301
+ } else {
1302
+ storeSubscription.product = [];
1303
+ }
1304
+ } else {
1305
+ storeSubscription.product = [];
1306
+ }
1307
+ let resultData = { clientSubscription, storeSubscription };
1308
+ return res.sendSuccess( resultData );
1309
+ } else {
1310
+ return res.sendError( 'Not Subscribe', 400 );
1311
+ }
1312
+ } else {
1313
+ return res.sendError( 'Invalid Client Id', 400 );
1314
+ }
1315
+ } catch ( error ) {
1316
+ logger.error( { error: error, message: req.query, function: 'getMySubscription' } );
1317
+ return res.sendError( { error: error }, 500 );
1318
+ }
1319
+ };
1320
+
1257
1321
  // async function getGeocodedAddress( lat, lng ) {
1258
1322
  // try {
1259
1323
  // const apiKey = 'AIzaSyDlOezgwQO0JviD0aizrCuN1FY9tcWfR3o'; // Use this if you're using dotenv
@@ -198,3 +198,12 @@ export const validateHeaderSchema = joi.object( {
198
198
  export const validateHeaderParams = {
199
199
  body: validateHeaderSchema,
200
200
  };
201
+
202
+ export const getMyProductSchema = joi.object( {
203
+ clientId: joi.string().required(),
204
+ storeId: joi.array().optional().empty(),
205
+ } );
206
+
207
+ export const getMyProductParams = {
208
+ body: getMyProductSchema,
209
+ };
@@ -52,6 +52,7 @@ import {
52
52
  headerLocationsV1,
53
53
  headerGroupsV1,
54
54
  isAllowedClient,
55
+ getMySubscription,
55
56
  } from '../controllers/tangoTrafficV1.controllers.js';
56
57
 
57
58
 
@@ -182,6 +183,7 @@ analysisTrafficRouter
182
183
  userType: [ 'tango', 'client' ], access: [
183
184
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
184
185
  ],
185
- } ), validate( validationDtos.validateHeaderParams ), headerStoresV1 );
186
+ } ), validate( validationDtos.validateHeaderParams ), headerStoresV1 )
187
+ .post( '/getMySubscription', isAllowedSessionHandler, validate( validationDtos.getMyProductParams ), getMySubscription );
186
188
 
187
189
  export default analysisTrafficRouter;
@@ -7,3 +7,11 @@ export function aggregateStore( query ) {
7
7
  return error;
8
8
  }
9
9
  };
10
+
11
+ export const findOneStore = async ( query={}, fields={} ) => {
12
+ try {
13
+ return await model.storeModel.findOne( query, fields );
14
+ } catch ( error ) {
15
+ return error;
16
+ }
17
+ };