카테고리 순서 변경 api

This commit is contained in:
mota
2025-10-30 20:18:59 +09:00
parent 16b01a2c51
commit 293e4a20b9
4 changed files with 26 additions and 6 deletions

View File

@@ -24,7 +24,11 @@ const updateSchema = z.object({
export async function PATCH(req: Request, context: { params: Promise<{ id: string }> }) {
const { id } = await context.params;
const userId = getUserIdFromRequest(req);
await requirePermission({ userId, resource: "POST", action: "UPDATE" });
try {
await requirePermission({ userId, resource: "POST", action: "UPDATE" });
} catch (e) {
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
}
const body = await req.json();
const parsed = updateSchema.safeParse(body);
if (!parsed.success) return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 });
@@ -35,7 +39,11 @@ export async function PATCH(req: Request, context: { params: Promise<{ id: strin
export async function DELETE(req: Request, context: { params: Promise<{ id: string }> }) {
const { id } = await context.params;
const userId = getUserIdFromRequest(req);
await requirePermission({ userId, resource: "POST", action: "DELETE" });
try {
await requirePermission({ userId, resource: "POST", action: "DELETE" });
} catch (e) {
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
}
const post = await prisma.post.update({ where: { id }, data: { status: "deleted" } });
return NextResponse.json({ post });
}