diff --git a/src/components/moderator/pages/event/FightEditRow.svelte b/src/components/moderator/pages/event/FightEditRow.svelte
index 0f44410..974a4b1 100644
--- a/src/components/moderator/pages/event/FightEditRow.svelte
+++ b/src/components/moderator/pages/event/FightEditRow.svelte
@@ -1,21 +1,32 @@
-
diff --git a/src/components/moderator/pages/event/columns.ts b/src/components/moderator/pages/event/columns.ts
index 6c074ce..4f4a855 100644
--- a/src/components/moderator/pages/event/columns.ts
+++ b/src/components/moderator/pages/event/columns.ts
@@ -77,4 +77,28 @@ export const columns: ColumnDef
= [
});
},
},
+ {
+ header: "Spielmodus",
+ accessorKey: "spielmodus",
+ },
+ {
+ header: "Map",
+ accessorKey: "map",
+ },
+ {
+ header: "Ergebnis",
+ accessorKey: "ergebnis",
+ cell: ({ row }) => {
+ const fight = row.original;
+ if (fight.ergebnis === 0 && fight.start > Date.now()) {
+ return "Noch nicht gespielt";
+ } else if (fight.ergebnis === 1) {
+ return fight.blueTeam.name + " hat gewonnen";
+ } else if (fight.ergebnis === 2) {
+ return fight.redTeam.name + " hat gewonnen";
+ } else {
+ return "Unentschieden";
+ }
+ },
+ },
];
diff --git a/src/components/repo/event.ts b/src/components/repo/event.ts
index 18d36e7..334f6a3 100644
--- a/src/components/repo/event.ts
+++ b/src/components/repo/event.ts
@@ -128,6 +128,7 @@ export class EventRepo {
.then((value) => z.array(EventFightSchema).parse(value));
}
public async createFight(eventId: string, fight: any): Promise {
+ delete fight.ergebnis;
return await fetchWithToken(this.token, `/events/${eventId}/fights`, {
method: "POST",
body: JSON.stringify(fight),
@@ -153,7 +154,10 @@ export class EventRepo {
CreateEventGroupSchema.parse(group);
return await fetchWithToken(this.token, `/events/${eventId}/groups`, {
method: "POST",
- body: JSON.stringify(group),
+ body: JSON.stringify({
+ name: group.name,
+ type: group.type,
+ }),
headers: { "Content-Type": "application/json" },
})
.then((value) => value.json())
diff --git a/src/components/repo/fight.ts b/src/components/repo/fight.ts
index a3d3a91..7020217 100644
--- a/src/components/repo/fight.ts
+++ b/src/components/repo/fight.ts
@@ -17,12 +17,12 @@
* along with this program. If not, see .
*/
-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 {
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 {
- 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 {
- return await fetchWithToken(this.token, `/fights/${fightId}`, {
+ public async updateFight(eventId: number, fightId: number, fight: UpdateFight): Promise {
+ 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 {
- const res = await fetchWithToken(this.token, `/fights/${fightId}`, {
+ public async deleteFight(eventId: number, fightId: number): Promise {
+ const res = await fetchWithToken(this.token, `/events/${eventId}/fights/${fightId}`, {
method: "DELETE",
});
diff --git a/src/components/types/event.ts b/src/components/types/event.ts
index e3a9b84..919c615 100644
--- a/src/components/types/event.ts
+++ b/src/components/types/event.ts
@@ -45,6 +45,15 @@ export const EventFightSchema = z.object({
export type EventFight = z.infer;
+export const EventFightEditSchema = EventFightSchema.omit({
+ id: true,
+ group: true,
+}).extend({
+ group: z.number().nullable(),
+});
+
+export type EventFightEdit = z.infer;
+
export type ResponseGroups = z.infer;
export const ResponseRelationSchema = z.object({
@@ -111,6 +120,12 @@ export const UpdateEventGroupSchema = z.object({
});
export type UpdateEventGroup = z.infer;
+export const GroupEditSchema = ResponseGroupsSchema.omit({
+ id: true,
+ points: true,
+});
+export type GroupUpdateEdit = z.infer;
+
export const CreateEventRelationSchema = z.object({
fightId: z.number(),
team: z.enum(["RED", "BLUE"]),