Initial commit: spreewaldzeit + Dockerfile for Coolify (Next.js + Prisma/SQLite)
This commit is contained in:
14
app/api/admin/blocks/[id]/route.ts
Normal file
14
app/api/admin/blocks/[id]/route.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
|
||||
export async function DELETE(
|
||||
_req: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
try {
|
||||
await prisma.block.delete({ where: { id: params.id } });
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch {
|
||||
return NextResponse.json({ error: "Nicht gefunden." }, { status: 404 });
|
||||
}
|
||||
}
|
||||
34
app/api/admin/blocks/route.ts
Normal file
34
app/api/admin/blocks/route.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { blockSchema } from "@/lib/validations";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const body = await request.json().catch(() => null);
|
||||
const parsed = blockSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: "Ungültige Eingabe.", issues: parsed.error.flatten().fieldErrors },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const { apartmentId, startDate, endDate, note, reason } = parsed.data;
|
||||
|
||||
const apt = await prisma.apartment.findUnique({ where: { id: apartmentId } });
|
||||
if (!apt) {
|
||||
return NextResponse.json({ error: "Wohnung nicht gefunden." }, { status: 404 });
|
||||
}
|
||||
|
||||
const block = await prisma.block.create({
|
||||
data: {
|
||||
apartmentId,
|
||||
startDate: new Date(startDate),
|
||||
endDate: new Date(endDate),
|
||||
note: note || null,
|
||||
reason,
|
||||
source: "manual",
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({ ok: true, block }, { status: 201 });
|
||||
}
|
||||
Reference in New Issue
Block a user