Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
car-crushers-portal/functions/api/events-team/events/[id]/certify.ts
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
28 lines (23 sloc)
721 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { jsonError } from "../../../../common.js"; | |
export async function onRequestPost(context: RequestContext) { | |
const { event } = context.data; | |
if (event.reached_minimum_player_count) | |
return jsonError("This event is already certified", 400); | |
const { D1 } = context.env; | |
try { | |
await D1.batch([ | |
D1.prepare( | |
"UPDATE events SET reached_minimum_player_count = 1 WHERE id = ?", | |
).bind(event.id), | |
D1.prepare( | |
"UPDATE et_members SET points = points + 10 WHERE id = ?;", | |
).bind(event.created_by), | |
]); | |
} catch (e) { | |
console.log(e); | |
return jsonError("Failed to complete batch transaction", 500); | |
} | |
return new Response(null, { | |
status: 204, | |
}); | |
} |