import { Controller , Get , Post , Body , Patch , Param , Delete , ParseIntPipe , Request , } from '@nestjs/common' ; import { TodoService } from './todo.service' ; import { CreateTodoDto } from './dto/create-todo.dto' ; import { UpdateTodoDto } from './dto/update-todo.dto' ; import { Todo } from './entities/todo.entity' ; import { ApiBearerAuth , ApiTags } from '@nestjs/swagger' ; @ ApiTags ( '待办事项' ) @ ApiBearerAuth ( ) @ Controller ( 'todo' ) export class TodoController { constructor ( private readonly todoService ) { } @ Post ( ) async create ( @ Request ( ) request , @ Body ( ) createTodoDto ) { return this . todoService . create ( request . user . id , createTodoDto ) ; } @ Get ( ) async findAll ( @ Request ( ) request ) { const { id , is_admin } = request . user ; if ( is_admin === 1 ) { return this . todoService . findAll ( ) ; } else { return this . todoService . findAllByUserId ( id ) ; } } @ Get ( ':id' ) async findOne ( @ Param ( 'id' , ParseIntPipe ) id ) { return this . todoService . findOne ( id ) ; } @ Patch ( ':id' ) async update ( @ Param ( 'id' , ParseIntPipe ) id , @ Body ( ) updateTodoDto ) { await this . todoService . update ( id , updateTodoDto ) ; return updateTodoDto ; } @ Delete ( ':id' ) async remove ( @ Param ( 'id' , ParseIntPipe ) id ) { await this . todoService . remove ( id ) ; return { id } ; } }