Stop double accumulation server-side
This commit is contained in:
parent
e7c6b8fa5b
commit
8654fa9676
@ -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(),
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user