Update Backend

This commit is contained in:
2024-11-23 13:28:33 +01:00
parent e70951c9dd
commit cb65e96165
23 changed files with 493 additions and 310 deletions

View File

@@ -23,21 +23,17 @@
import UserInfo from "./dashboard/UserInfo.svelte";
import {dataRepo} from "@repo/data.ts";
import {schemRepo} from "@repo/schem.ts";
import SWPaginator from "@components/styled/SWPaginator.svelte";
import UploadModal from "@components/dashboard/UploadModal.svelte";
import SWButton from "@components/styled/SWButton.svelte";
let userFetch = getUser();
let schematicFetch = getSchematics();
function getUser() {
return $dataRepo.getMe()
}
function getSchematics() {
return $schemRepo.getRootSchematicList()
}
function getSchematic(id: number) {
return $schemRepo.getSchematicList(id)
}
let uploadOpen = false;
</script>
{#await userFetch}
@@ -45,16 +41,15 @@
{:then user}
<UserInfo {user} />
<hr>
<div>
{#await schematicFetch}
<p>{t("status.loading")}</p>
{:then schematics}
<SchematicList {schematics} {user} on:reset={() => schematicFetch = getSchematics()} on:to={(e) => schematicFetch = getSchematic(e.detail.id) } />
{:catch error}
<p>error: {error.message}</p>
{/await}
<div class="flex flex-col justify-center">
<SWButton on:click={() => uploadOpen = true}>
{t("dashboard.schematic.upload")}
</SWButton>
</div>
{:catch error}
<p>error: {error.message}</p>
{/await}
<UploadModal bind:open={uploadOpen} on:refresh />

View File

@@ -33,13 +33,6 @@
export let group: string | null = "";
export let groupSearch = "";
$: selectPlayers = $players.map(player => {
return {
name: player.name,
value: player.id.toString()
};
}).sort((a, b) => a.name.localeCompare(b.name));
$: selectableTeams = teams.map(team => {
return {
name: team.name,

View File

@@ -32,8 +32,8 @@
$: lowerCaseSearch = search.toLowerCase();
$: filteredPlayers = $players.filter(value => value.name.toLowerCase().includes(lowerCaseSearch));
let selectedPlayer: number | null = null;
$: player = $players.find(value => value.id === selectedPlayer);
let selectedPlayer: string | null = null;
$: player = $players.find(value => value.uuid === selectedPlayer);
let playerPerms = loadPlayer(selectedPlayer);
$: playerPerms = loadPlayer(selectedPlayer);
@@ -44,7 +44,7 @@
let resetPassword = "";
let resetPasswordRepeat = "";
function loadPlayer(id: number | null) {
function loadPlayer(id: string | null) {
if (!id) {
return;
}
@@ -122,10 +122,10 @@
</div>
{#if filteredPlayers.length < 100}
<ul class="flex-1 overflow-scroll">
{#each filteredPlayers as player (player.id)}
{#each filteredPlayers as player (player.uuid)}
<li class="p-4 transition-colors hover:bg-gray-700 cursor-pointer"
class:text-orange-500={player.id === selectedPlayer}
on:click|preventDefault={() => selectedPlayer = player.id}>
class:text-orange-500={player.uuid === selectedPlayer}
on:click|preventDefault={() => selectedPlayer = player.uuid}>
{player.name}
</li>
{/each}

View File

@@ -96,7 +96,7 @@
$: selectPlayers = $players.map(player => {
return {
name: player.name,
value: player.id.toString()
value: player.uuid
};
}).sort((a, b) => a.name.localeCompare(b.name));
let spectatePort = "";

View File

@@ -39,14 +39,14 @@
async function addReferee() {
if (selectedPlayer) {
referees = (await $eventRepo.updateEvent(data.event.id.toString(), {
addReferee: [parseInt(selectedPlayer)]
addReferee: [selectedPlayer]
})).referees;
}
reset();
}
function removeReferee(id: number) {
function removeReferee(id: string) {
return async () => {
referees = (await $eventRepo.updateEvent(data.event.id.toString(), {
removeReferee: [id]
@@ -64,7 +64,7 @@
{#each referees as referee}
<li class="flex flex-grow justify-between">
{referee.name}
<SWButton on:click={removeReferee(referee.id)}>
<SWButton on:click={removeReferee(referee.uuid)}>
Entfernen
</SWButton>
</li>
@@ -83,7 +83,7 @@
<div class="flex flex-grow justify-center h-80">
<div>
<TypeAheadSearch bind:searchValue bind:selected={selectedPlayer}
items={$players.map(v => ({ name: v.name, value: v.id.toString() }))}/>
items={$players.map(v => ({ name: v.name, value: v.uuid }))}/>
</div>
</div>
<div slot="footer" class="flex flex-grow justify-end">

View File

@@ -40,7 +40,6 @@
export let schematics: SchematicList;
export let user: Player;
let uploadOpen = false;
let infoModalId: number | null = null;
function schemListClick(isDir: boolean, id: number) {
@@ -77,11 +76,6 @@
</BreadcrumbItem>
{/each}
</Breadcrumb>
<div class="flex flex-col justify-center">
<SWButton on:click={() => uploadOpen = true}>
{t("dashboard.schematic.upload")}
</SWButton>
</div>
</div>
<table>
<tbody>
@@ -133,8 +127,6 @@
<SWPaginator bind:page maxPage={maxPage} />
<UploadModal bind:open={uploadOpen} on:refresh />
{#if infoModalId !== null}
<SchematicInfo schematicId={infoModalId} {user} on:reset={() => infoModalId = null} />
{/if}

View File

@@ -38,8 +38,8 @@ export interface UpdateEvent {
maxTeamMembers?: number;
schemType?: string | null;
publicSchemsOnly?: boolean;
addReferee?: number[];
removeReferee?: number[];
addReferee?: string[];
removeReferee?: string[];
}
export class EventRepo {

View File

@@ -36,11 +36,11 @@ export class PermsRepo {
}
}
public async getPerms(userId: number): Promise<UserPerms> {
public async getPerms(userId: string): Promise<UserPerms> {
return await fetchWithToken(this.token, `/perms/user/${userId}`).then(value => value.json()).then(UserPermsSchema.parse);
}
public async setPrefix(userId: number, prefix: string): Promise<void> {
public async setPrefix(userId: string, prefix: string): Promise<void> {
const res = await fetchWithToken(this.token, `/perms/user/${userId}/prefix/${prefix}`, {
method: "PUT",
});
@@ -50,7 +50,7 @@ export class PermsRepo {
}
}
public async addPerm(userId: number, perm: string): Promise<void> {
public async addPerm(userId: string, perm: string): Promise<void> {
const res = await fetchWithToken(this.token, `/perms/user/${userId}/${perm}`, {
method: "PUT",
});
@@ -60,7 +60,7 @@ export class PermsRepo {
}
}
public async removePerm(userId: number, perm: string): Promise<void> {
public async removePerm(userId: string, perm: string): Promise<void> {
const res = await fetchWithToken(this.token, `/perms/user/${userId}/${perm}`, {
method: "DELETE",
});

View File

@@ -18,26 +18,13 @@
*/
import {fetchWithToken, tokenStore} from "./repo.ts";
import {type Schematic, type SchematicInfo, type SchematicList, SchematicSchema} from "@type/schem.ts";
import {SchematicInfoSchema, SchematicListSchema} from "@type/schem.ts";
import {type Schematic, SchematicSchema} from "@type/schem.ts";
import {derived} from "svelte/store";
export class SchematicRepo {
constructor(private token: string) {
}
public async getRootSchematicList(): Promise<SchematicList> {
return await fetchWithToken(this.token, "/schem").then(value => value.json()).then(SchematicListSchema.parse);
}
public async getSchematicList(id: number): Promise<SchematicList> {
return await fetchWithToken(this.token, `/schem/${id}/list`).then(value => value.json()).then(SchematicListSchema.parse);
}
public async getSchematicInfo(id: number): Promise<SchematicInfo> {
return await fetchWithToken(this.token, `/schem/${id}`).then(value => value.json()).then(SchematicInfoSchema.parse);
}
public async getSchematicCodeInfo(code: string): Promise<Schematic> {
return await fetchWithToken(this.token, `/download/${code}/info`).then(value => value.json()).then(SchematicSchema.parse);
}

View File

@@ -35,7 +35,7 @@ export class StatsRepo {
return await fetchWithToken(this.token, "/stats/fights").then(value => value.json()).then(FightStatsSchema.parse);
}
public async getUserStats(id: number): Promise<UserStats> {
public async getUserStats(id: string): Promise<UserStats> {
return await fetchWithToken(this.token, `/stats/user/${id}`).then(value => value.json()).then(UserStatsSchema.parse);
}
}

View File

@@ -25,7 +25,7 @@ export class UserRepo {
constructor(private token: string) {
}
public async setPassword(id: number, password: string): Promise<void> {
public async setPassword(id: string, password: string): Promise<void> {
await fetchWithToken(this.token, `/user/${id}/admin/password`, {
method: "PUT",
body: password,

View File

@@ -33,19 +33,19 @@ export const schemTypes = cached<SchematicType[]>([], () =>
.then(res => res.json()));
export const players = cached<Player[]>([], async () => {
const res = await fetchWithToken(get(tokenStore), "/data/users");
const res = await fetchWithToken(get(tokenStore), "/data/admin/users");
return z.array(PlayerSchema).parse(await res.json());
});
export const gamemodes = cached<string[]>([], async () => {
const res = await fetchWithToken(get(tokenStore), "/data/gamemodes");
const res = await fetchWithToken(get(tokenStore), "/data/admin/gamemodes");
return z.array(z.string()).parse(await res.json());
});
export const maps = cachedFamily<string, string[]>([], async (gamemode) => {
if (get(gamemodes).every(value => value !== gamemode)) return [];
const res = await fetchWithToken(get(tokenStore), `/data/gamemodes/${gamemode}/maps`);
const res = await fetchWithToken(get(tokenStore), `/data/admin/gamemodes/${gamemode}/maps`);
if (!res.ok) {
return [];
} else {
@@ -54,7 +54,7 @@ export const maps = cachedFamily<string, string[]>([], async (gamemode) => {
});
export const groups = cached<string[]>([], async () => {
const res = await fetchWithToken(get(tokenStore), "/data/groups");
const res = await fetchWithToken(get(tokenStore), "/data/admin/groups");
return z.array(z.string()).parse(await res.json());
});

View File

@@ -27,7 +27,6 @@ export const SchematicTypeSchema = z.object({
export type SchematicType = z.infer<typeof SchematicTypeSchema>;
export const PlayerSchema = z.object({
id: z.number(),
name: z.string(),
uuid: z.string(),
prefix: z.string(),