api.ts 1.6 KB
Newer Older
式部 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

export interface Schedule {
    UtcDateTime: string;
    Date: string;
    Time: string;
    TimeZoneDisplayName: string;
}

export const getSchedules = async (): Promise<Schedule[]> => {
    const response = await fetch("/api/fina/competitions/3337/schedule?discipline=");
    return await response.json();
};


export interface Competition {
    Id: string;
    DisciplineName: string;
}

export const getCompetitions = async (): Promise<Competition[]> => {
    const response = await fetch("/api/fina/competitions/3337/events");
    const data = await response.json() as { Sports: [{ DisciplineList: Competition[] }] };
    return data.Sports?.[0]?.DisciplineList;
};


export const getResults = async (hash: string)=> {
    const response = await fetch(`/api/fina/events/${hash}`);
    return await response.json();
};


export const getCountryFlag = (country: string): string => {
    return `https://www.worldaquatics.com/resources/v2.11.4/i/elements/flags/${country.toLowerCase()}.png`;
};


export const getAthletePhoto = async (...id: string[]) => {
    const query = id.map(i => `"FINA_ATHLETE:${i}"`).join(" or ");
    const response = await fetch(`/api/content/fina/photo/en/?pageSize=100&tagNames=athlete-image&referenceExpression=${query}`);
    const data = await response.json();
    return data.content;
};

export const getMedalTable = async () => {
    const response = await fetch("/api/fina/competitions/3337/medals");
    const data = await response.json() as { Medals: { SportMedals: { Country: string; Gold: number; Silver: number; Bronze: number; Total: number }[] } };
    return data.Medals.SportMedals?.[0];
};