diff --git a/extra-datasets/cities/demo-cities.json b/extra-datasets/cities/demo-cities.json deleted file mode 100644 index 2675d7b..0000000 --- a/extra-datasets/cities/demo-cities.json +++ /dev/null @@ -1,17 +0,0 @@ -[{ - "city": "New York", - "lat": 40.7128, - "lng": -74.0060 -},{ - "city":"London", - "lat": 51.5074, - "lng": -0.1278 -},{ - "city":"Paris", - "lat": 48.8566, - "lng": 2.3522 -},{ - "city":"Bondi Beach", - "lat": -33.8910, - "lng": 151.2769 -}] \ No newline at end of file diff --git a/package.json b/package.json index 24cfe13..14a733b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "overture-maps-api", - "version": "0.1.4", + "version": "0.1.5", "description": "", "author": "", "private": true, diff --git a/src/decorators/validate-lat-lng-user.decorator.ts b/src/decorators/validate-lat-lng-user.decorator.ts index c654c57..eb8bae3 100644 --- a/src/decorators/validate-lat-lng-user.decorator.ts +++ b/src/decorators/validate-lat-lng-user.decorator.ts @@ -1,5 +1,24 @@ import { Injectable, BadRequestException, ForbiddenException } from '@nestjs/common'; +const demoCities = [{ + "city": "New York", + "lat": 40.7128, + "lng": -74.0060 +},{ + "city":"London", + "lat": 51.5074, + "lng": -0.1278 +},{ + "city":"Paris", + "lat": 48.8566, + "lng": 2.3522 +},{ + "city":"Bondi Beach", + "lat": -33.8910, + "lng": 151.2769 +}] + + // Method decorator export function ValidateLatLngUser(): MethodDecorator { return function (target, propertyKey, descriptor: PropertyDescriptor) { @@ -12,7 +31,11 @@ export function ValidateLatLngUser(): MethodDecorator { const user = args[1] if (lat && lng && user?.isDemoAccount) { - throw new ForbiddenException('Demo accounts cannot access this feature'); + //check if lat / lng is found as a demo city + const foundCity = demoCities.find(city => city.lat === lat && city.lng === lng); + if (!foundCity) { + throw new BadRequestException(`Demo accounts can only access demo cities. These are ${demoCities.map(city => JSON.stringify(city)).join(", ")}`); + } } // Call the original method if validation passes diff --git a/src/interceptors/count-header.interceptor.ts b/src/interceptors/count-header.interceptor.ts index 7bb586e..0e5d5a4 100644 --- a/src/interceptors/count-header.interceptor.ts +++ b/src/interceptors/count-header.interceptor.ts @@ -11,7 +11,6 @@ export class CountHeaderInterceptor implements NestInterceptor { return next.handle().pipe( map((data) => { if (Array.isArray(data)) { - console.log('applyHeader', data.length); response.set('X-Total-Count', data.length.toString()); } return data; diff --git a/src/places/places.controller.ts b/src/places/places.controller.ts index 755702d..621bce5 100644 --- a/src/places/places.controller.ts +++ b/src/places/places.controller.ts @@ -63,7 +63,7 @@ export class PlacesController { async getPlacesWithBuildings(@Query() query: GetPlacesWithBuildingsDto, @AuthedUser() user: User) { if(query.match_nearest_building!==true) { - throw new HttpException("match_nearest_building must be true to get building shapes due to cost reasons", 400); + throw new HttpException("match_nearest_building must be true in the Demo API to get building shapes due to cost reasons", 400); //ToDo: refactor query to be optimised for this use case as is currently $2.25 per query instead of $0.02 }