Files
juwan-frontend/lib/api/players.ts
T
zetaloop b6002f5691 refactor: remove hardcoded display values and unused lib/id.ts
Delete hardcoded marketing stats in auth layout and ¥12,800
placeholder in owner dashboard. Remove lib/id.ts which is no
longer referenced by any module.
2026-05-01 17:33:05 +08:00

42 lines
1.0 KiB
TypeScript

import { isApiError } from "@/lib/errors"
import type { Player } from "@/lib/types"
import { httpJson } from "./http"
type Paginated<T> = {
items: T[] | null
meta: {
total: number
offset: number
limit: number
}
}
export async function listPlayers(): Promise<Player[]> {
const res = await httpJson<Paginated<Player>>("/api/v1/players?offset=0&limit=100", {
cache: "no-store",
})
return res.items ?? []
}
export async function getPlayerById(playerId: string): Promise<Player | undefined> {
try {
return await httpJson<Player>(`/api/v1/players/${encodeURIComponent(playerId)}`, {
cache: "no-store",
})
} catch (error) {
if (error instanceof Error && error.message === "UNAUTHORIZED") {
throw error
}
if (isApiError(error) && error.code === 404) {
return undefined
}
throw error
}
}
export async function listPlayersByShop(shopId: string): Promise<Player[]> {
const players = await listPlayers()
return players.filter((player) => String(player.shopId) === shopId)
}