Skip to content

Commit c4643ae

Browse files
committed
Cleanup and enhance types
1 parent 3d4041c commit c4643ae

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

src/api/apis/BoardGameGeekAPI.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export class BoardGameGeekAPI extends APIModel {
3939
let ret: MediaTypeModel[] = [];
4040

4141
for (const boardgame of Array.from(response.querySelectorAll("boardgame"))) {
42-
const id = boardgame.attributes.getNamedItem("objectid").value;
43-
const title = boardgame.querySelector("name").textContent;
42+
const id = boardgame.attributes.getNamedItem("objectid")!.value;
43+
const title = boardgame.querySelector("name")!.textContent!;
4444
const year = boardgame.querySelector("yearpublished")?.textContent ?? "";
4545

4646
ret.push(new BoardGameModel({
@@ -71,12 +71,12 @@ export class BoardGameGeekAPI extends APIModel {
7171
const response = new window.DOMParser().parseFromString(data, "text/xml")
7272
debugLog(response);
7373

74-
const boardgame = response.querySelector("boardgame");
75-
const title = boardgame.querySelector("name").textContent;
76-
const year = boardgame.querySelector("yearpublished").textContent;
77-
const image = boardgame.querySelector("image").textContent;
78-
const onlineRating = Number.parseFloat(boardgame.querySelector("statistics ratings average").textContent);
79-
const genres = Array.from(boardgame.querySelectorAll("boardgamecategory")).map(n => n.textContent);
74+
const boardgame = response.querySelector("boardgame")!;
75+
const title = boardgame.querySelector("name")!.textContent!;
76+
const year = boardgame.querySelector("yearpublished")?.textContent ?? "";
77+
const image = boardgame.querySelector("image")?.textContent ?? undefined;
78+
const onlineRating = Number.parseFloat(boardgame.querySelector("statistics ratings average")?.textContent ?? "");
79+
const genres = Array.from(boardgame.querySelectorAll("boardgamecategory")).map(n => n!.textContent!);
8080

8181
const model = new BoardGameModel({
8282
type: MediaType.BoardGame,

src/models/BoardGameModel.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,9 @@ import {MediaType} from '../utils/MediaType';
44

55

66
export class BoardGameModel extends MediaTypeModel {
7-
type: string;
8-
title: string;
9-
englishTitle: string;
10-
year: string;
11-
dataSource: string;
12-
url: string;
13-
id: string;
14-
157
genres: string[];
168
onlineRating: number;
17-
image: string;
9+
image?: string;
1810

1911
released: boolean;
2012

0 commit comments

Comments
 (0)