Files
twotalesanimation 2f91c71307
Deploy / deploy (push) Failing after 44s
Shoot sketches templates
2026-07-12 12:27:21 +02:00

50 lines
1.6 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { auth } from "@/auth";
import { db } from "@/lib/db";
function canManage(role: string) {
return ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(role);
}
// DELETE /api/sketch-templates/[id]
export async function DELETE(
_req: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
const session = await auth();
if (!session?.user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
if (!canManage(session.user.role))
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
const { id } = await params;
const template = await db.sketchTemplate.findUnique({ where: { id } });
if (!template) return NextResponse.json({ error: "Not found" }, { status: 404 });
await db.sketchTemplate.delete({ where: { id } });
return NextResponse.json({ ok: true });
}
// PATCH /api/sketch-templates/[id] — rename
export async function PATCH(
req: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
const session = await auth();
if (!session?.user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
if (!canManage(session.user.role))
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
const { id } = await params;
const { name } = await req.json();
if (!name?.trim()) return NextResponse.json({ error: "Name required" }, { status: 400 });
const template = await db.sketchTemplate.update({
where: { id },
data: { name: name.trim() },
});
return NextResponse.json({
template: { ...template, fileSize: template.fileSize != null ? Number(template.fileSize) : null },
});
}