fix undefined body & add loadAll overload

This commit is contained in:
Dan Percic 2021-11-22 10:06:38 +02:00
parent d67d556b68
commit 3ddedbbcf3
2 changed files with 6 additions and 7 deletions

View File

@ -46,6 +46,7 @@ export class EntitiesService<E extends IListable, I = E> extends GenericService<
);
}
loadAll(...args: unknown[]): Observable<E[]>;
loadAll(modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<E[]> {
return this.getAll(modelPath, queryParams).pipe(
mapEach(entity => new this._entityClass(entity)),

View File

@ -23,15 +23,13 @@ export interface QueryParam {
*/
export abstract class GenericService<I> {
protected readonly _http = this._injector.get(HttpClient);
private _lastCheckedForChanges = new Map<string, string>([[ROOT_CHANGES_KEY, '0']]);
private readonly _lastCheckedForChanges = new Map<string, string>([[ROOT_CHANGES_KEY, '0']]);
protected constructor(protected readonly _injector: Injector, protected readonly _defaultModelPath: string) {}
get<T = I[]>(): Observable<T>;
// eslint-disable-next-line @typescript-eslint/unified-signatures
get<T = I>(id: string, ...args: unknown[]): Observable<T>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
get<T>(id?: string, ...args: unknown[]): Observable<T> {
return id ? this._getOne<T>([id]) : this.getAll<T>();
@ -86,10 +84,10 @@ export abstract class GenericService<I> {
hasChanges$(key = ROOT_CHANGES_KEY): Observable<boolean> {
const modelPath = key === ROOT_CHANGES_KEY ? '' : `${key}/`;
return this._post<{ value: boolean }>(
{ value: this._lastCheckedForChanges.get(key) },
`${this._defaultModelPath}/${modelPath}changes`,
).pipe(map((res: { value: boolean }) => res.value));
const body = { value: this._lastCheckedForChanges.get(key) ?? '0' };
return this._post<{ value: boolean }>(body, `${this._defaultModelPath}/${modelPath}changes`).pipe(
map((res: { value: boolean }) => res.value),
);
}
@Validate()