mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 22:27:32 +00:00
3eac508baf
RowIdPipe (src/nest/common/row-id.pipe.ts) parses a path param with toRowId. It answers a refused spelling with the route's own not-found answer, so '0x5', '5e0' and 'abc' get what an id that names no row gets. ParseRowIdPipe replaces Nest's ParseIntPipe with the same 400 and message: ParseIntPipe let '-1' and numbers past 2^53 through, and Postgres refuses the latter as out of range. Journey, journey recordings, day import, book design, map, public photo, collections, doc-sync, vacay, atlas and the plugin user-data export declare their ids through it. The upload routes parse in the handler with withRowId, so a refused id takes the existing cleanup path, or carry SpoolCleanupInterceptor (collections).
64 lines
2.2 KiB
TypeScript
64 lines
2.2 KiB
TypeScript
import { AdminGuard } from '../auth-core/admin.guard';
|
|
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
|
|
import { ParseRowIdPipe } from '../common/row-id.pipe';
|
|
import { SchoolHolidaysService } from './school-holidays.service';
|
|
import { Body, Controller, Delete, Get, Param, Post, Put, Query, UseGuards, BadRequestException } from '@nestjs/common';
|
|
import { schoolHolidayCountryRequestSchema, schoolHolidayRegionRequestSchema } from '@trek/shared';
|
|
|
|
import { createZodDto } from 'nestjs-zod';
|
|
|
|
export class SchoolHolidayCountryDto extends createZodDto(schoolHolidayCountryRequestSchema) {}
|
|
export class SchoolHolidayRegionDto extends createZodDto(schoolHolidayRegionRequestSchema) {}
|
|
|
|
@Controller('api/school-holiday-catalog')
|
|
@UseGuards(JwtAuthGuard)
|
|
export class SchoolHolidaysController {
|
|
constructor(private readonly holidays: SchoolHolidaysService) {}
|
|
|
|
@Get()
|
|
async catalog() {
|
|
return this.holidays.catalog();
|
|
}
|
|
|
|
@Get('regions/:id')
|
|
async region(@Param('id', ParseRowIdPipe) id: number) {
|
|
return this.holidays.region(id);
|
|
}
|
|
|
|
@Get('regions/:id/holidays/:year')
|
|
async forYear(@Param('id', ParseRowIdPipe) id: number, @Param('year') year: string) {
|
|
if (!/^\d{4}$/.test(year)) throw new BadRequestException('Invalid year');
|
|
return this.holidays.holidays(id, year);
|
|
}
|
|
|
|
@Post('countries')
|
|
@UseGuards(AdminGuard)
|
|
async createCountry(@Body() body: SchoolHolidayCountryDto) {
|
|
return this.holidays.createCountry(body);
|
|
}
|
|
|
|
@Delete('countries/:code')
|
|
@UseGuards(AdminGuard)
|
|
async deleteCountry(@Param('code') code: string) {
|
|
return this.holidays.deleteCountry(code);
|
|
}
|
|
|
|
@Post('countries/:code/regions')
|
|
@UseGuards(AdminGuard)
|
|
async createRegion(@Param('code') code: string, @Body() body: SchoolHolidayRegionDto) {
|
|
return this.holidays.createRegion(code, body);
|
|
}
|
|
|
|
@Put('regions/:id')
|
|
@UseGuards(AdminGuard)
|
|
async updateRegion(@Param('id', ParseRowIdPipe) id: number, @Body() body: SchoolHolidayRegionDto) {
|
|
return this.holidays.updateRegion(id, body);
|
|
}
|
|
|
|
@Delete('regions/:id')
|
|
@UseGuards(AdminGuard)
|
|
async deleteRegion(@Param('id', ParseRowIdPipe) id: number, @Query('revision', ParseRowIdPipe) revision: number) {
|
|
return this.holidays.deleteRegion(id, revision);
|
|
}
|
|
}
|