Files
car-crushers-portal/functions/api/events-team/events/[id]/complete.ts
Regalijan a9863f5680
All checks were successful
Test, Build, Deploy / Test, Build, and Deploy (push) Successful in 55s
Test, Build, Deploy / Create Sentry Release (push) Successful in 9s
Remove unneeded unix time param
2026-04-16 04:08:20 -04:00

41 lines
968 B
TypeScript

import { jsonError } from "../../../../common.js";
export async function onRequestPost(context: RequestContext) {
const { D1 } = context.env;
const { event } = context.data;
try {
const completionTimeRow = await context.data.prisma.event.findUnique({
select: {
performed_at: true,
},
where: {
id: event.id,
},
});
if (completionTimeRow?.performed_at instanceof Date)
return jsonError(
"The event is already marked as complete or forgotten",
400,
);
await D1.batch([
D1.prepare(
"UPDATE events SET performed_at = CURRENT_TIMESTAMP 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,
});
}