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

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.14",
3
+ "version": "3.0.0-alpha.15",
4
4
  "description": "Traffic Analysis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,4 +1,4 @@
1
- import { logger, download } from 'tango-app-api-middleware';
1
+ import { logger, download, signedUrl } from 'tango-app-api-middleware';
2
2
  import * as clientService from '../services/clients.services.js';
3
3
  import {
4
4
  aggregateStore,
@@ -9,6 +9,7 @@ import { aggregateGroup } from '../services/group.service.js';
9
9
  import dayjs from 'dayjs';
10
10
  import mongoose from 'mongoose';
11
11
  const ObjectId = mongoose.Types.ObjectId;
12
+ import { findCamera } from '../services/camera.service.js';
12
13
 
13
14
  // Lamda Service Call //
14
15
  async function LamdaServiceCall( url, data ) {
@@ -1318,6 +1319,37 @@ export const getMySubscription = async ( req, res ) => {
1318
1319
  }
1319
1320
  };
1320
1321
 
1322
+ export const getStoreCameraImage = async ( req, res ) => {
1323
+ try {
1324
+ let reqestData = req.body;
1325
+ if ( reqestData.storeId && reqestData.storeId.length > 0 ) {
1326
+ const bucket= JSON.parse( process.env.BUCKET );
1327
+ if ( bucket && bucket.baseImage && bucket.baseImage != '' ) {
1328
+ const camera = await findCamera( { storeId: reqestData.storeId[0], isUp: true, isActivated: true }, { thumbnailImage: 1 } );
1329
+ if ( camera && camera.thumbnailImage && camera.thumbnailImage != '' ) {
1330
+ const params = {
1331
+ file_path: camera.thumbnailImage,
1332
+ Bucket: bucket.baseImage,
1333
+ };
1334
+ let cameraBaseImage = await signedUrl( params );
1335
+ let resultData = { cameraBaseImage: cameraBaseImage };
1336
+
1337
+ return res.sendSuccess( resultData );
1338
+ } else {
1339
+ return res.sendError( 'No Camera', 400 );
1340
+ }
1341
+ } else {
1342
+ return res.sendError( 'Bucket Name Missing', 400 );
1343
+ }
1344
+ } else {
1345
+ return res.sendError( 'Store Id rewuired', 400 );
1346
+ }
1347
+ } catch ( error ) {
1348
+ logger.error( { error: error, message: req.query, function: 'getMySubscription' } );
1349
+ return res.sendError( { error: error }, 500 );
1350
+ }
1351
+ };
1352
+
1321
1353
  // async function getGeocodedAddress( lat, lng ) {
1322
1354
  // try {
1323
1355
  // const apiKey = 'AIzaSyDlOezgwQO0JviD0aizrCuN1FY9tcWfR3o'; // Use this if you're using dotenv
@@ -207,3 +207,12 @@ export const getMyProductSchema = joi.object( {
207
207
  export const getMyProductParams = {
208
208
  body: getMyProductSchema,
209
209
  };
210
+
211
+ export const getStoreCameraImageSchema = joi.object( {
212
+ clientId: joi.string().required(),
213
+ storeId: joi.array().optional().empty(),
214
+ } );
215
+
216
+ export const getStoreCameraImageParams = {
217
+ body: getStoreCameraImageSchema,
218
+ };
@@ -53,6 +53,7 @@ import {
53
53
  headerGroupsV1,
54
54
  isAllowedClient,
55
55
  getMySubscription,
56
+ getStoreCameraImage,
56
57
  } from '../controllers/tangoTrafficV1.controllers.js';
57
58
 
58
59
 
@@ -184,6 +185,7 @@ analysisTrafficRouter
184
185
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
185
186
  ],
186
187
  } ), validate( validationDtos.validateHeaderParams ), headerStoresV1 )
187
- .post( '/getMySubscription', isAllowedSessionHandler, validate( validationDtos.getMyProductParams ), getMySubscription );
188
+ .post( '/getMySubscription', isAllowedSessionHandler, validate( validationDtos.getMyProductParams ), getMySubscription )
189
+ .post( '/getStoreCameraImage', isAllowedSessionHandler, validate( validationDtos.getStoreCameraImageParams ), getStoreCameraImage );
188
190
 
189
191
  export default analysisTrafficRouter;
@@ -0,0 +1,9 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export const findCamera = async ( query={}, field={}, sortBy={ updatedAt: -1 } ) => {
4
+ try {
5
+ return await model.cameraModel.findOne( query, field ).sort( sortBy );
6
+ } catch ( error ) {
7
+ return error;
8
+ }
9
+ };