import { Body, Controller, Delete, Get, Param, Post, Put, Query } from '@nestjs/common' import { Todo } from '@prisma/client' import { TodoDTO } from './dtos/todo.dto' import { TodoService } from './todo.service' @Controller('todo') export class TodoController { constructor(private readonly todoService: TodoService) {} @Get() async fetchAll(@Query() query): Promise { const sql = { take: isNaN(query.per_page) ? 20 : Number(query.per_page), skip: isNaN(query.page) ? 0 : Number(query.page) * query.per_page, //where: { is_done: true }, orderBy: { id: 'desc' } } //console.log(query) //console.log(sql) return this.todoService.fetchAll(sql) } @Get(':id') async fetchOne(@Param('id') id: number): Promise { return this.todoService.fetchOne(id) } @Delete(':id') async delete(@Param('id') id: number): Promise { return this.todoService.remove(id) } @Post() async add(@Body() data: Todo): Promise { return this.todoService.add(data) } @Put(':id') async update(@Param('id') id: number, @Body() data: TodoDTO): Promise { return this.todoService.update(id, data) } }