Allow Client.get to accept a string for ID path parameter

This commit is contained in:
Ryan Munro (Monbrey)
2019-08-03 09:22:35 +10:00
parent 93535ff9ad
commit 682f90c49a
2 changed files with 20 additions and 43 deletions

View File

@ -5,33 +5,25 @@ import { IQuery } from './interfaces/query';
import { AxiosResponse } from 'axios';
export class QueryBuilder {
static all<T extends Card | Set>(type: (new() => T)): Promise<T[]> {
let t = new type();
let params: IQuery[] = [{
name: 'pageSize',
value: 1000
}];
static all<T extends Card | Set>(type: (new () => T)): Promise<T[]> {
let t = new type();
let params: IQuery[] = [{
name: 'pageSize',
value: 1000
}];
return this.returnResponse(t.resource(), params);
}
return Client.get(t.resource(), params).catch(error => console.error(error));
}
static find<T extends Card | Set>(type: (new() => T), id: string): Promise<T> {
let t = new type();
let params: IQuery[] = [{
name: 'id',
value: id
}];
static find<T extends Card | Set>(type: (new () => T), id: string): Promise<T> {
let t = new type();
return this.returnResponse(t.resource(), params);
}
return Client.get(t.resource(), id).catch(error => console.error(error));
}
static where<T extends Card | Set>(type: (new() => T), params: IQuery[]): Promise<T[]> {
let t = new type();
static where<T extends Card | Set>(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).catch(error => console.error(error));
}
return Client.get(t.resource(), params).catch(error => console.error(error));
}
}