added prediction prototype

This commit is contained in:
VLE2FE
2020-08-12 15:15:31 +02:00
parent 8a44135d9a
commit c681c5d881
9 changed files with 143 additions and 6 deletions

View File

@ -25,19 +25,19 @@ export class ApiService {
}
get<T>(url, f: (data?: T, err?, headers?) => void = () => {}) {
this.requestErrorHandler<T>(this.http.get(this.host + url, this.options()), f);
this.requestErrorHandler<T>(this.http.get(this.url(url), this.options()), f);
}
post<T>(url, data = null, f: (data?: T, err?, headers?) => void = () => {}) {
this.requestErrorHandler<T>(this.http.post(this.host + url, data, this.options()), f);
this.requestErrorHandler<T>(this.http.post(this.url(url), data, this.options()), f);
}
put<T>(url, data = null, f: (data?: T, err?, headers?) => void = () => {}) {
this.requestErrorHandler<T>(this.http.put(this.host + url, data, this.options()), f);
this.requestErrorHandler<T>(this.http.put(this.url(url), data, this.options()), f);
}
delete<T>(url, f: (data?: T, err?, headers?) => void = () => {}) {
this.requestErrorHandler<T>(this.http.delete(this.host + url, this.options()), f);
this.requestErrorHandler<T>(this.http.delete(this.url(url), this.options()), f);
}
private requestErrorHandler<T>(observable: Observable<any>, f: (data?: T, err?, headers?) => void) {
@ -62,6 +62,15 @@ export class ApiService {
});
}
private url(url) {
if (/http[s]?:\/\//.test(url)) {
return url;
}
else {
return this.host + url;
}
}
private options(): {headers: HttpHeaders, observe: 'body'} {
return {headers: this.authOptions(), observe: 'response' as 'body'};
}