Add post handler for event-by-id
This commit is contained in:
parent
708a8219a6
commit
6c378080cc
@ -60,3 +60,25 @@ export async function onRequestPatch(context: RequestContext) {
|
|||||||
status: 204,
|
status: 204,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function onRequestPost(context: RequestContext) {
|
||||||
|
const eventId = context.params.id as string;
|
||||||
|
const eventData = await context.env.D1.prepare(
|
||||||
|
"SELECT approved, performed FROM events WHERE id = ?;",
|
||||||
|
)
|
||||||
|
.bind(eventId)
|
||||||
|
.first();
|
||||||
|
|
||||||
|
if (!eventData) return jsonError("No event exists with that ID", 404);
|
||||||
|
|
||||||
|
if (!eventData.approved)
|
||||||
|
return jsonError("Cannot perform unapproved event", 403);
|
||||||
|
|
||||||
|
await context.env.D1.prepare("UPDATE events SET performed = 1 WHERE id = ?;")
|
||||||
|
.bind(eventId)
|
||||||
|
.run();
|
||||||
|
|
||||||
|
return new Response(null, {
|
||||||
|
status: 204,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user