Built via two more parallel agent workflows (read schema -> return files), integrated + verified. Admin: /admin/emulator (emulator_settings + emulator_texts key/value editor), /admin/badges (give-badge via RCON), /admin/rare-values (CRUD), /admin/housekeeping (CRUD), /admin/email-templates (CRUD), /admin/photos (moderation). Public: /rares (+[category]), /leaderboard (credits/diamonds/duckets), /guilds (+[id] members), /redeem (voucher -> sendCurrency). Expanded: /u/[username] now shows badges + photos + guestbook (post form); /news/[slug] now shows reactions + comments (comment form). Reactions tallied in JS (Prisma groupBy typing avoided). Self-hosted Nunito via next/font/google wired to --font-nunito (the atom theme font, no runtime external fetch). Header + admin nav extended. Verified: tsc exit 0, vitest 48/48, next build exit 0.
69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
"use server";
|
|
|
|
import { revalidatePath } from "next/cache";
|
|
import { requireStaff } from "@/lib/admin/guard";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
export async function createEmailTemplate(formData: FormData): Promise<void> {
|
|
await requireStaff();
|
|
const name = String(formData.get("name") ?? "").trim().slice(0, 255);
|
|
const subject = String(formData.get("subject") ?? "").trim().slice(0, 255);
|
|
const body = String(formData.get("body") ?? "");
|
|
const variablesRaw = String(formData.get("variables") ?? "").trim();
|
|
const isActive = formData.get("isActive") != null;
|
|
if (!name || !subject || !body) return;
|
|
|
|
await prisma.emailTemplates.create({
|
|
data: {
|
|
name,
|
|
subject,
|
|
body,
|
|
variables: variablesRaw || null,
|
|
isActive,
|
|
},
|
|
});
|
|
revalidatePath("/admin/email-templates");
|
|
}
|
|
|
|
export async function updateEmailTemplate(formData: FormData): Promise<void> {
|
|
await requireStaff();
|
|
const raw = String(formData.get("id") ?? "");
|
|
if (!raw) return;
|
|
let id: bigint;
|
|
try {
|
|
id = BigInt(raw);
|
|
} catch {
|
|
return;
|
|
}
|
|
const subject = String(formData.get("subject") ?? "").trim().slice(0, 255);
|
|
const body = String(formData.get("body") ?? "");
|
|
const variablesRaw = String(formData.get("variables") ?? "").trim();
|
|
const isActive = formData.get("isActive") != null;
|
|
if (!subject || !body) return;
|
|
|
|
await prisma.emailTemplates.update({
|
|
where: { id },
|
|
data: {
|
|
subject,
|
|
body,
|
|
variables: variablesRaw || null,
|
|
isActive,
|
|
},
|
|
});
|
|
revalidatePath("/admin/email-templates");
|
|
}
|
|
|
|
export async function deleteEmailTemplate(formData: FormData): Promise<void> {
|
|
await requireStaff();
|
|
const raw = String(formData.get("id") ?? "");
|
|
if (!raw) return;
|
|
let id: bigint;
|
|
try {
|
|
id = BigInt(raw);
|
|
} catch {
|
|
return;
|
|
}
|
|
await prisma.emailTemplates.delete({ where: { id } });
|
|
revalidatePath("/admin/email-templates");
|
|
}
|