More events team nonsense
All checks were successful
Test, Build, Deploy / Test, Build, and Deploy (push) Successful in 55s
Test, Build, Deploy / Create Sentry Release (push) Successful in 6s

This commit is contained in:
2026-04-11 03:30:46 -04:00
parent 465bb30966
commit cfc57c838e
17 changed files with 355 additions and 259 deletions

View File

@@ -22,11 +22,18 @@ export async function onRequestPost(context: RequestContext) {
return jsonError("Invalid body", 400);
if (
await context.env.D1.prepare(
"SELECT id FROM events WHERE (approved = 1 OR pending = 1) AND day = ? AND month = ? AND type = ? AND year = ?;",
)
.bind(day, currentMonth, type, currentYear)
.first()
await context.data.prisma.event.findFirst({
select: {
id: true,
},
where: {
OR: [{ approved: true }, { pending: true }],
day,
month: currentMonth,
type,
year: currentYear,
},
})
)
return jsonError(
"Event with that type already exists for the specified date",
@@ -44,16 +51,21 @@ export async function onRequestPost(context: RequestContext) {
const weekRange = Math.floor(day / 7);
const existingEventInRange = await context.env.D1.prepare(
"SELECT id FROM events WHERE (approved = 1 OR pending = 1) AND day BETWEEN ? AND ? AND month = ? AND type = 'rotw' AND year = ?;",
)
.bind(
weekRanges[weekRange] - 7,
weekRanges[weekRange],
currentMonth,
currentYear,
)
.first();
const existingEventInRange = await context.data.prisma.event.findFirst({
select: {
id: true,
},
where: {
OR: [{ approved: true }, { pending: true }],
day: {
gte: weekRanges[weekRange] - 7,
lte: weekRanges[weekRange],
},
month: currentMonth,
type: "rotw",
year: currentYear,
},
});
if (existingEventInRange)
return jsonError("There is already an rotw for that week", 400);
@@ -61,23 +73,20 @@ export async function onRequestPost(context: RequestContext) {
const id = `${now.getTime()}${crypto.randomUUID().replaceAll("-", "")}`;
await context.env.D1.prepare(
"INSERT INTO events (answer, approved, created_at, created_by, day, details, id, month, pending, type, year) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
)
.bind(
context.data.body.answer || null,
Number(type === "gamenight"),
now.getTime(),
context.data.current_user.id,
await context.data.prisma.event.create({
data: {
answer: context.data.body.answer || null,
approved: type === "gamenight",
created_by: context.data.current_user.id,
day,
details,
id,
currentMonth,
Number(type !== "gamenight"),
month: currentMonth,
pending: type !== "gamenight",
type,
currentYear,
)
.run();
year: currentYear,
},
});
await fetch(context.env.EVENTS_WEBHOOK, {
body: JSON.stringify({