29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { apiJson, withApiHandler } from "@/lib/api-handler";
|
|
import { deleteBangForScope, updateBangForScope } from "@/modules/bangs/server/actions";
|
|
import { updateBangInput } from "@/modules/bangs/server/schemas";
|
|
import { z } from "zod";
|
|
|
|
export async function PATCH(request: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
const { id } = await params;
|
|
return withApiHandler(request, async (scope, req) => {
|
|
const body: unknown = await req.json();
|
|
const parsed = updateBangInput.parse(body);
|
|
const bang = await updateBangForScope(scope, { id, ...parsed });
|
|
return apiJson({
|
|
id: bang.id,
|
|
occurredOn: bang.occurredOn,
|
|
recordedBy: bang.recordedBy,
|
|
createdAt: bang.createdAt.toISOString(),
|
|
});
|
|
});
|
|
}
|
|
|
|
export async function DELETE(request: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
const { id } = await params;
|
|
return withApiHandler(request, async (scope) => {
|
|
z.string().uuid().parse(id);
|
|
await deleteBangForScope(scope, { id });
|
|
return apiJson({ ok: true });
|
|
});
|
|
}
|