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,96 @@
|
||||
"use server";
|
||||
|
||||
import { redirect } from "next/navigation";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { logAdminAction } from "@/lib/audit-log";
|
||||
import { requireAdmin, str, num } from "./_shared";
|
||||
|
||||
export async function createHarvestAction(formData: FormData): Promise<void> {
|
||||
const admin = await requireAdmin();
|
||||
const year = num(formData, "year");
|
||||
const type = str(formData, "type");
|
||||
const slug = `${type.toLowerCase().replace(/[^a-z0-9]+/g, "-")}-${year}`;
|
||||
|
||||
const harvest = await prisma.harvest.create({
|
||||
data: {
|
||||
year,
|
||||
type,
|
||||
slug,
|
||||
harvestDate: new Date(str(formData, "harvestDate")),
|
||||
location: str(formData, "location") || "Altenmünster",
|
||||
description: str(formData, "description"),
|
||||
},
|
||||
});
|
||||
|
||||
await logAdminAction(admin, {
|
||||
action: "harvest.create",
|
||||
entityType: "Harvest",
|
||||
entityId: harvest.id,
|
||||
detail: `${type} ${year}`,
|
||||
});
|
||||
|
||||
revalidatePath("/admin/ernten");
|
||||
redirect("/admin/ernten");
|
||||
}
|
||||
|
||||
export async function updateHarvestAction(formData: FormData): Promise<void> {
|
||||
const admin = await requireAdmin();
|
||||
const id = str(formData, "id");
|
||||
|
||||
await prisma.harvest.update({
|
||||
where: { id },
|
||||
data: {
|
||||
year: num(formData, "year"),
|
||||
type: str(formData, "type"),
|
||||
harvestDate: new Date(str(formData, "harvestDate")),
|
||||
location: str(formData, "location") || "Altenmünster",
|
||||
description: str(formData, "description"),
|
||||
},
|
||||
});
|
||||
|
||||
await logAdminAction(admin, { action: "harvest.update", entityType: "Harvest", entityId: id });
|
||||
|
||||
revalidatePath("/admin/ernten");
|
||||
redirect("/admin/ernten");
|
||||
}
|
||||
|
||||
export async function createBatchAction(formData: FormData): Promise<void> {
|
||||
const admin = await requireAdmin();
|
||||
const code = str(formData, "code");
|
||||
const batch = await prisma.batch.create({
|
||||
data: {
|
||||
code,
|
||||
harvestId: str(formData, "harvestId"),
|
||||
fillDate: new Date(str(formData, "fillDate")),
|
||||
bestBeforeDate: new Date(str(formData, "bestBeforeDate")),
|
||||
glassCount: num(formData, "glassCount"),
|
||||
remainingGlasses: num(formData, "remainingGlasses"),
|
||||
},
|
||||
});
|
||||
|
||||
await logAdminAction(admin, { action: "batch.create", entityType: "Batch", entityId: batch.id, detail: code });
|
||||
|
||||
revalidatePath("/admin/chargen");
|
||||
redirect("/admin/chargen");
|
||||
}
|
||||
|
||||
export async function updateBatchAction(formData: FormData): Promise<void> {
|
||||
const admin = await requireAdmin();
|
||||
const id = str(formData, "id");
|
||||
|
||||
await prisma.batch.update({
|
||||
where: { id },
|
||||
data: {
|
||||
fillDate: new Date(str(formData, "fillDate")),
|
||||
bestBeforeDate: new Date(str(formData, "bestBeforeDate")),
|
||||
glassCount: num(formData, "glassCount"),
|
||||
remainingGlasses: num(formData, "remainingGlasses"),
|
||||
},
|
||||
});
|
||||
|
||||
await logAdminAction(admin, { action: "batch.update", entityType: "Batch", entityId: id });
|
||||
|
||||
revalidatePath("/admin/chargen");
|
||||
redirect("/admin/chargen");
|
||||
}
|
||||
Reference in new issue
Block a user