Code Cleanup™
This commit is contained in:
@@ -28,15 +28,15 @@ export class AuthRepo {
|
||||
return await fetchWithToken(this.token, "/auth/login", {
|
||||
body: JSON.stringify({
|
||||
username,
|
||||
password
|
||||
password,
|
||||
}),
|
||||
method: "POST",
|
||||
}).then(value => value.json()).then(value => value.token)
|
||||
}).then(value => value.json()).then(value => value.token);
|
||||
}
|
||||
|
||||
public async logout(): Promise<void> {
|
||||
await fetchWithToken(this.token, "/auth/tokens/logout", {
|
||||
method: "POST"
|
||||
method: "POST",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@ import {fetchWithToken, tokenStore} from "./repo.ts";
|
||||
import {derived} from "svelte/store";
|
||||
|
||||
export class DataRepo {
|
||||
constructor(private token: string) {}
|
||||
constructor(private token: string) {
|
||||
}
|
||||
|
||||
public async getServer(): Promise<Server> {
|
||||
return await fetchWithToken(this.token, "/data/server").then(value => value.json()).then(ServerSchema.parse);
|
||||
|
||||
@@ -25,24 +25,25 @@ import type {Dayjs} from "dayjs";
|
||||
import {derived} from "svelte/store";
|
||||
|
||||
export interface CreateEvent {
|
||||
name: string
|
||||
start: Dayjs
|
||||
end: Dayjs
|
||||
name: string;
|
||||
start: Dayjs;
|
||||
end: Dayjs;
|
||||
}
|
||||
|
||||
export interface UpdateEvent {
|
||||
name: string
|
||||
start: Dayjs
|
||||
end: Dayjs
|
||||
deadline: Dayjs
|
||||
maxTeamMembers: number
|
||||
schemType: string | null
|
||||
publicSchemsOnly: boolean
|
||||
spectateSystem: boolean
|
||||
name: string;
|
||||
start: Dayjs;
|
||||
end: Dayjs;
|
||||
deadline: Dayjs;
|
||||
maxTeamMembers: number;
|
||||
schemType: string | null;
|
||||
publicSchemsOnly: boolean;
|
||||
spectateSystem: boolean;
|
||||
}
|
||||
|
||||
export class EventRepo {
|
||||
constructor(private token: string) {}
|
||||
constructor(private token: string) {
|
||||
}
|
||||
|
||||
public async listEvents(): Promise<ShortEvent[]> {
|
||||
return await fetchWithToken(this.token, "/events")
|
||||
@@ -62,7 +63,7 @@ export class EventRepo {
|
||||
body: JSON.stringify({
|
||||
name: event.name,
|
||||
start: +event.start,
|
||||
end: +event.end
|
||||
end: +event.end,
|
||||
}),
|
||||
}).then(value => value.json())
|
||||
.then(SWEventSchema.parse);
|
||||
@@ -79,18 +80,18 @@ export class EventRepo {
|
||||
maxTeamMembers: event.maxTeamMembers,
|
||||
schemType: event.schemType,
|
||||
publicSchemsOnly: event.publicSchemsOnly,
|
||||
spectateSystem: event.spectateSystem
|
||||
spectateSystem: event.spectateSystem,
|
||||
}),
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}).then(value => value.json())
|
||||
.then(SWEventSchema.parse);
|
||||
}
|
||||
|
||||
public async deleteEvent(id: string): Promise<boolean> {
|
||||
const res = await fetchWithToken(this.token, `/events/${id}`, {
|
||||
method: "DELETE"
|
||||
method: "DELETE",
|
||||
});
|
||||
|
||||
return res.ok;
|
||||
|
||||
@@ -25,27 +25,28 @@ import type {Dayjs} from "dayjs";
|
||||
import {derived} from "svelte/store";
|
||||
|
||||
export interface CreateFight {
|
||||
spielmodus: string
|
||||
map: string
|
||||
blueTeam: number
|
||||
redTeam: number
|
||||
start: Dayjs
|
||||
kampfleiter: number | null
|
||||
group: string | null
|
||||
spielmodus: string;
|
||||
map: string;
|
||||
blueTeam: number;
|
||||
redTeam: number;
|
||||
start: Dayjs;
|
||||
kampfleiter: number | null;
|
||||
group: string | null;
|
||||
}
|
||||
|
||||
export interface UpdateFight {
|
||||
spielmodus: string | null
|
||||
map: string | null
|
||||
blueTeam: number | null
|
||||
redTeam: number | null
|
||||
start: Dayjs | null
|
||||
kampfleiter: number | null
|
||||
group: string | null
|
||||
spielmodus: string | null;
|
||||
map: string | null;
|
||||
blueTeam: number | null;
|
||||
redTeam: number | null;
|
||||
start: Dayjs | null;
|
||||
kampfleiter: number | null;
|
||||
group: string | 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`)
|
||||
@@ -54,7 +55,7 @@ export class FightRepo {
|
||||
}
|
||||
|
||||
public async createFight(eventId: number, fight: CreateFight): Promise<EventFight> {
|
||||
return await fetchWithToken(this.token, `/fights`, {
|
||||
return await fetchWithToken(this.token, "/fights", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
event: eventId,
|
||||
@@ -64,10 +65,10 @@ export class FightRepo {
|
||||
redTeam: fight.redTeam,
|
||||
start: +fight.start,
|
||||
kampfleiter: fight.kampfleiter,
|
||||
group: fight.group
|
||||
})
|
||||
group: fight.group,
|
||||
}),
|
||||
}).then(value => value.json())
|
||||
.then(EventFightSchema.parse)
|
||||
.then(EventFightSchema.parse);
|
||||
}
|
||||
|
||||
public async updateFight(fightId: number, fight: UpdateFight): Promise<EventFight> {
|
||||
@@ -80,15 +81,15 @@ export class FightRepo {
|
||||
redTeam: fight.redTeam,
|
||||
start: fight.start?.valueOf(),
|
||||
kampfleiter: fight.kampfleiter,
|
||||
group: fight.group
|
||||
})
|
||||
group: fight.group,
|
||||
}),
|
||||
}).then(value => value.json())
|
||||
.then(EventFightSchema.parse)
|
||||
.then(EventFightSchema.parse);
|
||||
}
|
||||
|
||||
public async deleteFight(fightId: number): Promise<void> {
|
||||
const res = await fetchWithToken(this.token, `/fights/${fightId}`, {
|
||||
method: "DELETE"
|
||||
method: "DELETE",
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
|
||||
@@ -25,7 +25,8 @@ import {z} from "zod";
|
||||
import {derived} from "svelte/store";
|
||||
|
||||
export class PageRepo {
|
||||
constructor(private token: string) {}
|
||||
constructor(private token: string) {
|
||||
}
|
||||
|
||||
public async listPages(branch: string = "master"): Promise<PageList> {
|
||||
return await fetchWithToken(this.token, `/page?branch=${branch}`)
|
||||
@@ -45,8 +46,8 @@ export class PageRepo {
|
||||
method: "PUT",
|
||||
body: JSON.stringify({
|
||||
content: bytesToBase64(new TextEncoder().encode(content)),
|
||||
sha, message
|
||||
})
|
||||
sha, message,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -69,11 +70,17 @@ export class PageRepo {
|
||||
}
|
||||
|
||||
public async merge(branch: string, message: string): Promise<void> {
|
||||
await fetchWithToken(this.token, "/page/branch/merge", {method: "POST", body: JSON.stringify({branch, message})});
|
||||
await fetchWithToken(this.token, "/page/branch/merge", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({branch, message}),
|
||||
});
|
||||
}
|
||||
|
||||
public async deletePage(id: number, message: string, sha: string, branch: string = "master"): Promise<void> {
|
||||
await fetchWithToken(this.token, `/page/${id}?branch=${branch}`, {method: "DELETE", body: JSON.stringify({message, sha})});
|
||||
await fetchWithToken(this.token, `/page/${id}?branch=${branch}`, {
|
||||
method: "DELETE",
|
||||
body: JSON.stringify({message, sha}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@ import {PermsSchema, UserPermsSchema} from "@type/perms.js";
|
||||
import {derived} from "svelte/store";
|
||||
|
||||
export class PermsRepo {
|
||||
constructor(private token: string) {}
|
||||
constructor(private token: string) {
|
||||
}
|
||||
|
||||
public async listPerms(): Promise<Perms> {
|
||||
const res = await fetchWithToken(this.token, "/perms");
|
||||
|
||||
@@ -20,7 +20,12 @@
|
||||
import {writable} from "svelte/store";
|
||||
|
||||
export const fetchWithToken = (token: string, url: string, params: RequestInit = {}) =>
|
||||
fetch(`${import.meta.env.PUBLIC_API_SERVER}${url}`, {...params, headers: {...(token !== "" ? {"Authorization": "Bearer " + (token)}:{}), "Content-Type": "application/json", ...params.headers}})
|
||||
fetch(`${import.meta.env.PUBLIC_API_SERVER}${url}`, {...params,
|
||||
headers: {
|
||||
...(token !== "" ? {"Authorization": "Bearer " + (token)} : {}),
|
||||
"Content-Type": "application/json", ...params.headers,
|
||||
},
|
||||
})
|
||||
.then(value => {
|
||||
if (value.status === 401) {
|
||||
tokenStore.set("");
|
||||
|
||||
@@ -18,12 +18,13 @@
|
||||
*/
|
||||
|
||||
import {fetchWithToken, tokenStore} from "./repo.ts";
|
||||
import type {SchematicCode, SchematicInfo, SchematicList} from "@type/schem.ts";
|
||||
import {SchematicCodeSchema, SchematicInfoSchema, SchematicListSchema} from "@type/schem.ts";
|
||||
import type {SchematicInfo, SchematicList} from "@type/schem.ts";
|
||||
import {SchematicInfoSchema, SchematicListSchema} from "@type/schem.ts";
|
||||
import {derived} from "svelte/store";
|
||||
|
||||
export class SchematicRepo {
|
||||
constructor(private token: string) {}
|
||||
constructor(private token: string) {
|
||||
}
|
||||
|
||||
public async getRootSchematicList(): Promise<SchematicList> {
|
||||
return await fetchWithToken(this.token, "/schem").then(value => value.json()).then(SchematicListSchema.parse);
|
||||
@@ -42,8 +43,8 @@ export class SchematicRepo {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
name,
|
||||
content
|
||||
})
|
||||
content,
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ import {derived} from "svelte/store";
|
||||
|
||||
export class StatsRepo {
|
||||
|
||||
constructor(private token: string) {}
|
||||
constructor(private token: string) {
|
||||
}
|
||||
|
||||
public async getRankings(gamemode: string): Promise<Ranking> {
|
||||
return await fetchWithToken(this.token, `/stats/ranked/${gamemode}`).then(value => value.json()).then(RankingSchema.parse);
|
||||
|
||||
Reference in New Issue
Block a user