import type { RequestEvent, RequestHandler } from './$types'
import {json} from '@sveltejs/kit'
import { getUser, updateUser } from '$lib/data/users'

//api/users/1
export const PUT: RequestHandler = async ({ request }: RequestEvent) => {
    const o  = await request.json()
    if(!updateUser(o))
        return json({message:"call updateUser fail "},{status:400})
    return json({message:"Update Success"})
}
export const GET: RequestHandler = async ({params}: RequestEvent) => {
    const id = Number(params.id)
    const u = await getUser(id)
    if(!u)
        return json({message:`User ${id} not found`},{status:404})
    return json(u)
}

