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,37 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { sendMail } from "@/lib/mail";
|
||||
import { backInStockEmail } from "@/lib/email-templates";
|
||||
import { isLocale, defaultLocale } from "@/i18n/config";
|
||||
|
||||
/**
|
||||
* Versendet die Wiederverfuegbarkeits-E-Mail an alle wartenden Anmeldungen
|
||||
* fuer ein Produkt und markiert sie als benachrichtigt. Wird vom Admin-Bereich
|
||||
* aufgerufen, wenn der Lagerbestand eines zuvor ausverkauften Produkts wieder
|
||||
* auf > 0 gesetzt wird (siehe updateProductAction in admin/actions.ts).
|
||||
*/
|
||||
export async function notifyStockAvailable(productId: string): Promise<void> {
|
||||
const pending = await prisma.stockNotification.findMany({
|
||||
where: { productId, notifiedAt: null },
|
||||
});
|
||||
if (pending.length === 0) return;
|
||||
|
||||
const product = await prisma.product.findUnique({
|
||||
where: { id: productId },
|
||||
select: { name: true, slug: true },
|
||||
});
|
||||
if (!product) return;
|
||||
|
||||
// E-Mail-Fehler duerfen den Bestands-Update selbst nicht scheitern lassen —
|
||||
// sendMail wirft nie (siehe lib/mail.ts). Jede Anmeldung wird in der bei
|
||||
// der Anmeldung gespeicherten Sprache benachrichtigt (koennen unterschiedliche sein).
|
||||
for (const notification of pending) {
|
||||
const locale = isLocale(notification.locale) ? notification.locale : defaultLocale;
|
||||
const { subject, html, text } = await backInStockEmail({ locale, ...product });
|
||||
await sendMail({ to: notification.email, subject, html, text });
|
||||
}
|
||||
|
||||
await prisma.stockNotification.updateMany({
|
||||
where: { id: { in: pending.map((n) => n.id) } },
|
||||
data: { notifiedAt: new Date() },
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user