You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.1 KiB
56 lines
1.1 KiB
import isUndefined from 'lodash/isUndefined'
|
|
|
|
import { callApi } from 'helpers'
|
|
|
|
import { STATS_API_URL } from 'config'
|
|
|
|
export type PlayerParam = {
|
|
clickable: boolean,
|
|
data_type: string,
|
|
id: number,
|
|
lexic: number,
|
|
lexica_short: number | null,
|
|
markers: Array<number> | null,
|
|
name_en: string,
|
|
name_ru: string,
|
|
val: number | null,
|
|
}
|
|
|
|
export type PlayersStats = {
|
|
[playerId: string]: {
|
|
[paramId: string]: PlayerParam,
|
|
},
|
|
}
|
|
|
|
type Response = {
|
|
data?: PlayersStats,
|
|
error?: string,
|
|
message?: string,
|
|
}
|
|
|
|
type GetPlayersStatsArgs = {
|
|
matchId: number,
|
|
second?: number,
|
|
sportName: string,
|
|
teamId: number,
|
|
}
|
|
|
|
export const getPlayersStats = async ({
|
|
matchId,
|
|
second,
|
|
sportName,
|
|
teamId,
|
|
}: GetPlayersStatsArgs) => {
|
|
const config = {
|
|
method: 'GET',
|
|
}
|
|
|
|
const response: Response = await callApi({
|
|
config,
|
|
url: `${STATS_API_URL}/${sportName}/matches/${matchId}/teams/${teamId}/players/stats${isUndefined(second) ? '' : `?second=${second}`}`,
|
|
})
|
|
|
|
if (response.error) Promise.reject(response)
|
|
|
|
return Promise.resolve(response.data || {})
|
|
}
|
|
|