Shows/controller: validate search parameters
This commit is contained in:
parent
a2b747a823
commit
02c2f37379
1 changed files with 11 additions and 3 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue