Shows/controller: validate search parameters

This commit is contained in:
Toast 2025-02-01 20:33:18 +01:00
parent a2b747a823
commit 02c2f37379

View file

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