From 02c2f373795b69db919f15871920e7b0e8094ae5 Mon Sep 17 00:00:00 2001 From: Toast Date: Sat, 1 Feb 2025 20:33:18 +0100 Subject: [PATCH] Shows/controller: validate search parameters --- src/shows/shows.controller.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/shows/shows.controller.ts b/src/shows/shows.controller.ts index 8215fa6..86e4ca1 100644 --- a/src/shows/shows.controller.ts +++ b/src/shows/shows.controller.ts @@ -14,6 +14,13 @@ import { import { ShowsService } from './shows.service'; import { ShowDto } from './dto/show.dto'; import { PaginationDto } from 'src/pagination.dto'; +import { IsNotEmpty, IsString } from 'class-validator'; + +export class SearchDto { + @IsString() + @IsNotEmpty() + query: string; +} @Controller('shows') export class ShowsController { @@ -78,15 +85,16 @@ export class ShowsController { } @Get('search') - async search(@Query('query') name: string) { + async search(@Query() search: SearchDto) { try { - const shows = await this.showsService.search(name); + const { query } = search; + const shows = await this.showsService.search(query); if (shows.length > 0) { return { status: 'Ok', show: shows, test: shows.length }; } else { throw new NotFoundException({ status: 'Error', - message: `Can't find show matching ${name}`, + message: `Can't find show matching ${query}`, }); } } catch (error) {