feat: Enhance event management with FightEdit and GroupEdit components, including improved data handling and new functionalities

This commit is contained in:
2025-05-22 19:41:49 +02:00
parent 1da279bb24
commit 5277c9a3fc
9 changed files with 371 additions and 112 deletions

View File

@@ -17,12 +17,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import type {EventFight} from "@type/event.js";
import {fetchWithToken, tokenStore} from "./repo";
import {z} from "zod";
import {EventFightSchema} from "@type/event.js";
import type {Dayjs} from "dayjs";
import {derived} from "svelte/store";
import type { EventFight } from "@type/event.js";
import { fetchWithToken, tokenStore } from "./repo";
import { z } from "zod";
import { EventFightSchema } from "@type/event.js";
import type { Dayjs } from "dayjs";
import { derived } from "svelte/store";
export interface CreateFight {
spielmodus: string;
@@ -39,23 +39,22 @@ export interface UpdateFight {
map: string | null;
blueTeam: number | null;
redTeam: number | null;
start: Dayjs | null;
start: number | null;
spectatePort: number | null;
group: string | null;
group: number | null;
}
export class FightRepo {
constructor(private token: string) {
}
constructor(private token: string) {}
public async listFights(eventId: number): Promise<EventFight[]> {
return await fetchWithToken(this.token, `/events/${eventId}/fights`)
.then(value => value.json())
.then(value => z.array(EventFightSchema).parse(value));
.then((value) => value.json())
.then((value) => z.array(EventFightSchema).parse(value));
}
public async createFight(eventId: number, fight: CreateFight): Promise<EventFight> {
return await fetchWithToken(this.token, "/fights", {
return await fetchWithToken(this.token, `/events/${eventId}/fights`, {
method: "POST",
body: JSON.stringify({
event: eventId,
@@ -67,28 +66,25 @@ export class FightRepo {
spectatePort: fight.spectatePort,
group: fight.group,
}),
}).then(value => value.json())
})
.then((value) => value.json())
.then(EventFightSchema.parse);
}
public async updateFight(fightId: number, fight: UpdateFight): Promise<EventFight> {
return await fetchWithToken(this.token, `/fights/${fightId}`, {
public async updateFight(eventId: number, fightId: number, fight: UpdateFight): Promise<EventFight> {
return await fetchWithToken(this.token, `/events/${eventId}/fights/${fightId}`, {
method: "PUT",
body: JSON.stringify({
spielmodus: fight.spielmodus,
map: fight.map,
blueTeam: fight.blueTeam,
redTeam: fight.redTeam,
...fight,
start: fight.start?.valueOf(),
spectatePort: fight.spectatePort,
group: fight.group,
}),
}).then(value => value.json())
})
.then((value) => value.json())
.then(EventFightSchema.parse);
}
public async deleteFight(fightId: number): Promise<void> {
const res = await fetchWithToken(this.token, `/fights/${fightId}`, {
public async deleteFight(eventId: number, fightId: number): Promise<void> {
const res = await fetchWithToken(this.token, `/events/${eventId}/fights/${fightId}`, {
method: "DELETE",
});