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.
63 lines
1.2 KiB
63 lines
1.2 KiB
import reduce from 'lodash/reduce'
|
|
import map from 'lodash/map'
|
|
|
|
import {
|
|
DATA_URL,
|
|
PROCEDURES,
|
|
SportTypes,
|
|
} from 'config'
|
|
import { callApi } from 'helpers'
|
|
|
|
const proc = PROCEDURES.get_tournament_list
|
|
|
|
type Country = {
|
|
id: number,
|
|
name_eng: string,
|
|
name_rus: string,
|
|
}
|
|
|
|
export type Tournament = {
|
|
country: Country,
|
|
gender: number | null,
|
|
id: number,
|
|
name_eng: string,
|
|
name_rus: string,
|
|
short_name_eng: string | null,
|
|
short_name_rus: string | null,
|
|
sport: SportTypes,
|
|
tournament_type: number,
|
|
}
|
|
|
|
export type Tournaments = Array<Tournament>
|
|
|
|
const getSportTournaments = (sportId: SportTypes): Promise<Tournaments> => {
|
|
const config = {
|
|
body: {
|
|
params: {
|
|
_p_sport: sportId,
|
|
},
|
|
proc,
|
|
},
|
|
}
|
|
|
|
return callApi({
|
|
config,
|
|
url: DATA_URL,
|
|
})
|
|
}
|
|
|
|
export type TournamentsBySports = Partial<Record<SportTypes, Tournaments>>
|
|
|
|
export const getTournamentsBySports = async (sportIds: Array<SportTypes>) => {
|
|
const responses = await Promise.all(map(sportIds, getSportTournaments))
|
|
const tournamentsBySports = reduce(
|
|
responses,
|
|
(acc, curr) => {
|
|
const { sport } = curr[0]
|
|
acc[sport] = curr
|
|
return acc
|
|
},
|
|
{} as TournamentsBySports,
|
|
)
|
|
return tournamentsBySports
|
|
}
|
|
|