SwapIt / app / api / product / new / route.js
route.js
Raw
import { op } from "@utils/user.mjs"

export const POST = async (req) => {
    const {User_Id, NOP, type, image, desc, price} = await req.json()
    try {
        await op.CreateProduct(User_Id,NOP,type,image,desc,price,Date().toString);
        const newProduct = {
            User_Id: User_Id,
            NOP: NOP,
            type:type,
            image:image,
            desc:desc,
            price:price
        }
        return new Response(JSON.stringify(newProduct),{status: 201});
    } catch (error) {
        return new Response("Failed to create a Post!" , {status: 500})
    }
}