diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 79869be065068220ec5a1da241c04e416590fc95..bb71762235a1187989c66f732efe2aa222b128a2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -35,12 +35,17 @@ deploy_dev: - docker-compose pull service-ram - docker-compose up -d --force-recreate service-ram - docker system prune -a -f + environment: + name: dev + url: https://resin-dev.grandlyon.com test: stage: test image: node:14.15.4 before_script: - export GHOST_HOST_AND_PORT=http://localhost:2368 + - export GHOST_ADMIN_API_KEY=60142bc9e33940000156bccc:6217742e2671e322612e89cac9bab61fcd01822709fe5d8f5e6a5b3e54d5e6bb + - export SALT=$TEST_SALT script: - npm i - npm run test:cov diff --git a/src/structures/structures.controller.ts b/src/structures/structures.controller.ts index 4dc62b845fc0b1ed7932fc8141d660509bdb54b5..52582b6bb6a921c9f8fc4c4ecd39c40a5d0151d4 100644 --- a/src/structures/structures.controller.ts +++ b/src/structures/structures.controller.ts @@ -4,6 +4,7 @@ import { Delete, Get, HttpException, + HttpService, HttpStatus, Param, Post, @@ -29,11 +30,28 @@ import { StructuresService } from './services/structures.service'; @Controller('structures') export class StructuresController { constructor( + private readonly httpService: HttpService, private readonly structureService: StructuresService, private readonly userService: UsersService, private readonly tempUserService: TempUserService ) {} + /** + * Return points of given town exist. + * @param zipcode + * @returns Array of points + */ + @Get('coordinates/:zipcode') + @ApiParam({ name: 'zipcode', type: String, required: true }) + public async getCoordinates(@Param('zipcode') city: string): Promise<any> { + return await this.httpService + .get(encodeURI('https://download.data.grandlyon.com/geocoding/photon-bal/api?q=' + city)) + .toPromise() + .then(async (res) => res.data.features) + .then((data) => data.filter((cityPoint) => cityPoint.properties.city.toLowerCase().includes(city.toLowerCase()))) + .then((data) => data.map((filteredCityPoint) => filteredCityPoint.geometry.coordinates)); + } + @Post() public async create(@Body() createStructureDto: CreateStructureDto): Promise<Structure> { return this.structureService.create(createStructureDto.idUser, createStructureDto.structure);