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

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