Skip to content
Snippets Groups Projects
tclStopPoint.controller.ts 1.52 KiB
import { Body, Controller, Logger, Post, UseGuards } from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { Roles } from '../users/decorators/roles.decorator';
import { RolesGuard } from '../users/guards/roles.guard';
import { PgisCoord } from './schemas/pgisCoord.schema';
import { TclStopPoint } from './tclStopPoint.schema';
import { TclStopPointService } from './tclStopPoint.service';

@ApiTags('tcl')
@Controller('tcl')
export class TclStopPointController {
  private readonly logger = new Logger(TclStopPointController.name);
  constructor(private tclStopPointService: TclStopPointService) {}

  @ApiOperation({
    description: `Mettre à jour les points d'arrêt TCL à partir de Data Grand Lyon`,
  })
  @ApiResponse({
    status: 201,
    description: 'The stop points have been updated successfully.',
  })
  @Post('/update')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('admin')
  public updateStopPoints(): Promise<void> {
    this.logger.debug('updateStopPoints');
    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);
  }
}