import { prisma } from "@/lib/prisma"; import { asStringArray } from "@/lib/json-array"; import type { ProductWithRelations } from "@/lib/data"; export async function isProductWishlisted(productId: string, customerId: string): Promise { const item = await prisma.wishlistItem.findUnique({ where: { customerId_productId: { customerId, productId } }, select: { id: true }, }); return item !== null; } /** Gespeicherte Produkte einer Kundin/eines Kunden, neueste zuerst. */ export async function getWishlistProducts(customerId: string): Promise { const items = await prisma.wishlistItem.findMany({ where: { customerId }, orderBy: { createdAt: "desc" }, select: { product: { include: { harvest: true, batch: true, inventory: { select: { quantity: true } } }, }, }, }); return items.map((item) => ({ ...item.product, tasteTags: asStringArray(item.product.tasteTags), images: asStringArray(item.product.images), })); }