Cleanup and enhance types

This commit is contained in:
Cedric Finance 2022-08-28 19:50:00 +02:00
parent 3d4041cf16
commit c4643ae642
2 changed files with 9 additions and 17 deletions

View file

@ -39,8 +39,8 @@ export class BoardGameGeekAPI extends APIModel {
let ret: MediaTypeModel[] = [];
for (const boardgame of Array.from(response.querySelectorAll("boardgame"))) {
const id = boardgame.attributes.getNamedItem("objectid").value;
const title = boardgame.querySelector("name").textContent;
const id = boardgame.attributes.getNamedItem("objectid")!.value;
const title = boardgame.querySelector("name")!.textContent!;
const year = boardgame.querySelector("yearpublished")?.textContent ?? "";
ret.push(new BoardGameModel({
@ -71,12 +71,12 @@ export class BoardGameGeekAPI extends APIModel {
const response = new window.DOMParser().parseFromString(data, "text/xml")
debugLog(response);
const boardgame = response.querySelector("boardgame");
const title = boardgame.querySelector("name").textContent;
const year = boardgame.querySelector("yearpublished").textContent;
const image = boardgame.querySelector("image").textContent;
const onlineRating = Number.parseFloat(boardgame.querySelector("statistics ratings average").textContent);
const genres = Array.from(boardgame.querySelectorAll("boardgamecategory")).map(n => n.textContent);
const boardgame = response.querySelector("boardgame")!;
const title = boardgame.querySelector("name")!.textContent!;
const year = boardgame.querySelector("yearpublished")?.textContent ?? "";
const image = boardgame.querySelector("image")?.textContent ?? undefined;
const onlineRating = Number.parseFloat(boardgame.querySelector("statistics ratings average")?.textContent ?? "");
const genres = Array.from(boardgame.querySelectorAll("boardgamecategory")).map(n => n!.textContent!);
const model = new BoardGameModel({
type: MediaType.BoardGame,

View file

@ -4,17 +4,9 @@ import {MediaType} from '../utils/MediaType';
export class BoardGameModel extends MediaTypeModel {
type: string;
title: string;
englishTitle: string;
year: string;
dataSource: string;
url: string;
id: string;
genres: string[];
onlineRating: number;
image: string;
image?: string;
released: boolean;