Skip to content

Commit e3ae62d

Browse files
committed
Add football EntrySummary which has no results feild
1 parent c77c8a3 commit e3ae62d

File tree

7 files changed

+275
-269
lines changed

7 files changed

+275
-269
lines changed

dotcom-rendering/src/footballTables.ts

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { listParse } from './footballMatches';
33
import type {
44
FEFootballTable,
55
FEGroup,
6+
FEGroupSummary,
67
FELeagueTableEntry,
8+
FELeagueTableEntrySummary,
79
FETeamResult,
810
} from './frontend/feFootballTablesPage';
911
import { error, ok, type Result } from './lib/result';
@@ -26,7 +28,7 @@ type Team = {
2628
url?: string;
2729
};
2830

29-
export type Entry = {
31+
type EntrySummary = {
3032
position: number;
3133
team: Team;
3234
gamesPlayed: number;
@@ -37,6 +39,9 @@ export type Entry = {
3739
goalsAgainst: number;
3840
goalDifference: number;
3941
points: number;
42+
};
43+
44+
export type Entry = EntrySummary & {
4045
results: TeamResult[];
4146
};
4247

@@ -53,6 +58,11 @@ export type FootballTable = {
5358
entries: Entry[];
5459
};
5560

61+
export type FootballTableSummary = {
62+
groupName?: string;
63+
entries: EntrySummary[];
64+
};
65+
5666
export type FootballTableCompetitions = FootballTableCompetition[];
5767

5868
type MissingScore = {
@@ -70,6 +80,14 @@ export const parseTable = (
7080
entries: entries.sort((a, b) => a.position - b.position),
7181
}));
7282

83+
export const parseTableSummary = (
84+
feGroup: FEGroupSummary,
85+
): Result<ParserError, FootballTableSummary> =>
86+
parseEntriesSummaries(feGroup.entries).map((entries) => ({
87+
groupName: feGroup.round.name,
88+
entries: entries.sort((a, b) => a.position - b.position),
89+
}));
90+
7391
const parseTables = listParse(parseTable);
7492

7593
const parseResult = (result: FETeamResult): Result<ParserError, TeamResult> => {
@@ -104,12 +122,12 @@ const parseResult = (result: FETeamResult): Result<ParserError, TeamResult> => {
104122

105123
const parseResults = listParse(parseResult);
106124

107-
const parseEntry = (
108-
feEntry: FELeagueTableEntry,
109-
): Result<ParserError, Entry> => {
125+
const mapBaseEntryFields = (
126+
feEntry: FELeagueTableEntrySummary,
127+
): EntrySummary => {
110128
const { team, teamUrl } = feEntry;
111129

112-
return parseResults(feEntry.results).map((results) => ({
130+
return {
113131
position: team.rank,
114132
team: {
115133
name: cleanTeamName(team.name),
@@ -124,12 +142,28 @@ const parseEntry = (
124142
goalsAgainst: team.total.goalsAgainst,
125143
goalDifference: team.goalDifference,
126144
points: team.points,
145+
};
146+
};
147+
148+
const parseEntry = (
149+
feEntry: FELeagueTableEntry,
150+
): Result<ParserError, Entry> => {
151+
return parseResults(feEntry.results).map((results) => ({
152+
...mapBaseEntryFields(feEntry),
127153
results,
128154
}));
129155
};
130156

131157
const parseEntries = listParse(parseEntry);
132158

159+
const parseEntrySummary = (
160+
feEntry: FELeagueTableEntrySummary,
161+
): Result<ParserError, EntrySummary> => {
162+
return ok(mapBaseEntryFields(feEntry));
163+
};
164+
165+
const parseEntriesSummaries = listParse(parseEntrySummary);
166+
133167
const parseFootballTableCompetition = (
134168
table: FEFootballTable,
135169
): Result<ParserError, FootballTableCompetition> =>

dotcom-rendering/src/frontend/feFootballMatchPage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { FEFootballDataPage } from './feFootballDataPage';
2-
import { type FEGroup } from './feFootballTablesPage';
2+
import { type FEGroupSummary } from './feFootballTablesPage';
33

44
export type FEFootballPlayerEvent = {
55
eventTime: string;
@@ -43,5 +43,5 @@ export type FEFootballMatch = {
4343

4444
export type FEFootballMatchPage = FEFootballDataPage & {
4545
footballMatch: FEFootballMatch;
46-
group?: FEGroup;
46+
group?: FEGroupSummary;
4747
};

dotcom-rendering/src/frontend/feFootballTablesPage.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ export type FERecentResultsPerTeam = {
4242
results: FETeamResult[];
4343
};
4444

45-
export type FELeagueTableEntry = {
45+
export type FELeagueTableEntrySummary = {
4646
stageNumber: string;
4747
round: FERound;
4848
team: FELeagueTeam;
4949
teamUrl?: string;
50+
};
51+
52+
export type FELeagueTableEntry = FELeagueTableEntrySummary & {
5053
results: FETeamResult[];
5154
};
5255

@@ -55,6 +58,11 @@ export type FEGroup = {
5558
entries: FELeagueTableEntry[];
5659
};
5760

61+
export type FEGroupSummary = {
62+
round: FERound;
63+
entries: FELeagueTableEntrySummary[];
64+
};
65+
5866
export type FEFootballTable = {
5967
competition: FECompetitionSummary;
6068
groups: FEGroup[];

dotcom-rendering/src/frontend/schemas/feFootballMatchPage.json

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -459,62 +459,9 @@
459459
},
460460
"teamUrl": {
461461
"type": "string"
462-
},
463-
"results": {
464-
"type": "array",
465-
"items": {
466-
"type": "object",
467-
"properties": {
468-
"matchId": {
469-
"type": "string"
470-
},
471-
"self": {
472-
"type": "object",
473-
"properties": {
474-
"id": {
475-
"type": "string"
476-
},
477-
"name": {
478-
"type": "string"
479-
},
480-
"score": {
481-
"type": "number"
482-
}
483-
},
484-
"required": [
485-
"id",
486-
"name"
487-
]
488-
},
489-
"foe": {
490-
"type": "object",
491-
"properties": {
492-
"id": {
493-
"type": "string"
494-
},
495-
"name": {
496-
"type": "string"
497-
},
498-
"score": {
499-
"type": "number"
500-
}
501-
},
502-
"required": [
503-
"id",
504-
"name"
505-
]
506-
}
507-
},
508-
"required": [
509-
"foe",
510-
"matchId",
511-
"self"
512-
]
513-
}
514462
}
515463
},
516464
"required": [
517-
"results",
518465
"round",
519466
"stageNumber",
520467
"team"

0 commit comments

Comments
 (0)