Skip to content
Snippets Groups Projects
tclStopPoint.controller.ts 1.38 KiB
Newer Older
  • Learn to ignore specific revisions
  • Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
    import { ApiOperation, ApiResponse } from '@nestjs/swagger';
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
    import { Roles } from '../users/decorators/roles.decorator';
    import { RolesGuard } from '../users/guards/roles.guard';
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    import { PgisCoord } from './interfaces/pgis.coord';
    import { TclStopPoint } from './tclStopPoint.schema';
    import { TclStopPointService } from './tclStopPoint.service';
    
    @Controller('tcl')
    export class TclStopPointController {
      constructor(private tclStopPointService: TclStopPointService) {}
    
      @ApiOperation({
        description: `Mettre à jour les points d'arrêt TCL à partir de Data Grand Lyon`,
      })
      @ApiResponse({
        status: 204,
        description: 'The stop points have been updated successfully.',
      })
      @Get('/update')
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
      @UseGuards(JwtAuthGuard, RolesGuard)
      @Roles('admin')
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
      public updateStopPoints(): Promise<void> {
        return this.tclStopPointService.updateStopPoints();
      }
    
      @ApiOperation({
        description: `Récupérer les arrêts les plus proches d'un point géographique`,
      })
      @ApiResponse({
        status: 200,
        description: 'The closest stop points have been fetched successfully.',
      })
      @Post('/closest')
      public getClosestStopPoints(@Body() pgisCoord: PgisCoord): Promise<TclStopPoint[]> {
        return this.tclStopPointService.getClosestStopPoints(pgisCoord);
      }
    }