Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Stop double accumulation server-side
  • Loading branch information
regalijan committed Feb 3, 2025
1 parent e7c6b8f commit 8654fa9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions functions/api/events-team/events/[id]/complete.ts
Expand Up @@ -5,6 +5,18 @@ export async function onRequestPost(context: RequestContext) {
const { event } = context.data;

try {
const completionTimeRow = await D1.prepare(
"SELECT performed_at FROM events WHERE id = ?;",
)
.bind(event.id)
.first();

if (typeof completionTimeRow?.performed_at !== "number")
return jsonError(
"The event is already marked as complete or forgotten",
400,
);

await D1.batch([
D1.prepare("UPDATE events SET performed_at = ? WHERE id = ?;").bind(
Date.now(),
Expand Down
9 changes: 9 additions & 0 deletions functions/api/events-team/events/[id]/forgotten.ts
Expand Up @@ -5,6 +5,15 @@ export async function onRequestPost(context: RequestContext) {
const { event } = context.data;

try {
const row = await D1.prepare(
"SELECT performed_at FROM events WHERE id = ?;",
)
.bind(event.id)
.first();

if (typeof row?.performed_at !== "number")
return jsonError("Event already marked as completed or forgotten", 400);

await D1.batch([
D1.prepare("UPDATE events SET performed_at = 0 WHERE id = ?;").bind(
event.id,
Expand Down

0 comments on commit 8654fa9

Please sign in to comment.