Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Drop KV for et member management
  • Loading branch information
regalijan committed Feb 1, 2024
1 parent c57b2fd commit 98a9e0e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 5 additions & 11 deletions functions/api/events-team/team-members/user.ts
Expand Up @@ -11,7 +11,6 @@ export async function onRequestDelete(context: RequestContext) {
)
return jsonError("Invalid ID", 400);

await context.env.DATA.delete(`etmember_${id}`);
await context.env.D1.prepare("DELETE FROM et_members WHERE id = ?;")
.bind(id)
.run();
Expand All @@ -35,7 +34,11 @@ export async function onRequestPost(context: RequestContext) {
if (typeof name !== "string" || !name.length || name.length > 32)
return jsonError("Invalid name", 400);

if (await context.env.DATA.get(`etmember_${id}`))
if (
await context.env.D1.prepare("SELECT * FROM et_members WHERE id = ?;")
.bind(id)
.first()
)
return jsonError("User is already a member", 400);

if (!["string", "undefined"].includes(typeof roblox_username))
Expand Down Expand Up @@ -86,15 +89,6 @@ export async function onRequestPost(context: RequestContext) {
const createdAt = Date.now();
const addingUser = context.data.current_user.id;

await context.env.DATA.put(
`etmember_${id}`,
JSON.stringify({
created_at: createdAt,
created_by: addingUser,
name,
roblox_id,
}),
);
await context.env.D1.prepare(
"INSERT INTO et_members (created_at, created_by, id, name, roblox_id) VALUES (?, ?, ?, ?, ?);",
)
Expand Down
8 changes: 7 additions & 1 deletion functions/permissions.ts
Expand Up @@ -8,7 +8,13 @@ export default async function (
if (roles?.includes("374851061233614849")) permissions |= 1 << 0; // Administration
if (!roles) permissions |= 1 << 1;
if (roles?.includes("593209890949038082")) permissions |= 1 << 2; // Discord Moderator
if (Boolean(await context.env.DATA.get(`etmember_${userid}`)))
if (
Boolean(
await context.env.D1.prepare("SELECT * FROM et_members WHERE id = ?;")
.bind(userid)
.first(),
)
)
permissions |= 1 << 3; // Events Team
if (roles?.includes("607697704419852289")) permissions |= 1 << 4; // Events Team Management
if (
Expand Down

0 comments on commit 98a9e0e

Please sign in to comment.