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) {