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:
@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user