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

@@ -31,6 +31,7 @@ import {
import { useLoaderData } from "@remix-run/react"; import { useLoaderData } from "@remix-run/react";
import { useState } from "react"; import { useState } from "react";
import utc from "dayjs/plugin/utc.js"; import utc from "dayjs/plugin/utc.js";
import { EtMember } from "../../generated/prisma/client.js";
export const links: LinksFunction = () => { export const links: LinksFunction = () => {
return [ return [
@@ -56,18 +57,31 @@ export async function loader({ context }: { context: RequestContext }) {
}); });
const now = new Date(); const now = new Date();
const eventsData = await context.env.D1.prepare( const eventsData = await context.data.prisma.event.findMany({
"SELECT answer, approved, created_by, day, details, id, month, pending, performed_at, reached_minimum_player_count, type, year FROM events WHERE month = ? AND year = ? ORDER BY day;", orderBy: {
) day: "asc",
.bind(now.getUTCMonth() + 1, now.getUTCFullYear()) },
.all(); select: {
answer: true,
approved: true,
created_by: true,
day: true,
details: true,
id: true,
month: true,
pending: true,
performed_at: true,
reached_minimum_player_count: true,
type: true,
year: true,
},
where: {
month: now.getUTCMonth() + 1,
year: now.getUTCFullYear(),
},
});
if (eventsData.error) const calendarData = eventsData.map((e) => {
throw new Response(null, {
status: 500,
});
const calendarData = eventsData.results.map((e) => {
return { return {
id: e.id, id: e.id,
title: (e.type as string).toUpperCase(), title: (e.type as string).toUpperCase(),
@@ -78,19 +92,17 @@ export async function loader({ context }: { context: RequestContext }) {
}; };
}); });
const memberData = await context.env.D1.prepare( const memberData = await context.data.prisma.$queryRaw<
"SELECT id, name FROM et_members WHERE id IN (SELECT created_by FROM events WHERE month = ? AND year = ?);", EtMember[]
) >`SELECT id, name FROM et_members WHERE id IN (SELECT created_by FROM events WHERE month = ${now.getUTCMonth() + 1} AND year = ${now.getUTCFullYear()});`;
.bind(now.getUTCMonth() + 1, now.getUTCFullYear())
.all();
return { return {
calendarData, calendarData,
canManage: Boolean( canManage: Boolean(
[1 << 4, 1 << 12].find((p) => context.data.current_user.permissions & p), [1 << 4, 1 << 12].find((p) => context.data.current_user.permissions & p),
), ),
eventList: eventsData.results, eventList: eventsData,
memberData: memberData.results, memberData,
}; };
} }
@@ -111,15 +123,7 @@ export default function () {
<ModalBody> <ModalBody>
<Heading size="md">Host</Heading> <Heading size="md">Host</Heading>
<Text> <Text>
{ {data.memberData.find((m) => m.id === eventData.created_by)?.name}
(
data.memberData.find(
(m) => m.id === eventData.created_by,
) as {
[k: string]: any;
}
)?.name
}
</Text> </Text>
<br /> <br />
<Heading size="md">Event Type</Heading> <Heading size="md">Event Type</Heading>

View File

@@ -25,14 +25,13 @@ export async function loader({ context }: { context: RequestContext }) {
status: 403, status: 403,
}); });
const memberResults = await context.env.D1.prepare( const { prisma } = context.data;
"SELECT id, name FROM et_members;", const memberResults = await prisma.etMember.findMany({
).all(); select: {
id: true,
if (!memberResults.success) name: true,
throw new Response(null, { },
status: 500, });
});
const data: { const data: {
[k: string]: { [k: string]: {
@@ -45,7 +44,7 @@ export async function loader({ context }: { context: RequestContext }) {
}; };
} = {}; } = {};
for (const row of memberResults.results as Record<string, string>[]) { for (const row of memberResults) {
data[row.id].fotd = 0; data[row.id].fotd = 0;
data[row.id].gamenight = 0; data[row.id].gamenight = 0;
data[row.id].name = row.name; data[row.id].name = row.name;
@@ -53,22 +52,26 @@ export async function loader({ context }: { context: RequestContext }) {
data[row.id].qotd = 0; data[row.id].qotd = 0;
} }
const eventsResult = await context.env.D1.prepare( const eventsResult = await prisma.event.findMany({
"SELECT answered_at, created_by, day, month, performed_at, reached_minimum_player_count, type, year FROM events;", select: {
).all(); answered_at: true,
created_by: true,
day: true,
month: true,
performed_at: true,
reached_minimum_player_count: true,
type: true,
year: true,
},
});
if (!eventsResult.success) for (const row of eventsResult) {
throw new Response(null, { const creator = row.created_by;
status: 500, const type = row.type;
});
for (const row of eventsResult.results) {
const creator = row.created_by as string;
const type = row.type as string;
if (!data[creator]) continue; if (!data[creator]) continue;
if (row.performed_at) data[creator][type as string] += 10; if (row.performed_at) data[creator][type] += 10;
else { else {
const now = new Date(); const now = new Date();
const currentYear = now.getUTCFullYear(); const currentYear = now.getUTCFullYear();
@@ -76,33 +79,17 @@ export async function loader({ context }: { context: RequestContext }) {
const currentDay = now.getUTCDate(); const currentDay = now.getUTCDate();
if ( if (
(row.year as number) < currentYear || row.year < currentYear ||
(currentYear === row.year && currentMonth > (row.month as number)) || (currentYear === row.year && currentMonth > row.month) ||
(currentMonth === row.month && (currentMonth === row.month &&
currentYear === row.year && currentYear === row.year &&
(row.day as number) < currentDay) row.day < currentDay)
) )
data[creator][type] -= 5; data[creator][type] -= 5;
} }
switch (row.type) { if (row.type === "gamenight" && row.reached_minimum_player_count)
case "gamenight": data[creator].gamenight += 10;
if (row.reached_minimum_player_count) data[creator].gamenight += 10;
break;
case "rotw":
if (
(row.answered_at as number) - (row.performed_at as number) >=
86400000
)
data[creator].rotw += 10;
break;
default:
break;
}
} }
return data; return data;

View File

@@ -44,9 +44,12 @@ export async function loader({ context }: { context: RequestContext }) {
status: 403, status: 403,
}); });
return ( return await context.data.prisma.etMember.findMany({
await context.env.D1.prepare("SELECT id, name FROM et_members;").all() select: {
).results; id: true,
name: true,
},
});
} }
export default function () { export default function () {

View File

@@ -37,14 +37,40 @@ export async function loader({ context }: { context: RequestContext }) {
year--; year--;
} }
const data = await context.env.D1.prepare( const data = await context.data.prisma.event.findMany({
"SELECT day, details, id FROM events WHERE approved = 1 AND month = ? AND year = ? AND (performed_at IS NULL OR (reached_minimum_player_count = 0 AND type = 'gamenight')) ORDER BY day;", orderBy: {
) day: "asc",
.bind(month, year) },
.all(); select: {
answered_at: true,
day: true,
details: true,
id: true,
performed_at: true,
reached_minimum_player_count: true,
type: true,
},
where: {
AND: {
approved: true,
month,
year,
OR: [
{
AND: [
{
reached_minimum_player_count: false,
type: "gamenight",
},
],
},
],
},
},
});
return { return {
events: data.results as Record<string, string | number>[], events: data,
past_cutoff: now.getUTCDate() > 7, past_cutoff: now.getUTCDate() > 7,
}; };
} }
@@ -52,7 +78,7 @@ export async function loader({ context }: { context: RequestContext }) {
export default function () { export default function () {
const { events, past_cutoff } = useLoaderData<typeof loader>(); const { events, past_cutoff } = useLoaderData<typeof loader>();
const { isOpen, onClose, onOpen } = useDisclosure(); const { isOpen, onClose, onOpen } = useDisclosure();
const [eventData, setEventData] = useState({} as { [k: string]: any }); const [eventData, setEventData] = useState({} as (typeof events)[number]);
const [isBrowserSupported, setIsBrowserSupported] = useState(true); const [isBrowserSupported, setIsBrowserSupported] = useState(true);
const toast = useToast(); const toast = useToast();
@@ -74,10 +100,10 @@ export default function () {
}); });
} }
function getStatus(event: { [k: string]: string | number }) { function getStatus(event: (typeof events)[number]) {
if (!event.performed_at) return "Approved"; if (!event.performed_at) return "Approved";
if (event.type === "rotw" && event.answered_at) return "Solved"; if (event.type === "rotw" && event.answered_at) return "Solved";
if (event.type === "gamenight" && event.areached_minimum_player_count) if (event.type === "gamenight" && event.reached_minimum_player_count)
return "Certified"; return "Certified";
return "Completed"; return "Completed";
@@ -106,7 +132,7 @@ export default function () {
}); });
const newData = structuredClone(eventData); const newData = structuredClone(eventData);
newData.reached_minimum_player_count = 1; newData.reached_minimum_player_count = true;
setEventData(newData); setEventData(newData);
} }
@@ -134,9 +160,12 @@ export default function () {
}); });
const newData = structuredClone(eventData); const newData = structuredClone(eventData);
newData.performed_at = Date.now();
setEventData(newData); setEventData(
Object.defineProperty(newData, "performed_at", {
value: new Date().toISOString(),
}),
);
} }
async function forgotten() { async function forgotten() {
@@ -162,9 +191,12 @@ export default function () {
}); });
const newData = structuredClone(eventData); const newData = structuredClone(eventData);
newData.performed_at = 0;
setEventData(newData); setEventData(
Object.defineProperty(newData, "performed_at", {
value: new Date().toISOString(),
}),
);
} }
async function solve() { async function solve() {
@@ -190,9 +222,12 @@ export default function () {
}); });
const newData = structuredClone(eventData); const newData = structuredClone(eventData);
newData.answered_at = Date.now();
setEventData(newData); setEventData(
Object.defineProperty(newData, "performed_at", {
value: new Date().toISOString(),
}),
);
} }
return ( return (
@@ -216,13 +251,13 @@ export default function () {
<Box gap="8px"> <Box gap="8px">
<Heading size="xs">Completion</Heading> <Heading size="xs">Completion</Heading>
<Button <Button
disabled={typeof eventData.completed_at === "number"} disabled={Boolean(eventData.performed_at)}
onClick={async () => await completed()} onClick={async () => await completed()}
> >
Mark as Complete Mark as Complete
</Button> </Button>
<Button <Button
disabled={typeof eventData.completed_at === "number"} disabled={typeof eventData.performed_at === "number"}
onClick={async () => await forgotten()} onClick={async () => await forgotten()}
> >
Mark as Forgotten Mark as Forgotten
@@ -243,7 +278,7 @@ export default function () {
<Box gap="8px"> <Box gap="8px">
<Heading size="xs">Certified Status</Heading> <Heading size="xs">Certified Status</Heading>
<Button <Button
disabled={Boolean(eventData.reached_minimum_player_count)} disabled={eventData.reached_minimum_player_count}
onClick={async () => await certify()} onClick={async () => await certify()}
> >
{eventData.reached_minimum_player_count {eventData.reached_minimum_player_count
@@ -277,8 +312,8 @@ export default function () {
<Tr> <Tr>
<Td>{event.day}</Td> <Td>{event.day}</Td>
<Td> <Td>
{(event.details as string).length > 100 {event.details.length > 100
? `${(event.details as string).substring(0, 97)}...` ? `${event.details.substring(0, 97)}...`
: event.details} : event.details}
</Td> </Td>
<Td>{getStatus(event)}</Td> <Td>{getStatus(event)}</Td>

View File

@@ -2,15 +2,18 @@ import { jsonError } from "../../../common.js";
export async function onRequestDelete(context: RequestContext) { export async function onRequestDelete(context: RequestContext) {
const eventId = context.params.id as string; const eventId = context.params.id as string;
const eventData: const eventData = await context.data.prisma.event.findUnique({
| ({ select: {
[k: string]: number; created_by: true,
} & { created_by: string }) day: true,
| null = await context.env.D1.prepare( month: true,
"SELECT created_by, day, month, performed_at, year FROM events WHERE id = ?;", performed_at: true,
) year: true,
.bind(eventId) },
.first(); where: {
id: eventId,
},
});
if (!eventData) return jsonError("No event exists with that ID", 404); if (!eventData) return jsonError("No event exists with that ID", 404);
@@ -41,9 +44,11 @@ export async function onRequestDelete(context: RequestContext) {
400, 400,
); );
await context.env.D1.prepare("DELETE FROM events WHERE id = ?;") await context.data.prisma.event.delete({
.bind(eventId) where: {
.run(); id: eventId,
},
});
return new Response(null, { return new Response(null, {
status: 204, status: 204,
@@ -53,13 +58,18 @@ export async function onRequestDelete(context: RequestContext) {
export async function onRequestPatch(context: RequestContext) { export async function onRequestPatch(context: RequestContext) {
const eventId = context.params.id as string; const eventId = context.params.id as string;
const { body } = context.data; const { body } = context.data;
const eventData: const eventData = await context.data.prisma.event.findUnique({
| ({ [k: string]: number } & { created_by: string; type: string }) select: {
| null = await context.env.D1.prepare( created_by: true,
"SELECT created_by, day, month, type, year FROM events WHERE id = ?;", day: true,
) month: true,
.bind(eventId) type: true,
.first(); year: true,
},
where: {
id: eventId,
},
});
if (!eventData) return jsonError("No event exists with that ID", 404); if (!eventData) return jsonError("No event exists with that ID", 404);
@@ -83,7 +93,7 @@ export async function onRequestPatch(context: RequestContext) {
typeof body.day !== "number" || typeof body.day !== "number" ||
body.day > date.getUTCDate() || body.day > date.getUTCDate() ||
body.day < 1 || body.day < 1 ||
// Check for non-integers // Check for nonintegers
Math.floor(body.day) !== body.day || Math.floor(body.day) !== body.day ||
currentDay >= body.day currentDay >= body.day
) )
@@ -107,26 +117,38 @@ export async function onRequestPatch(context: RequestContext) {
4: 35, 4: 35,
}; };
const weekRange = Math.floor(body.day / 7); const weekRange = Math.floor(body.day / 7);
const matchingROTW = await context.data.prisma.event.findMany({
const matchingROTW = await context.env.D1.prepare( select: {
"SELECT id FROM events WHERE (approved = 1 OR pending = 1) AND day BETWEEN ? AND ? AND month = ? AND type = 'rotw' AND year = ?;", id: true,
) },
.bind( where: {
weekRanges[weekRange] - 7, OR: [{ approved: true }, { pending: true }],
weekRanges[weekRange], day: {
eventData.month, gte: weekRanges[weekRange] - 7,
eventData.year, lte: weekRanges[weekRange],
) },
.first(); month: eventData.month,
year: eventData.year,
},
});
if (matchingROTW) if (matchingROTW)
return jsonError("There is already an ROTW scheduled for that week", 400); return jsonError("There is already an ROTW scheduled for that week", 400);
} else { } else {
const matchingEvent = await context.env.D1.prepare( const matchingEvent = await context.data.prisma.event.findMany({
"SELECT id FROM events WHERE (approved = 1 OR pending = 1) AND day = ? AND month = ? AND type = ? AND year = ?;", select: {
) id: true,
.bind(body.day, eventData.month, eventData.type, eventData.year) },
.first(); where: {
OR: [{ approved: true }, { pending: true }],
AND: [
{ day: body.day },
{ month: eventData.month },
{ type: eventData.type },
{ year: eventData.year },
],
},
});
if (matchingEvent) if (matchingEvent)
return jsonError( return jsonError(
@@ -135,9 +157,14 @@ export async function onRequestPatch(context: RequestContext) {
); );
} }
await context.env.D1.prepare("UPDATE events SET day = ? WHERE id = ?;") await context.data.prisma.event.update({
.bind(body.day, eventId) data: {
.run(); day: body.day,
},
where: {
id: eventId,
},
});
await fetch(context.env.EVENTS_WEBHOOK, { await fetch(context.env.EVENTS_WEBHOOK, {
body: JSON.stringify({ body: JSON.stringify({
@@ -162,22 +189,29 @@ export async function onRequestPatch(context: RequestContext) {
export async function onRequestPost(context: RequestContext) { export async function onRequestPost(context: RequestContext) {
const eventId = context.params.id as string; const eventId = context.params.id as string;
const eventData = await context.env.D1.prepare( const eventData = await context.data.prisma.event.findUnique({
"SELECT approved, performed_at FROM events WHERE id = ?;", select: {
) approved: true,
.bind(eventId) performed_at: true,
.first(); },
where: {
id: eventId,
},
});
if (!eventData) return jsonError("No event exists with that ID", 404); if (!eventData) return jsonError("No event exists with that ID", 404);
if (!eventData.approved) if (!eventData.approved)
return jsonError("Cannot perform unapproved event", 403); return jsonError("Cannot perform unapproved event", 403);
await context.env.D1.prepare( await context.data.prisma.event.update({
"UPDATE events SET performed_at = ? WHERE id = ?;", data: {
) performed_at: new Date(),
.bind(Date.now(), eventId) },
.run(); where: {
id: eventId,
},
});
return new Response(null, { return new Response(null, {
status: 204, status: 204,

View File

@@ -6,12 +6,11 @@ export async function onRequest(context: RequestContext) {
// Skip checks for the by-id endpoint // Skip checks for the by-id endpoint
if (pathSegments.length <= 5) return await context.next(); if (pathSegments.length <= 5) return await context.next();
const eventInfo = await context.env.D1.prepare( const eventInfo = await context.data.prisma.event.findUnique({
"SELECT * FROM events WHERE id = ?;", where: {
) id: context.params.id as string,
.bind(context.params.id) },
.first(); });
if (!eventInfo) return jsonError("This event does not exist.", 404); if (!eventInfo) return jsonError("This event does not exist.", 404);
if (![1 << 4, 1 << 12].find((p) => context.data.current_user.permissions & p)) if (![1 << 4, 1 << 12].find((p) => context.data.current_user.permissions & p))

View File

@@ -10,7 +10,7 @@ export async function onRequestPost(context: RequestContext) {
try { try {
await D1.batch([ await D1.batch([
D1.prepare( D1.prepare(
"UPDATE events SET reached_minimum_player_count = 1 WHERE id = ?", "UPDATE events SET reached_minimum_player_count = TRUE WHERE id = ?",
).bind(event.id), ).bind(event.id),
D1.prepare( D1.prepare(
"UPDATE et_members SET points = points + 10 WHERE id = ?;", "UPDATE et_members SET points = points + 10 WHERE id = ?;",

View File

@@ -5,23 +5,25 @@ export async function onRequestPost(context: RequestContext) {
const { event } = context.data; const { event } = context.data;
try { try {
const completionTimeRow = await D1.prepare( const completionTimeRow = await context.data.prisma.event.findUnique({
"SELECT performed_at FROM events WHERE id = ?;", select: {
) performed_at: true,
.bind(event.id) },
.first(); where: {
id: event.id,
},
});
if (typeof completionTimeRow?.performed_at === "number") if (completionTimeRow?.performed_at instanceof Date)
return jsonError( return jsonError(
"The event is already marked as complete or forgotten", "The event is already marked as complete or forgotten",
400, 400,
); );
await D1.batch([ await D1.batch([
D1.prepare("UPDATE events SET performed_at = ? WHERE id = ?;").bind( D1.prepare(
Date.now(), "UPDATE events SET performed_at = CURRENT_TIMESTAMP WHERE id = ?;",
event.id, ).bind(Date.now(), event.id),
),
D1.prepare( D1.prepare(
"UPDATE et_members SET points = points + 10 WHERE id = ?;", "UPDATE et_members SET points = points + 10 WHERE id = ?;",
).bind(event.created_by), ).bind(event.created_by),

View File

@@ -5,12 +5,15 @@ export async function onRequestPost(context: RequestContext) {
if (typeof context.data.body.approved !== "boolean") if (typeof context.data.body.approved !== "boolean")
return jsonError("Decision type must be a boolean", 400); return jsonError("Decision type must be a boolean", 400);
const updatedEvent: Record<string, number | string> | null = const updatedEvent = await context.data.prisma.event.update({
await context.env.D1.prepare( data: {
"UPDATE events SET approved = ?, pending = 0 WHERE id = ? RETURNING created_by, day, month, year;", approved: context.data.body.approved,
) pending: false,
.bind(Number(context.data.body.approved), context.data.event.id) },
.first(); where: {
id: context.data.event.id,
},
});
if (!updatedEvent) return jsonError("This event does not exist", 404); if (!updatedEvent) return jsonError("This event does not exist", 404);
@@ -19,10 +22,14 @@ export async function onRequestPost(context: RequestContext) {
type: "json", type: "json",
}); });
const usernameData: Record<string, string> | null = const usernameData = await context.data.prisma.etMember.findUnique({
await context.env.D1.prepare("SELECT name FROM et_members WHERE id = ?;") where: {
.bind(updatedEvent.created_by) id: updatedEvent.created_by,
.first(); },
select: {
name: true,
},
});
if (emailData && usernameData) { if (emailData && usernameData) {
await sendEmail( await sendEmail(

View File

@@ -2,22 +2,25 @@ import { jsonError } from "../../../../common.js";
export async function onRequestPost(context: RequestContext) { export async function onRequestPost(context: RequestContext) {
const { D1 } = context.env; const { D1 } = context.env;
const { event } = context.data; const { event, prisma } = context.data;
try { try {
const row = await D1.prepare( const row = await prisma.event.findUnique({
"SELECT performed_at FROM events WHERE id = ?;", select: {
) performed_at: true,
.bind(event.id) },
.first(); where: {
id: event.id,
},
});
if (typeof row?.performed_at === "number") if (row?.performed_at instanceof Date)
return jsonError("Event already marked as completed or forgotten", 400); return jsonError("Event already marked as completed or forgotten", 400);
await D1.batch([ await D1.batch([
D1.prepare("UPDATE events SET performed_at = 0 WHERE id = ?;").bind( D1.prepare(
event.id, "UPDATE events SET performed_at = datetime(0, 'unixepoch') WHERE id = ?;",
), ).bind(event.id),
D1.prepare( D1.prepare(
"UPDATE et_members SET points = points - 5 WHERE id = ?;", "UPDATE et_members SET points = points - 5 WHERE id = ?;",
).bind(event.created_by), ).bind(event.created_by),

View File

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

View File

@@ -12,9 +12,14 @@ export async function onRequestPost(context: RequestContext) {
if (typeof points !== "number") return jsonError("Invalid point count", 400); if (typeof points !== "number") return jsonError("Invalid point count", 400);
await context.env.D1.prepare("UPDATE et_members SET points = ? WHERE id = ?;") await context.data.prisma.etMember.update({
.bind(points, context.params.id) data: {
.run(); points,
},
where: {
id: context.params.id as string,
},
});
return new Response(null, { return new Response(null, {
status: 204, status: 204,

View File

@@ -1,7 +1,9 @@
export async function onRequestDelete(context: RequestContext) { export async function onRequestDelete(context: RequestContext) {
await context.env.D1.prepare("DELETE FROM et_strikes WHERE id = ?;") await context.data.prisma.etStrike.delete({
.bind(context.params.id) where: {
.run(); id: context.params.id as string,
},
});
return new Response(null, { return new Response(null, {
status: 204, status: 204,

View File

@@ -11,9 +11,11 @@ export async function onRequestPost(context: RequestContext) {
user.length > 20 || user.length > 20 ||
user.length < 17 || user.length < 17 ||
user.match(/\D/) || user.match(/\D/) ||
!(await D1.prepare("SELECT id FROM et_members WHERE id = ?;") !(await context.data.prisma.etMember.findUnique({
.bind(user) where: {
.first()) id: user,
},
}))
) )
return jsonError("Invalid user id", 400); return jsonError("Invalid user id", 400);

View File

@@ -19,9 +19,9 @@ export async function onRequestDelete(context: RequestContext) {
) )
return jsonError("Invalid ID", 400); return jsonError("Invalid ID", 400);
await context.env.D1.prepare("DELETE FROM et_members WHERE id = ?;") await context.data.prisma.etMember.delete({
.bind(id) where: { id },
.run(); });
return new Response(null, { return new Response(null, {
status: 204, status: 204,
@@ -40,9 +40,10 @@ export async function onRequestPatch(context: RequestContext) {
if (typeof body.name !== "string" && typeof body.roblox_username !== "string") if (typeof body.name !== "string" && typeof body.roblox_username !== "string")
return jsonError("At least one property must be provided", 400); return jsonError("At least one property must be provided", 400);
const updates = []; let queryData: { name?: string; roblox_id?: number } = {};
if (body.name?.length) updates.push({ query: "name = ?", value: body.name }); if (body.name?.length)
queryData = Object.defineProperty(queryData, "name", { value: body.name });
if (typeof body.roblox_username === "string" && body.roblox_username) { if (typeof body.roblox_username === "string" && body.roblox_username) {
const robloxResolveResp = await fetch( const robloxResolveResp = await fetch(
@@ -66,21 +67,22 @@ export async function onRequestPatch(context: RequestContext) {
if (!data.length) if (!data.length)
return jsonError("No Roblox user exists with that name", 400); return jsonError("No Roblox user exists with that name", 400);
updates.push({ query: "roblox_id = ?", value: data[0].id }); queryData = Object.defineProperty(queryData, "roblox_id", {
value: data[0].id,
});
} }
await context.env.D1.prepare( await context.data.prisma.etMember.update({
`UPDATE et_members data: queryData,
SET ${updates.map((u) => u.query).join(", ")} where: {
WHERE id = ?;`, id: body.id,
) },
.bind(...updates.map((u) => u.value), body.id) });
.run();
return jsonResponse( return jsonResponse(
JSON.stringify({ JSON.stringify({
name: body.name, name: body.name,
roblox_id: updates.find((u) => typeof u.value === "number")?.value, roblox_id: queryData.roblox_id,
}), }),
); );
} }
@@ -100,9 +102,11 @@ export async function onRequestPost(context: RequestContext) {
return jsonError("Invalid name", 400); return jsonError("Invalid name", 400);
if ( if (
await context.env.D1.prepare("SELECT * FROM et_members WHERE id = ?;") await context.data.prisma.etMember.findUnique({
.bind(id) where: {
.first() id,
},
})
) )
return jsonError("User is already a member", 400); return jsonError("User is already a member", 400);
@@ -151,14 +155,16 @@ export async function onRequestPost(context: RequestContext) {
roblox_id = data[0].id; roblox_id = data[0].id;
} }
const createdAt = Date.now();
const addingUser = context.data.current_user.id; const addingUser = context.data.current_user.id;
await context.env.D1.prepare( await context.data.prisma.etMember.create({
"INSERT INTO et_members (created_at, created_by, id, name, roblox_id) VALUES (?, ?, ?, ?, ?);", data: {
) created_by: addingUser,
.bind(createdAt, addingUser, id, name, roblox_id || null) id,
.run(); name,
roblox_id,
},
});
return new Response(null, { return new Response(null, {
status: 204, status: 204,

View File

@@ -3,13 +3,12 @@ import { jsonError } from "../../common.js";
export async function onRequestDelete(context: RequestContext) { export async function onRequestDelete(context: RequestContext) {
const path = decodeURIComponent(context.params.id as string); const path = decodeURIComponent(context.params.id as string);
if (typeof path !== "string") return jsonError("Invalid path", 400); await context.data.prisma.shortLink.delete({
where: {
await context.env.D1.prepare( path,
"DELETE FROM short_links WHERE path = ? AND user = ?;", user: context.data.current_user.id,
) },
.bind(path, context.data.current_user.id) });
.run();
return new Response(null, { return new Response(null, {
status: 204, status: 204,
@@ -39,15 +38,15 @@ export async function onRequestPatch(context: RequestContext) {
if (path.length > 256) return jsonError("Path is too long", 400); if (path.length > 256) return jsonError("Path is too long", 400);
await context.env.D1.prepare( await context.data.prisma.shortLink.update({
"UPDATE short_links SET path = ? WHERE path = ? AND user = ?;", data: {
)
.bind(
path, path,
decodeURIComponent(context.params.id as string), },
context.data.current_user.id, where: {
) path: decodeURIComponent(context.params.id as string),
.run(); user: context.data.current_user.id,
},
});
return new Response(null, { return new Response(null, {
status: 204, status: 204,

View File

@@ -9,11 +9,10 @@ export default async function (
if (!roles) permissions |= 1 << 1; if (!roles) permissions |= 1 << 1;
if (roles?.includes("593209890949038082")) permissions |= 1 << 2; // Discord Moderator if (roles?.includes("593209890949038082")) permissions |= 1 << 2; // Discord Moderator
if ( if (
Boolean( await context.data.prisma.etMember.findUnique({
await context.env.D1.prepare("SELECT * FROM et_members WHERE id = ?;") select: { id: true },
.bind(userid) where: { id: userid },
.first(), })
)
) )
permissions |= 1 << 3; // Events Team permissions |= 1 << 3; // Events Team
if (roles?.includes("607594065952899072")) permissions |= 1 << 4; // Events Manager if (roles?.includes("607594065952899072")) permissions |= 1 << 4; // Events Manager