ÜRÜN İLANI OLUŞTUR
```javascript
export async function createProduct(imageUrl, prev, formData) {
const name = formData.get("name");
const description = formData.get("description");
const price = formData.get("price");
if (!name || !description || !price) {
return { message: "All fields are required!" };
}
if (!imageUrl) {
return { message: "Please upload an image!" };
}
try {
const session = await auth();
if (!session) {
return { message: "User not authenticated!" };
}
const product = await prisma.product.create({
data: {
name,
description,
price: parseFloat(price),
image : imageUrl,
sellerId: session.user.id,
},
});
revalidatePath("/myproducts")
return { message: "Product created!", productId: product.id };
} catch (error) {
console.error("Error creating product:", error);
return { message: "Something went wrong!" };
}
}
```
Last updated