11import { deleteTask , getTaskById , updateTask } from "@/app/lib/tasks_controller" ;
2+ import { TaskInput } from "@/models/models" ;
23import { NextResponse } from "next/server" ;
34
45export const GET = async ( req : Request ) => {
@@ -18,17 +19,29 @@ export const GET = async (req: Request) => {
1819 }
1920} ;
2021
21- export const PUT = async ( req : Request ) => {
22+ export const PATCH = async ( req : Request ) => {
2223 try {
23- const { title, description, author_id } = await req . json ( ) ;
24+ const { title, description, author_id, status } = await req . json ( ) ;
2425 const id = req . url . split ( "tasks/" ) [ 1 ] ;
25- updateTask ( id , { title, description, author_id} ) ;
26+
27+ // Atualiza apenas os campos que foram passados na requisição
28+ const updatedData : Partial < TaskInput > = { } ;
29+
30+ if ( title ) updatedData . title = title ;
31+ if ( description ) updatedData . description = description ;
32+ if ( author_id ) updatedData . author_id = author_id ;
33+ if ( status ) updatedData . status = status ; // Se o status for passado, ele também será atualizado.
34+
35+ // Chama a função para atualizar a task no banco de dados
36+ await updateTask ( id , updatedData ) ;
37+
2638 return NextResponse . json ( { message : "OK" } , { status : 200 } ) ;
2739 } catch ( err ) {
28- return NextResponse . json ( { message : 'Error' } , { status : 500 } )
40+ return NextResponse . json ( { message : 'Error' , error : err . message } , { status : 500 } ) ;
2941 }
3042} ;
3143
44+
3245export const DELETE = async ( req : Request ) => {
3346 try {
3447 const id = req . url . split ( "tasks/" ) [ 1 ] ;
0 commit comments