/
Library.ts
57 lines (47 loc) · 1.85 KB
/
Library.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import BaseClient from '../BaseClient';
import CardUtils from '../utils/Card';
import { CardTemplate } from '../../interfaces/CardTemplate';
import { Treatment } from '../../interfaces/Treatment';
export default class Library {
private baseClient: BaseClient;
public constructor(baseClient: BaseClient) {
this.baseClient = baseClient;
}
/**
* Get a list of Treatments
* @param page the page to get (1 page = 100 treatments)
* @returns a Promise resolved with the response or rejected in case of error
*/
public async getTreatments(page = 1): Promise<Treatment[]> {
const result = await this.baseClient.get(`treatments`, {
page,
});
const data: Treatment[] = result.treatments.map((treatment: any) => ({
id: treatment.id,
name: treatment.name,
categoryId: treatment.categoryId,
designation: treatment.designation,
tier: treatment.tier,
active: treatment.active,
variation: treatment.variation,
gameSide: treatment.gameSide,
accentColor: treatment.accentColor,
artistName: treatment.artistName,
season: treatment.season,
buyPrice: treatment.buyPrice,
images: treatment.images,
videos: treatment.videos,
}));
return data;
}
/**
* Get a list of CardTemplate given a collection id
* @param collectionId the collection id
* @returns a Promise resolved with the response or rejected in case of error
*/
public async getCollectionCardTemplates(collectionId: number): Promise<CardTemplate[]> {
const result = await this.baseClient.get(`collections/${collectionId}/card-templates`);
const data: CardTemplate[] = result.map(CardUtils.createCardTemplate);
return data;
}
}