feat: Wabenhain Honig-Shop Anwendung
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.
This commit is contained in:
1 parent
5c76fcc266
commit
c7927f2883
240 files changed
+26096
-137
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import type { BulkDiscountTierLike } from "@/lib/bulk-discount-calc";
|
||||
|
||||
// Startwert, falls noch kein Mengenrabatt-Code existiert — danach frei im
|
||||
// Admin-Bereich (Gutscheine) editierbar, siehe ensureBulkDiscountCode().
|
||||
const BULK_DISCOUNT_CODE = "MENGE10";
|
||||
const BULK_DISCOUNT_PERCENT = 10;
|
||||
const BULK_DISCOUNT_MIN_QUANTITY = 3;
|
||||
|
||||
/**
|
||||
* Idempotent — legt einen Mengenrabatt-Code als Startwert an, falls noch
|
||||
* keiner existiert. Danach ist er im Admin-Bereich (Gutscheine) frei in Hoehe
|
||||
* (value) und Menge (minQuantity) editierbar — update:{} ueberschreibt
|
||||
* bestehende Admin-Anpassungen nie.
|
||||
*/
|
||||
export async function ensureBulkDiscountCode(): Promise<void> {
|
||||
await prisma.discountCode.upsert({
|
||||
where: { code: BULK_DISCOUNT_CODE },
|
||||
create: {
|
||||
code: BULK_DISCOUNT_CODE,
|
||||
type: "PERCENT",
|
||||
value: BULK_DISCOUNT_PERCENT,
|
||||
minOrderCents: 0,
|
||||
minQuantity: BULK_DISCOUNT_MIN_QUANTITY,
|
||||
},
|
||||
update: {},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Alle aktuell gueltigen Mengenrabatt-Codes (minQuantity gesetzt) als leichte
|
||||
* Vorschau-Daten fuer Warenkorb/Checkout — die eigentliche Anwendung im
|
||||
* Checkout laeuft weiterhin ueber die volle DiscountCode-Zeile (fuer
|
||||
* usedCount/Order-Verknuepfung), s. api/checkout/route.ts.
|
||||
*/
|
||||
export async function getBulkDiscountTiers(): Promise<BulkDiscountTierLike[]> {
|
||||
const now = new Date();
|
||||
const codes = await prisma.discountCode.findMany({
|
||||
where: { minQuantity: { not: null }, type: "PERCENT", isActive: true },
|
||||
});
|
||||
return codes
|
||||
.filter((code) => (!code.validFrom || code.validFrom <= now) && (!code.validUntil || code.validUntil >= now))
|
||||
.map((code) => ({ code: code.code, minQuantity: code.minQuantity as number, percent: code.value }));
|
||||
}
|
||||
Reference in new issue
Block a user