feat: api v1 garden bangs routes and openapi
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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 });
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user