Cleanup and enhance types
This commit is contained in:
parent
3d4041cf16
commit
c4643ae642
2 changed files with 9 additions and 17 deletions
|
|
@ -39,8 +39,8 @@ export class BoardGameGeekAPI extends APIModel {
|
||||||
let ret: MediaTypeModel[] = [];
|
let ret: MediaTypeModel[] = [];
|
||||||
|
|
||||||
for (const boardgame of Array.from(response.querySelectorAll("boardgame"))) {
|
for (const boardgame of Array.from(response.querySelectorAll("boardgame"))) {
|
||||||
const id = boardgame.attributes.getNamedItem("objectid").value;
|
const id = boardgame.attributes.getNamedItem("objectid")!.value;
|
||||||
const title = boardgame.querySelector("name").textContent;
|
const title = boardgame.querySelector("name")!.textContent!;
|
||||||
const year = boardgame.querySelector("yearpublished")?.textContent ?? "";
|
const year = boardgame.querySelector("yearpublished")?.textContent ?? "";
|
||||||
|
|
||||||
ret.push(new BoardGameModel({
|
ret.push(new BoardGameModel({
|
||||||
|
|
@ -71,12 +71,12 @@ export class BoardGameGeekAPI extends APIModel {
|
||||||
const response = new window.DOMParser().parseFromString(data, "text/xml")
|
const response = new window.DOMParser().parseFromString(data, "text/xml")
|
||||||
debugLog(response);
|
debugLog(response);
|
||||||
|
|
||||||
const boardgame = response.querySelector("boardgame");
|
const boardgame = response.querySelector("boardgame")!;
|
||||||
const title = boardgame.querySelector("name").textContent;
|
const title = boardgame.querySelector("name")!.textContent!;
|
||||||
const year = boardgame.querySelector("yearpublished").textContent;
|
const year = boardgame.querySelector("yearpublished")?.textContent ?? "";
|
||||||
const image = boardgame.querySelector("image").textContent;
|
const image = boardgame.querySelector("image")?.textContent ?? undefined;
|
||||||
const onlineRating = Number.parseFloat(boardgame.querySelector("statistics ratings average").textContent);
|
const onlineRating = Number.parseFloat(boardgame.querySelector("statistics ratings average")?.textContent ?? "");
|
||||||
const genres = Array.from(boardgame.querySelectorAll("boardgamecategory")).map(n => n.textContent);
|
const genres = Array.from(boardgame.querySelectorAll("boardgamecategory")).map(n => n!.textContent!);
|
||||||
|
|
||||||
const model = new BoardGameModel({
|
const model = new BoardGameModel({
|
||||||
type: MediaType.BoardGame,
|
type: MediaType.BoardGame,
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,9 @@ import {MediaType} from '../utils/MediaType';
|
||||||
|
|
||||||
|
|
||||||
export class BoardGameModel extends MediaTypeModel {
|
export class BoardGameModel extends MediaTypeModel {
|
||||||
type: string;
|
|
||||||
title: string;
|
|
||||||
englishTitle: string;
|
|
||||||
year: string;
|
|
||||||
dataSource: string;
|
|
||||||
url: string;
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
genres: string[];
|
genres: string[];
|
||||||
onlineRating: number;
|
onlineRating: number;
|
||||||
image: string;
|
image?: string;
|
||||||
|
|
||||||
released: boolean;
|
released: boolean;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue