59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
Patch,
|
|
Delete,
|
|
Body,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { videos, Prisma, video_situation } from 'generated/prisma';
|
|
|
|
import { VideosService } from './videos.service';
|
|
import { VideoResponseDto } from './dto/video-response.dto';
|
|
import { PaginatedQueryDto, PaginatedResponse } from './dto/paginated.dto';
|
|
import { EBooleanPipe } from './videos.pipe';
|
|
|
|
@Controller('videos')
|
|
export class VideosController {
|
|
constructor(private readonly videosService: VideosService) {}
|
|
|
|
@Get()
|
|
async list(
|
|
@Query() query: PaginatedQueryDto,
|
|
@Query('situation') situation?: video_situation,
|
|
@Query('pageable', new EBooleanPipe(true)) pageable: boolean = true,
|
|
): Promise<PaginatedResponse<VideoResponseDto> | VideoResponseDto[]> {
|
|
const situacao = situation?.toLocaleUpperCase() as video_situation;
|
|
|
|
if (pageable || query.page || query.perPage) {
|
|
return this.videosService.listPaginated(
|
|
Number(query.page ?? 1),
|
|
Number(query.perPage ?? 10),
|
|
query.direction as 'asc' | 'desc',
|
|
situacao,
|
|
);
|
|
}
|
|
|
|
return this.videosService.list(situacao);
|
|
}
|
|
|
|
@Get(':id')
|
|
async get(@Param('id') id: string): Promise<videos | null> {
|
|
return this.videosService.get(Number(id));
|
|
}
|
|
|
|
@Patch(':id')
|
|
async update(
|
|
@Param('id') id: string,
|
|
@Body() body: Prisma.videosUpdateInput,
|
|
): Promise<videos> {
|
|
return this.videosService.update(Number(id), body);
|
|
}
|
|
|
|
@Delete(':id')
|
|
async delete(@Param('id') id: string): Promise<videos> {
|
|
return this.videosService.delete(Number(id));
|
|
}
|
|
}
|