Vollstaendige Next.js/Prisma-E-Commerce-Anwendung fuer eine Imkerei: Shop, Warenkorb, Stripe-Checkout, Kundenkonto mit 2FA, Admin-Bereich (Produkte, Ernten, Chargen, Bestellungen, Gutscheine, admin-editierbare Website-Inhalte), i18n (DE/EN), Rate-Limiting/CSP/Audit-Log-Haertung, PostgreSQL- und MySQL-Unterstuetzung ueber austauschbare Prisma- Treiber-Adapter, Unit-/Komponenten-/E2E-Tests.
30 lines
1018 B
TypeScript
30 lines
1018 B
TypeScript
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<boolean> {
|
|
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<ProductWithRelations[]> {
|
|
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),
|
|
}));
|
|
}
|