
import { NextResponse } from 'next/server'
import { createUserMethod,deleteUser,getAllUser } from '@/methods/userMethods'



export async function POST(request: Request) {
  const body = await request.json()
  const { name, prenom,email } = body

  if (!name || !email) {
    return NextResponse.json({ error: 'Champs manquants' }, { status: 400 })
  }

  const user = await createUserMethod(name,prenom, email)
  return NextResponse.json(user, { status: 201 })
}



export async function GET() {
  const user = await getAllUser()
  return NextResponse.json(user, { status: 200 })
}



export async function DELETE(request : Request){
  const param = await request.json()
  const { id } = param
  
  const user = deleteUser(parseInt(id))

  return NextResponse.json(user,{status : 200})
}

