Improve existing event checks

This commit is contained in:
Regalijan 2024-02-22 13:40:54 -05:00
parent be62702e77
commit 41d5935fb5
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -23,7 +23,7 @@ export async function onRequestPost(context: RequestContext) {
if ( if (
await context.env.D1.prepare( await context.env.D1.prepare(
"SELECT * FROM events WHERE approved = false AND day = ? AND month = ? AND type = ? AND year = ?;", "SELECT * FROM events WHERE (approved = true OR approved IS NULL) AND day = ? AND month = ? AND type = ? AND year = ?;",
) )
.bind(day, currentMonth, type, currentYear) .bind(day, currentMonth, type, currentYear)
.first() .first()
@ -45,7 +45,7 @@ export async function onRequestPost(context: RequestContext) {
const weekRange = Math.floor(day / 7); const weekRange = Math.floor(day / 7);
const existingEventInRange = await context.env.D1.prepare( const existingEventInRange = await context.env.D1.prepare(
"SELECT id FROM events WHERE day > ? AND day <= ? AND month = ? AND type = 'rotw' AND year = ?;", "SELECT id FROM events WHERE (approved = true OR approved IS NULL) AND day > ? AND day <= ? AND month = ? AND type = 'rotw' AND year = ?;",
) )
.bind( .bind(
weekRanges[weekRange] - 7, weekRanges[weekRange] - 7,