添加交锋往绩接口

This commit is contained in:
xianyi
2026-01-15 15:08:45 +08:00
parent cff077c5f7
commit 8513f10a10
3 changed files with 85 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ import {
ApiListResponse,
ApiResponse,
Country,
H2HData,
League,
LiveScoreMatch,
Match,
@@ -255,3 +256,58 @@ export const fetchSearch = async (
throw error;
}
};
// 获取两队/两球员之间的历史对战数据
export const fetchH2H = async (
sportId: number,
options: {
firstTeamId?: number;
secondTeamId?: number;
firstPlayerId?: number;
secondPlayerId?: number;
timezone?: string;
}
): Promise<H2HData> => {
try {
const params: {
sport_id: number;
first_team_id?: number;
second_team_id?: number;
first_player_id?: number;
second_player_id?: number;
timezone?: string;
} = {
sport_id: sportId,
};
if (options.firstTeamId) {
params.first_team_id = options.firstTeamId;
}
if (options.secondTeamId) {
params.second_team_id = options.secondTeamId;
}
if (options.firstPlayerId) {
params.first_player_id = options.firstPlayerId;
}
if (options.secondPlayerId) {
params.second_player_id = options.secondPlayerId;
}
if (options.timezone) {
params.timezone = options.timezone;
}
const response = await apiClient.get<ApiResponse<H2HData>>(
API_ENDPOINTS.H2H,
{ params }
);
if (response.data.code === 0) {
return response.data.data;
}
throw new Error(response.data.message);
} catch (error) {
console.error("Fetch H2H error:", error);
throw error;
}
};