Skip to content

Commit

Permalink
add allow listed Demo cities
Browse files Browse the repository at this point in the history
  • Loading branch information
AdenForshaw committed Nov 12, 2024
1 parent d347333 commit 8148d70
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
17 changes: 0 additions & 17 deletions extra-datasets/cities/demo-cities.json

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "overture-maps-api",
"version": "0.1.4",
"version": "0.1.5",
"description": "",
"author": "",
"private": true,
Expand Down
25 changes: 24 additions & 1 deletion src/decorators/validate-lat-lng-user.decorator.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/interceptors/count-header.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/places/places.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 8148d70

Please sign in to comment.