Refactor stores and types for improved data handling and schema definitions
All checks were successful
SteamWarCI Build successful
All checks were successful
SteamWarCI Build successful
- Consolidated player fetching logic in stores.ts to utilize dataRepo. - Introduced teams fetching logic in stores.ts. - Updated permissions structure in stores.ts for better clarity. - Enhanced data schemas in data.ts with new ResponseUser and ResponseTeam schemas. - Expanded event-related schemas in event.ts to include groups, relations, and event creation/update structures. - Improved code formatting for consistency and readability across files.
This commit is contained in:
@@ -17,26 +17,38 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import type {Player, Server} from "@type/data.ts";
|
||||
import {PlayerSchema, ServerSchema} from "@type/data.ts";
|
||||
import {fetchWithToken, tokenStore} from "./repo.ts";
|
||||
import {derived, get} from "svelte/store";
|
||||
import type { Player, Server } from "@type/data.ts";
|
||||
import { PlayerSchema, ServerSchema } from "@type/data.ts";
|
||||
import { fetchWithToken, tokenStore } from "./repo.ts";
|
||||
import { derived, get } from "svelte/store";
|
||||
import { TeamSchema, type Team } from "@components/types/team.ts";
|
||||
|
||||
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);
|
||||
return await fetchWithToken(this.token, "/data/server")
|
||||
.then((value) => value.json())
|
||||
.then(ServerSchema.parse);
|
||||
}
|
||||
|
||||
public async getMe(): Promise<Player> {
|
||||
return await fetchWithToken(this.token, "/data/me").then(value => value.json()).then(PlayerSchema.parse);
|
||||
return await fetchWithToken(this.token, "/data/me")
|
||||
.then((value) => value.json())
|
||||
.then(PlayerSchema.parse);
|
||||
}
|
||||
|
||||
public async getPlayers(): Promise<Player[]> {
|
||||
return await fetchWithToken(get(tokenStore), "/data/admin/users").then(value => value.json()).then(PlayerSchema.array().parse);
|
||||
return await fetchWithToken(get(tokenStore), "/data/admin/users")
|
||||
.then((value) => value.json())
|
||||
.then(PlayerSchema.array().parse);
|
||||
}
|
||||
|
||||
public async getTeams(): Promise<Team[]> {
|
||||
return await fetchWithToken(get(tokenStore), "/data/admin/teams")
|
||||
.then((value) => value.json())
|
||||
.then(TeamSchema.array().parse);
|
||||
}
|
||||
}
|
||||
|
||||
export const dataRepo = derived(tokenStore, ($token) => new DataRepo($token));
|
||||
export const dataRepo = derived(tokenStore, ($token) => new DataRepo($token));
|
||||
|
||||
Reference in New Issue
Block a user