fix: update match configuration to bestOf 5 and scoringType to score_v2
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import { d as db, u as user, p as playerRating } from "../../../../chunks/index2.js";
|
||||
import { eq, desc } from "drizzle-orm";
|
||||
import { error } from "@sveltejs/kit";
|
||||
const ROLE_HIERARCHY = {
|
||||
player: 0,
|
||||
referee: 1,
|
||||
admin: 2
|
||||
};
|
||||
function hasRole(userRole, minRole) {
|
||||
const level = ROLE_HIERARCHY[userRole] ?? 0;
|
||||
const required = ROLE_HIERARCHY[minRole];
|
||||
return level >= required;
|
||||
}
|
||||
function requireRole(locals, minRole, message = "Insufficient permissions") {
|
||||
if (!locals.user) {
|
||||
error(401, "Not logged in");
|
||||
}
|
||||
if (!hasRole(locals.user.role, minRole)) {
|
||||
error(403, message);
|
||||
}
|
||||
}
|
||||
async function setUserRole(userId, role) {
|
||||
await db.update(user).set({ role }).where(eq(user.id, userId));
|
||||
}
|
||||
const load = async ({ locals }) => {
|
||||
requireRole(locals, "admin");
|
||||
const users = await db.query.user.findMany({
|
||||
orderBy: desc(user.createdAt)
|
||||
});
|
||||
const usersWithRatings = await Promise.all(
|
||||
users.map(async (u) => {
|
||||
const rating = await db.query.playerRating.findFirst({
|
||||
where: eq(playerRating.userId, u.id)
|
||||
});
|
||||
return {
|
||||
id: u.id,
|
||||
name: u.name,
|
||||
email: u.email,
|
||||
image: u.image,
|
||||
role: u.role ?? "player",
|
||||
createdAt: u.createdAt,
|
||||
elo: rating?.elo ?? 1e3,
|
||||
wins: rating?.wins ?? 0,
|
||||
losses: rating?.losses ?? 0
|
||||
};
|
||||
})
|
||||
);
|
||||
return { users: usersWithRatings };
|
||||
};
|
||||
const actions = {
|
||||
setRole: async ({ request, locals }) => {
|
||||
requireRole(locals, "admin");
|
||||
const form = await request.formData();
|
||||
const userId = form.get("userId")?.toString();
|
||||
const role = form.get("role")?.toString();
|
||||
if (!userId || !role) return { error: "User ID and role are required" };
|
||||
if (!["player", "referee", "admin"].includes(role)) {
|
||||
return { error: "Invalid role" };
|
||||
}
|
||||
if (userId === locals.user.id && role !== "admin") {
|
||||
return { error: "You can't demote yourself" };
|
||||
}
|
||||
await setUserRole(userId, role);
|
||||
return { success: true };
|
||||
}
|
||||
};
|
||||
export {
|
||||
actions,
|
||||
load
|
||||
};
|
||||
@@ -0,0 +1,70 @@
|
||||
import { e as escape_html, a as ensure_array_like, b as attr, s as stringify } from "../../../../chunks/index3.js";
|
||||
import "@sveltejs/kit/internal";
|
||||
import "../../../../chunks/url.js";
|
||||
import "../../../../chunks/utils.js";
|
||||
import "@sveltejs/kit/internal/server";
|
||||
import "../../../../chunks/root.js";
|
||||
import "../../../../chunks/exports.js";
|
||||
import "../../../../chunks/state.svelte.js";
|
||||
function _page($$renderer, $$props) {
|
||||
$$renderer.component(($$renderer2) => {
|
||||
let { data } = $$props;
|
||||
const roleBadge = {
|
||||
player: {
|
||||
label: "Player",
|
||||
color: "bg-surface-600 text-text-secondary border-border"
|
||||
},
|
||||
referee: {
|
||||
label: "Referee",
|
||||
color: "bg-yellow-500/20 text-yellow-400 border-yellow-500/30"
|
||||
},
|
||||
admin: {
|
||||
label: "Admin",
|
||||
color: "bg-red-500/20 text-red-400 border-red-500/30"
|
||||
}
|
||||
};
|
||||
$$renderer2.push(`<div class="mx-auto max-w-4xl"><div><h1 class="text-2xl font-700 tracking-tight">Admin Panel</h1> <p class="mt-1 text-sm text-text-secondary">${escape_html(data.users.length)} registered user${escape_html(data.users.length !== 1 ? "s" : "")}</p></div> `);
|
||||
{
|
||||
$$renderer2.push("<!--[!-->");
|
||||
}
|
||||
$$renderer2.push(`<!--]--> <div class="mt-6 rounded-lg border border-border bg-surface-800"><div class="grid grid-cols-[auto_1fr_auto_auto_auto] gap-4 border-b border-border px-4 py-3"><span class="text-xs font-600 text-text-secondary">Avatar</span> <span class="text-xs font-600 text-text-secondary">User</span> <span class="text-xs font-600 text-text-secondary">ELO</span> <span class="text-xs font-600 text-text-secondary">W/L</span> <span class="text-xs font-600 text-text-secondary">Role</span></div> <!--[-->`);
|
||||
const each_array = ensure_array_like(data.users);
|
||||
for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
|
||||
let u = each_array[$$index];
|
||||
const badge = roleBadge[u.role] ?? roleBadge.player;
|
||||
$$renderer2.push(`<div class="grid grid-cols-[auto_1fr_auto_auto_auto] items-center gap-4 border-b border-border/50 px-4 py-3 last:border-b-0">`);
|
||||
if (u.image) {
|
||||
$$renderer2.push("<!--[-->");
|
||||
$$renderer2.push(`<img${attr("src", u.image)} alt="" class="h-8 w-8 rounded-full"/>`);
|
||||
} else {
|
||||
$$renderer2.push("<!--[!-->");
|
||||
$$renderer2.push(`<div class="flex h-8 w-8 items-center justify-center rounded-full bg-surface-600 text-xs font-700 text-text-secondary">${escape_html(u.name.charAt(0).toUpperCase())}</div>`);
|
||||
}
|
||||
$$renderer2.push(`<!--]--> <div class="min-w-0"><p class="truncate text-sm font-500">${escape_html(u.name)}</p> <p class="truncate text-xs text-text-secondary">${escape_html(u.email)}</p></div> <span class="text-sm font-600 tabular-nums text-text-primary">${escape_html(u.elo)}</span> <span class="text-xs tabular-nums text-text-secondary"><span class="text-green-400">${escape_html(u.wins)}W</span> / <span class="text-red-400">${escape_html(u.losses)}L</span></span> <form method="post" action="?/setRole" class="flex items-center gap-2"><input type="hidden" name="userId"${attr("value", u.id)}/> `);
|
||||
$$renderer2.select(
|
||||
{
|
||||
name: "role",
|
||||
value: u.role,
|
||||
onchange: (e) => e.currentTarget.form?.requestSubmit(),
|
||||
class: `rounded-md border px-2 py-1 text-xs font-500 ${stringify(badge.color)} cursor-pointer bg-transparent focus:outline-none`
|
||||
},
|
||||
($$renderer3) => {
|
||||
$$renderer3.option({ value: "player", class: "bg-surface-800 text-text-primary" }, ($$renderer4) => {
|
||||
$$renderer4.push(`Player`);
|
||||
});
|
||||
$$renderer3.option({ value: "referee", class: "bg-surface-800 text-text-primary" }, ($$renderer4) => {
|
||||
$$renderer4.push(`Referee`);
|
||||
});
|
||||
$$renderer3.option({ value: "admin", class: "bg-surface-800 text-text-primary" }, ($$renderer4) => {
|
||||
$$renderer4.push(`Admin`);
|
||||
});
|
||||
}
|
||||
);
|
||||
$$renderer2.push(`</form></div>`);
|
||||
}
|
||||
$$renderer2.push(`<!--]--></div></div>`);
|
||||
});
|
||||
}
|
||||
export {
|
||||
_page as default
|
||||
};
|
||||
Reference in New Issue
Block a user