feat: voucher crud and list
This commit is contained in:
1 parent
73295653ee
commit
660d6cff51
7 files changed
+358
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getDb } from "@/lib/db";
|
||||
|
||||
export async function GET(_req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params;
|
||||
const db = getDb();
|
||||
const v = await db.voucher.findUnique({ where: { id: Number(id) } });
|
||||
if (!v) return NextResponse.json({ error: "not found" }, { status: 404 });
|
||||
return NextResponse.json(v);
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params;
|
||||
const body = await req.json().catch(() => ({}));
|
||||
if (body.action !== "redeem") return NextResponse.json({ error: "unknown action" }, { status: 400 });
|
||||
const db = getDb();
|
||||
const v = await db.voucher.findUnique({ where: { id: Number(id) } });
|
||||
if (!v) return NextResponse.json({ error: "not found" }, { status: 404 });
|
||||
const updated = await db.voucher.update({ where: { id: v.id }, data: { status: "eingeloest", restCents: 0 } });
|
||||
return NextResponse.json(updated);
|
||||
}
|
||||
Reference in new issue
Block a user