Basic Working Product

The QueryBuilder is now being used to get data for each different class i.e. Card, Set, Type, SuperType and SubType
This commit is contained in:
Bradyn Glines
2018-01-20 16:45:17 -07:00
parent 92c2dea62f
commit 94a0da5aaa
17 changed files with 158 additions and 42 deletions

View File

@ -8,7 +8,37 @@ import { IQuery } from './interfaces/query';
import { AxiosResponse } from 'axios';
export class QueryBuilder {
static find<T>(type: (new() => T), id: string): T {
Client.get(type.resource())
static all<T extends Card | Set | Type | SuperType | SubType>(type: (new() => T)): Promise<T[]> {
let t = new type();
let params: IQuery[] = [{
name: 'pageSize',
value: 1000
}];
return this.returnResponse(t.resource(), params);
}
static find<T extends Card | Set | Type | SuperType | SubType>(type: (new() => T), id: string): Promise<T> {
let t = new type();
let params: IQuery[] = [{
name: 'id',
value: id
}];
return this.returnResponse(t.resource(), params);
}
static where<T extends Card | Set | Type | SuperType | SubType>(type: (new() => T), params: IQuery[]): Promise<T[]> {
let t = new type();
return this.returnResponse(t.resource(), params);
}
private static returnResponse(resource: string, params: IQuery[]): Promise<any> {
return Client.get(resource, params)
.then(response => {
return response;
})
.catch(error => console.error(error));
}
}