Skip to content

Commit

Permalink
feat: add stats dto to collection item
Browse files Browse the repository at this point in the history
Add deserialization for:
- BggCollectionItemDto.conditiontext
- BggCollectionItemDto.stats

Github: Close #46
  • Loading branch information
LearningProcesss committed Jun 18, 2023
1 parent 49ecb06 commit a9643e8
Show file tree
Hide file tree
Showing 10 changed files with 3,125 additions and 14 deletions.
17 changes: 9 additions & 8 deletions buildtest/cjs/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ describe('BggClient', () => {

expect(validationResult).toStrictEqual([])
}, 70000);
it('should fetch and deserialize all data when request has not all params', async () => {
const dtoList = await client.thing.query({ id: 174430, videos: 1, comments: 1, marketplace: 1, stats: 1, type: "boardgame" })

const validationResult = ValidatorTraverse(dtoList[0], reflectionProperties, reflectionPropertiesExcludable)

expect(validationResult).toStrictEqual([])
}, 70000);
it('should fetch with paginated progress with method function', async () => {
let count = 0;
await client.thing.queryWithProgress({
Expand Down Expand Up @@ -95,7 +88,7 @@ describe('BggClient', () => {

const dtoList = await client.thread.query({ id: 1082079, count: 10, minarticledate: '2021-12-15' })

console.log("thread dtolist", dtoList);
// console.log("thread dtolist", dtoList);

const validationResult = ValidatorTraverse(dtoList[0], reflectionProperties, reflectionPropertiesExcludable)

Expand Down Expand Up @@ -139,6 +132,14 @@ describe('BggClient', () => {

const validationResult = ValidatorTraverse(dtoList[0], reflectionProperties, reflectionPropertiesExcludable)

expect(validationResult).toStrictEqual([])
}, 70000);
it('should parse Collection dto when xml response contains conditiontext property', async () => {

const dtoList = await client.collection.query({ username: 'Vitho', stats: 1 })

const validationResult = ValidatorTraverse(dtoList[0], reflectionProperties, reflectionPropertiesExcludable)

expect(validationResult).toStrictEqual([])
}, 70000);
});
Expand Down
10 changes: 10 additions & 0 deletions rest.http
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ GET https://www.boardgamegeek.com/xmlapi2/family?id=8374&type=boardgamefamily

GET https://www.boardgamegeek.com/xmlapi2/collection?username=mattiabanned&version=1 HTTP/1.1

###
GET https://www.boardgamegeek.com/xmlapi2/collection?username=Vitho&stats=1 HTTP/1.1

###
GET https://www.boardgamegeek.com/xmlapi2/collection?username=Vitho HTTP/1.1

### plays

GET https://www.boardgamegeek.com/xmlapi2/plays?username=mattiabanned HTTP/1.1
Expand All @@ -23,6 +29,10 @@ GET https://www.boardgamegeek.com/xmlapi2/plays?username=mattiabanned HTTP/1.1

GET https://www.boardgamegeek.com/xmlapi2/thread?id=1082079 HTTP/1.1

###

GET https://boardgamegeek.com/xmlapi2/thread?id=1082079&count=10&minarticledate=2021-12-15 HTTP/1.1

### search

GET https://www.boardgamegeek.com/xmlapi2/search?query=34294&type=boardgame
Expand Down
14 changes: 13 additions & 1 deletion src/dto/concrete/subdto/BggCollectionItemDto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JsonAlias, JsonClassType, JsonDeserialize, JsonManagedReference, JsonProperty } from "jackson-js";
import { BggCollectionItemStatusDto } from "./BggCollectionItemStatusDto";
import { BggCollectionItemStatsDto, BggCollectionItemStatusDto } from ".";

export class BggCollectionItemDto {
@JsonProperty()
Expand Down Expand Up @@ -72,4 +72,16 @@ export class BggCollectionItemDto {
})
@JsonManagedReference()
status: BggCollectionItemStatusDto;

@JsonProperty()
@JsonClassType({ type: () => [String] })
conditiontext: string;

@JsonProperty()
@JsonClassType({ type: () => [BggCollectionItemStatsDto] })
@JsonDeserialize({
using: (value: any[]) => value[0]
})
@JsonManagedReference()
stats: BggCollectionItemStatsDto;
}
125 changes: 125 additions & 0 deletions src/dto/concrete/subdto/BggCollectionItemStatsDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { JsonAlias, JsonClassType, JsonDeserialize, JsonManagedReference, JsonProperty } from "jackson-js";

export class BggCollectionItemStatsDto {
@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonAlias({ values: ["@_minplayers"] })
minplayers: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonAlias({ values: ["@_maxplayers"] })
maxplayers: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonAlias({ values: ["@_minplaytime"] })
minplaytime: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonAlias({ values: ["@_maxplaytime"] })
maxplaytime: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonAlias({ values: ["@_playingtime"] })
playingtime: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonAlias({ values: ["@_numowned"] })
numowned: number;

@JsonProperty()
@JsonClassType({ type: () => [BggCollectionItemStatRatingDto] })
@JsonManagedReference()
@JsonDeserialize({
//eslint-disable-next-line @typescript-eslint/no-explicit-any
using: (items: any[]) => items[0]
})
rating!: BggCollectionItemStatRatingDto;
}

export class BggCollectionItemStatRatingDto {
@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonAlias({ values: ["@_value"] })
value: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonDeserialize({
using: (value: []) => value.map(item => item['@_value'])[0]
})
usersrated!: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonDeserialize({
using: (value: []) => value.map(item => item['@_value'])[0]
})
average!: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonDeserialize({
using: (value: []) => value.map(item => item['@_value'])[0]
})
bayesaverage!: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonDeserialize({
using: (value: []) => value.map(item => item['@_value'])[0]
})
stddev!: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonDeserialize({
using: (value: []) => value.map(item => item['@_value'])[0]
})
median!: number;

@JsonProperty()
@JsonClassType({ type: () => [Array, [BggCollectionItemStatRatingRanksDto]] })
@JsonManagedReference()
@JsonDeserialize({
//eslint-disable-next-line @typescript-eslint/no-explicit-any
using: (items: any[]) => items[0]?.rank
})
ranks!: BggCollectionItemStatRatingRanksDto[];
}

export class BggCollectionItemStatRatingRanksDto {
@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonAlias({ values: ["@_type"] })
type: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonAlias({ values: ["@_id"] })
id: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonAlias({ values: ["@_name"] })
name: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonAlias({ values: ["@_friendlyname"] })
friendlyname: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonAlias({ values: ["@_value"] })
value: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonAlias({ values: ["@_bayesaverage"] })
bayesaverage: number;
}
4 changes: 3 additions & 1 deletion src/dto/concrete/subdto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export { BggPlaysPlayDto } from './BggPlaySubDtos';
export { BggCollectionItemDto } from './BggCollectionItemDto';
export { BggPollDto } from './BggPollDto';
export { BggSearchItemDto } from './BggSearchItemDto';
export { BggThingVersionDto } from './BggThingVersionDto';
export { BggThingVersionDto } from './BggThingVersionDto';
export { BggCollectionItemStatsDto } from './BggCollectionItemStatsDto';
export { BggCollectionItemStatusDto } from './BggCollectionItemStatusDto';
Loading

0 comments on commit a9643e8

Please sign in to comment.