62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import {apiClient} from "@/lib/api/client";
|
|
|
|
const PICKS_ENDPOINTS = {
|
|
getFixtures: process.env.NEXT_PUBLIC_PICKS_FIXTURES_PATH ?? '/api/fixtures',
|
|
getPicks: process.env.NEXT_PUBLIC_PICKS_PATH ?? '/api/picks',
|
|
savePick: process.env.NEXT_PUBLIC_PICKS_PATH ?? '/api/picks',
|
|
};
|
|
|
|
export type PickSelection = 'home' | 'draw' | 'away';
|
|
|
|
export type Fixture = {
|
|
id: number
|
|
home_team: string
|
|
away_team: string
|
|
stage: string
|
|
status: string
|
|
venue: string
|
|
starts_at: number
|
|
home_short_name: string
|
|
away_short_name: string
|
|
}
|
|
|
|
export type FixturesResponse = {
|
|
fixtures: Fixture[]
|
|
}
|
|
|
|
export type Pick = {
|
|
id: number
|
|
match_id: number
|
|
selection: PickSelection
|
|
points_awarded: number
|
|
submitted_at: string | null
|
|
graded_at: string | null
|
|
}
|
|
|
|
export type PicksResponse = {
|
|
picks: Pick[]
|
|
}
|
|
|
|
export type SavePickPayload = {
|
|
match_id: number
|
|
selection: PickSelection
|
|
}
|
|
|
|
export type SavePickResponse = {
|
|
pick: Pick
|
|
}
|
|
|
|
export const picksClient = {
|
|
async getFixtures(signal?: AbortSignal) {
|
|
return apiClient.get<FixturesResponse>(PICKS_ENDPOINTS.getFixtures, {signal})
|
|
},
|
|
|
|
async getPicks(signal?: AbortSignal) {
|
|
return apiClient.get<PicksResponse>(PICKS_ENDPOINTS.getPicks, {signal})
|
|
},
|
|
|
|
async savePick(payload: SavePickPayload) {
|
|
await apiClient.ensureCsrfCookie();
|
|
return apiClient.post<SavePickResponse>(PICKS_ENDPOINTS.savePick, payload);
|
|
}
|
|
}
|