update last changed before the request

This commit is contained in:
Dan Percic 2023-03-06 11:22:20 +02:00
parent 33fb6b0525
commit e21ca5059e

View File

@ -2,7 +2,7 @@ import { HttpClient, HttpEvent, HttpParams } from '@angular/common/http';
import { inject } from '@angular/core';
import { Observable } from 'rxjs';
import { HeadersConfiguration, List, RequiredParam, Validate } from '../utils';
import { map, tap } from 'rxjs/operators';
import { map } from 'rxjs/operators';
const ROOT_CHANGES_KEY = 'root';
@ -37,16 +37,17 @@ export abstract class GenericService<I> {
getAll<R extends I[]>(modelPath?: string, queryParams?: List<QueryParam>): Observable<R>;
getAll<R = I[]>(modelPath?: string, queryParams?: List<QueryParam>): Observable<R>;
getAll<R = I[]>(modelPath = this._defaultModelPath, queryParams?: List<QueryParam>): Observable<R> {
const request$ = this._http.get<R>(`/${encodeURI(modelPath)}`, {
this._updateLastChanged();
return this._http.get<R>(`/${encodeURI(modelPath)}`, {
headers: HeadersConfiguration.getHeaders({ contentType: false }),
observe: 'body',
params: this._queryParams(queryParams),
});
return request$.pipe(tap(() => this._updateLastChanged()));
}
getFor<R = I[]>(entityId: string, queryParams?: List<QueryParam>): Observable<R> {
return this.getAll<R>(`${this._defaultModelPath}/${entityId}`, queryParams).pipe(tap(() => this._updateLastChanged(entityId)));
this._updateLastChanged(entityId);
return this.getAll<R>(`${this._defaultModelPath}/${entityId}`, queryParams);
}
@Validate()