ÜRÜN İLANINI DÜZENLE

```javascript
export async function editProduct(id, 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!" };
  }

  try {
    const session = await auth();
    if (!session) {
      return { message: "User not authenticated!" };
    }

    const foundProduct = await prisma.product.findUnique({
      where: {
        id,
      },
    });
    if (!foundProduct) {
      return { message: "Product not found!" };
    }

    if (foundProduct.sellerId !== session.user.id) {
      return { message: "You are not the seller of this product!" };
    }

    const product = await prisma.product.update({
      where: {
        id,
      },
      data: {
        name,
        description,
        price: parseFloat(price),
      },
    });
    revalidatePath("/myproducts")
    return { message: "Product updated!", productId: product.id };
  } catch (error) {
    console.error("Error updating product:", error);
    return { message: "Something went wrong!" };
  }
}
```

Last updated