Ott 461 matches request proc change (#165)
* refactor(#461): matches request split into 4 different funcs (#161) Co-authored-by: mirlan.maksitaliev <mirlan.maksitaliev@instatsport.com> * refactor(#461): connected profile spec. matches request functions (#162) Co-authored-by: mirlan.maksitaliev <mirlan.maksitaliev@instatsport.com> * Ott 461 matches request proc change part 3 (#163) * refactor(#461): simplified matches requests a bit * refactor(#461): renamed matches types * refactor(#461): converted flat team to object Co-authored-by: mirlan.maksitaliev <mirlan.maksitaliev@instatsport.com> * refactor(#461): show sport and tournament names on specific profiles (#164) Co-authored-by: mirlan.maksitaliev <mirlan.maksitaliev@instatsport.com>keep-around/af30b88d367751c9e05a735e4a0467a96238ef47
parent
2994726834
commit
d767f266f2
@ -1,52 +0,0 @@ |
||||
import map from 'lodash/map' |
||||
import flatten from 'lodash/flatten' |
||||
import pipe from 'lodash/fp/pipe' |
||||
import fpMap from 'lodash/fp/map' |
||||
|
||||
import format from 'date-fns/format' |
||||
|
||||
import type { Content } from 'requests' |
||||
import { ProfileTypes } from 'config' |
||||
import { getProfileLogo, getSportLexic } from 'helpers' |
||||
|
||||
type Name = 'name_rus' | 'name_eng' |
||||
|
||||
const prepareMatch = ({ |
||||
matches: matchesList, |
||||
sport, |
||||
...rest |
||||
}: Content, suffix: string) => map(matchesList, ({ |
||||
date, |
||||
id, |
||||
stream_status, |
||||
team1, |
||||
team2, |
||||
}) => ({ |
||||
date: format(new Date(date), 'dd.MM.yy'), |
||||
id, |
||||
preview: '/images/preview.png', |
||||
sportName: getSportLexic(sport), |
||||
sportType: sport, |
||||
streamStatus: stream_status, |
||||
team1Logo: getProfileLogo({ |
||||
id: team1.id, |
||||
profileType: ProfileTypes.TEAMS, |
||||
sportType: sport, |
||||
}), |
||||
team1Name: team1[`name_${suffix}` as Name], |
||||
team1Score: team1.score, |
||||
team2Logo: getProfileLogo({ |
||||
id: team2.id, |
||||
profileType: ProfileTypes.TEAMS, |
||||
sportType: sport, |
||||
}), |
||||
team2Name: team2[`name_${suffix}` as Name], |
||||
team2Score: team2.score, |
||||
time: format(new Date(date), 'HH:mm'), |
||||
tournamentName: rest[`name_${suffix}` as Name], |
||||
})) |
||||
|
||||
export const prepareMatches = (content: Array<Content>, suffix: string) => pipe( |
||||
fpMap((items: Content) => prepareMatch(items, suffix)), |
||||
flatten, |
||||
)(content) |
||||
@ -0,0 +1,15 @@ |
||||
import map from 'lodash/map' |
||||
|
||||
import type { MatchesBySection, Matches } from 'requests' |
||||
import { SportTypes } from 'config' |
||||
|
||||
const addSportTypeToMatches = (matches: Matches, sport: SportTypes) => ( |
||||
map(matches, (match) => ({ ...match, sport })) |
||||
) |
||||
|
||||
export const addSportType = (matches: MatchesBySection, sport: SportTypes) => ({ |
||||
...matches, |
||||
broadcast: addSportTypeToMatches(matches.broadcast, sport), |
||||
features: addSportTypeToMatches(matches.features, sport), |
||||
highlights: addSportTypeToMatches(matches.highlights, sport), |
||||
}) |
||||
@ -0,0 +1,63 @@ |
||||
import map from 'lodash/map' |
||||
|
||||
import format from 'date-fns/format' |
||||
|
||||
import type { Match, Team } from 'requests' |
||||
import { ProfileTypes, SportTypes } from 'config' |
||||
import { getProfileLogo, getSportLexic } from 'helpers' |
||||
|
||||
type Name = 'name_rus' | 'name_eng' |
||||
|
||||
type Args = { |
||||
sport: SportTypes, |
||||
suffix: string, |
||||
team: Team, |
||||
} |
||||
|
||||
const prepareTeam = ({ |
||||
sport, |
||||
suffix, |
||||
team, |
||||
}: Args) => ({ |
||||
logo: getProfileLogo({ |
||||
id: team.id, |
||||
profileType: ProfileTypes.TEAMS, |
||||
sportType: sport, |
||||
}), |
||||
name: team[`name_${suffix}` as Name], |
||||
score: team.score, |
||||
}) |
||||
|
||||
const prepareMatch = ({ |
||||
date, |
||||
id, |
||||
sport, |
||||
stream_status, |
||||
team1, |
||||
team2, |
||||
tournament, |
||||
}: Match, suffix: string) => ({ |
||||
date: format(new Date(date), 'dd.MM.yy'), |
||||
id, |
||||
preview: '/images/preview.png', |
||||
sportName: getSportLexic(sport), |
||||
sportType: sport, |
||||
streamStatus: stream_status, |
||||
team1: prepareTeam({ |
||||
sport, |
||||
suffix, |
||||
team: team1, |
||||
}), |
||||
team2: prepareTeam({ |
||||
sport, |
||||
suffix, |
||||
team: team2, |
||||
}), |
||||
time: format(new Date(date), 'HH:mm'), |
||||
tournamentName: tournament?.[`name_${suffix}` as Name], |
||||
}) |
||||
|
||||
export const prepareMatches = (matches: Array<Match>, suffix: string) => map( |
||||
matches, |
||||
(match: Match) => prepareMatch(match, suffix), |
||||
) |
||||
@ -1,118 +0,0 @@ |
||||
import { |
||||
DATA_URL, |
||||
PROCEDURES, |
||||
SportTypes, |
||||
} from 'config' |
||||
import { callApi, getResponseData } from 'helpers' |
||||
|
||||
import { MatchStatuses } from 'features/HeaderFilters' |
||||
|
||||
const proc = PROCEDURES.get_matches |
||||
|
||||
type Data = { |
||||
is_video_sections: boolean, |
||||
video_content: VideoContent, |
||||
} |
||||
|
||||
type VideoContent = { |
||||
broadcast: Items, |
||||
features: Items, |
||||
highlights: Items, |
||||
show: boolean, |
||||
} |
||||
|
||||
type Items = { |
||||
content: Array<Content> | null, |
||||
name: string, |
||||
} |
||||
|
||||
export type Content = { |
||||
id: number, |
||||
matches: Array<Match>, |
||||
name_eng: string, |
||||
name_rus: string, |
||||
sport: SportTypes, |
||||
} |
||||
|
||||
type Match = { |
||||
date: string, |
||||
has_video: boolean, |
||||
id: number, |
||||
round_id: number | null, |
||||
stream_status: MatchStatuses, |
||||
team1: Team, |
||||
team2: Team, |
||||
} |
||||
|
||||
type Team = { |
||||
id: number, |
||||
name_eng: string, |
||||
name_rus: string, |
||||
score: number, |
||||
} |
||||
|
||||
type Args = { |
||||
date?: string, |
||||
limit?: number, |
||||
matchStatus?: MatchStatuses | null, |
||||
offset?: number, |
||||
playerId?: number | null, |
||||
sportType: SportTypes | null, |
||||
teamId?: number | null, |
||||
tournamentId?: number | null, |
||||
} |
||||
|
||||
export type Matches = { |
||||
broadcast: Array<Content>, |
||||
features: Array<Content>, |
||||
hasNextPage?: boolean, |
||||
highlights: Array<Content>, |
||||
isVideoSections: boolean, |
||||
} |
||||
|
||||
export const getMatches = async ({ |
||||
date, |
||||
limit, |
||||
matchStatus, |
||||
offset, |
||||
playerId, |
||||
sportType, |
||||
teamId, |
||||
tournamentId, |
||||
}: Args) => { |
||||
const config = { |
||||
body: { |
||||
params: { |
||||
_p_date: date, |
||||
_p_limit: limit, |
||||
_p_offset: offset, |
||||
_p_player_id: playerId || null, |
||||
_p_sport: sportType, |
||||
_p_stream_status: matchStatus, |
||||
_p_team_id: teamId || null, |
||||
_p_tournament_id: tournamentId || null, |
||||
}, |
||||
proc, |
||||
}, |
||||
} |
||||
|
||||
const data: Data = await callApi({ |
||||
config, |
||||
url: DATA_URL, |
||||
}).then(getResponseData(proc)) |
||||
|
||||
const { |
||||
broadcast, |
||||
features, |
||||
highlights, |
||||
show, |
||||
} = data.video_content |
||||
|
||||
return { |
||||
broadcast: broadcast.content || [], |
||||
features: features.content || [], |
||||
hasNextPage: Boolean(show), |
||||
highlights: highlights.content || [], |
||||
isVideoSections: data.is_video_sections, |
||||
} |
||||
} |
||||
@ -0,0 +1,42 @@ |
||||
import { PROCEDURES, SportTypes } from 'config' |
||||
|
||||
import { MatchStatuses } from 'features/HeaderFilters' |
||||
|
||||
import type { MatchesBySection } from './types' |
||||
import { requestMatches } from './request' |
||||
|
||||
const proc = PROCEDURES.get_matches_tmp |
||||
|
||||
type Args = { |
||||
date: string, |
||||
limit: number, |
||||
matchStatus: MatchStatuses | null, |
||||
offset: number, |
||||
sportType: SportTypes | null, |
||||
tournamentId: number | null, |
||||
} |
||||
|
||||
export const getHomeMatches = async ({ |
||||
date, |
||||
limit, |
||||
matchStatus, |
||||
offset, |
||||
sportType, |
||||
tournamentId, |
||||
}: Args): Promise<MatchesBySection> => { |
||||
const config = { |
||||
body: { |
||||
params: { |
||||
_p_date: date, |
||||
_p_limit: limit, |
||||
_p_offset: offset, |
||||
_p_sport: sportType, |
||||
_p_stream_status: matchStatus, |
||||
_p_tournament_id: tournamentId, |
||||
}, |
||||
proc, |
||||
}, |
||||
} |
||||
|
||||
return requestMatches(config) |
||||
} |
||||
@ -0,0 +1,34 @@ |
||||
import { PROCEDURES, SportTypes } from 'config' |
||||
|
||||
import type { MatchesBySection } from './types' |
||||
import { requestMatches } from './request' |
||||
|
||||
const proc = PROCEDURES.get_player_matches |
||||
|
||||
type Args = { |
||||
limit: number, |
||||
offset: number, |
||||
playerId: number, |
||||
sportType: SportTypes, |
||||
} |
||||
|
||||
export const getPlayerMatches = async ({ |
||||
limit, |
||||
offset, |
||||
playerId, |
||||
sportType, |
||||
}: Args): Promise<MatchesBySection> => { |
||||
const config = { |
||||
body: { |
||||
params: { |
||||
_p_limit: limit, |
||||
_p_offset: offset, |
||||
_p_player_id: playerId, |
||||
_p_sport: sportType, |
||||
}, |
||||
proc, |
||||
}, |
||||
} |
||||
|
||||
return requestMatches(config) |
||||
} |
||||
@ -0,0 +1,34 @@ |
||||
import { PROCEDURES, SportTypes } from 'config' |
||||
|
||||
import type { MatchesBySection } from './types' |
||||
import { requestMatches } from './request' |
||||
|
||||
const proc = PROCEDURES.get_team_matches |
||||
|
||||
type Args = { |
||||
limit: number, |
||||
offset: number, |
||||
sportType: SportTypes, |
||||
teamId: number, |
||||
} |
||||
|
||||
export const getTeamMatches = async ({ |
||||
limit, |
||||
offset, |
||||
sportType, |
||||
teamId, |
||||
}: Args): Promise<MatchesBySection> => { |
||||
const config = { |
||||
body: { |
||||
params: { |
||||
_p_limit: limit, |
||||
_p_offset: offset, |
||||
_p_sport: sportType, |
||||
_p_team_id: teamId, |
||||
}, |
||||
proc, |
||||
}, |
||||
} |
||||
|
||||
return requestMatches(config) |
||||
} |
||||
@ -0,0 +1,34 @@ |
||||
import { PROCEDURES, SportTypes } from 'config' |
||||
|
||||
import type { MatchesBySection } from './types' |
||||
import { requestMatches } from './request' |
||||
|
||||
const proc = PROCEDURES.get_tournament_matches |
||||
|
||||
type Args = { |
||||
limit: number, |
||||
offset: number, |
||||
sportType: SportTypes, |
||||
tournamentId: number, |
||||
} |
||||
|
||||
export const getTournamentMatches = async ({ |
||||
limit, |
||||
offset, |
||||
sportType, |
||||
tournamentId, |
||||
}: Args): Promise<MatchesBySection> => { |
||||
const config = { |
||||
body: { |
||||
params: { |
||||
_p_limit: limit, |
||||
_p_offset: offset, |
||||
_p_sport: sportType, |
||||
_p_tournament_id: tournamentId, |
||||
}, |
||||
proc, |
||||
}, |
||||
} |
||||
|
||||
return requestMatches(config) |
||||
} |
||||
@ -0,0 +1,5 @@ |
||||
export * from './types' |
||||
export * from './getHomeMatches' |
||||
export * from './getTeamMatches' |
||||
export * from './getPlayerMatches' |
||||
export * from './getTournamentMatches' |
||||
@ -0,0 +1,29 @@ |
||||
import { DATA_URL } from 'config' |
||||
import { callApi, getResponseData } from 'helpers' |
||||
|
||||
import type { MatchesResponse, MatchesBySection } from './types' |
||||
|
||||
type Config = { |
||||
body: { |
||||
proc: string, |
||||
}, |
||||
} |
||||
|
||||
export const requestMatches = async (config: Config): Promise<MatchesBySection> => { |
||||
const { |
||||
is_video_sections, |
||||
show, |
||||
video_content: data, |
||||
}: MatchesResponse = await callApi({ |
||||
config, |
||||
url: DATA_URL, |
||||
}).then(getResponseData(config.body.proc)) |
||||
|
||||
return { |
||||
broadcast: data.broadcast || [], |
||||
features: data.features || [], |
||||
hasNextPage: Boolean(show), |
||||
highlights: data.highlights || [], |
||||
isVideoSections: Boolean(is_video_sections), |
||||
} |
||||
} |
||||
@ -0,0 +1,50 @@ |
||||
import { SportTypes } from 'config' |
||||
|
||||
import { MatchStatuses } from 'features/HeaderFilters' |
||||
|
||||
type Tournament = { |
||||
id: number, |
||||
name_eng: string, |
||||
name_rus: string, |
||||
} |
||||
|
||||
export type Team = { |
||||
id: number, |
||||
name_eng: string, |
||||
name_rus: string, |
||||
score: number, |
||||
} |
||||
|
||||
export type Match = { |
||||
date: string, |
||||
has_video: boolean, |
||||
id: number, |
||||
round_id: number | null, |
||||
sport: SportTypes, |
||||
stream_status: MatchStatuses, |
||||
team1: Team, |
||||
team2: Team, |
||||
tournament: Tournament, |
||||
} |
||||
|
||||
export type Matches = Array<Match> |
||||
|
||||
type VideoContent = { |
||||
broadcast: Matches, |
||||
features: Matches, |
||||
highlights: Matches, |
||||
} |
||||
|
||||
export type MatchesResponse = { |
||||
is_video_sections: boolean | null, |
||||
show: boolean, |
||||
video_content: VideoContent, |
||||
} |
||||
|
||||
export type MatchesBySection = { |
||||
broadcast: Matches, |
||||
features: Matches, |
||||
hasNextPage: boolean, |
||||
highlights: Matches, |
||||
isVideoSections: boolean, |
||||
} |
||||
Loading…
Reference in new issue