Added upload method to generic service
This commit is contained in:
parent
df4f99aab9
commit
019072dfd2
@ -1,4 +1,4 @@
|
|||||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
import { HttpClient, HttpEvent, HttpParams } from '@angular/common/http';
|
||||||
import { Injector } from '@angular/core';
|
import { Injector } from '@angular/core';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { CustomHttpUrlEncodingCodec, List, RequiredParam, Validate } from '../utils';
|
import { CustomHttpUrlEncodingCodec, List, RequiredParam, Validate } from '../utils';
|
||||||
@ -40,7 +40,11 @@ export abstract class GenericService<I> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Validate()
|
@Validate()
|
||||||
delete(@RequiredParam() body: unknown, modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<unknown> {
|
delete(
|
||||||
|
@RequiredParam() body: unknown,
|
||||||
|
modelPath = this._defaultModelPath,
|
||||||
|
queryParams?: List<QueryParam>,
|
||||||
|
): Observable<unknown> {
|
||||||
let path = `/${encodeURI(modelPath)}`;
|
let path = `/${encodeURI(modelPath)}`;
|
||||||
|
|
||||||
if (typeof body === 'string') {
|
if (typeof body === 'string') {
|
||||||
@ -55,6 +59,24 @@ export abstract class GenericService<I> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Validate()
|
||||||
|
upload<R = I>(data?: Blob, modelPath = this._defaultModelPath): Observable<HttpEvent<R>> {
|
||||||
|
const formParams = new FormData();
|
||||||
|
|
||||||
|
if (data !== undefined) {
|
||||||
|
formParams.append('file', data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Fix getHeaders()?
|
||||||
|
const headers = HeadersConfiguration.getHeaders().delete('content-type');
|
||||||
|
|
||||||
|
return this._http.post<R>(`/${encodeURI(modelPath)}`, formParams, {
|
||||||
|
headers,
|
||||||
|
observe: 'events',
|
||||||
|
reportProgress: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Validate()
|
@Validate()
|
||||||
protected _post<R = I>(
|
protected _post<R = I>(
|
||||||
@RequiredParam() body: unknown,
|
@RequiredParam() body: unknown,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user