loadIfChanged handle dossier deleted
This commit is contained in:
parent
12bbbcdad2
commit
146fb5bee2
@ -1,7 +1,7 @@
|
||||
import { Injectable, Injector } from '@angular/core';
|
||||
import { EntitiesService, List, mapEach, QueryParam, RequiredParam, shareLast, Toaster, Validate } from '@iqser/common-ui';
|
||||
import { Dossier, IDossier, IDossierRequest } from '@red/domain';
|
||||
import { catchError, filter, map, mapTo, switchMap, tap } from 'rxjs/operators';
|
||||
import { Dossier, DossierStats, IDossier, IDossierRequest } from '@red/domain';
|
||||
import { catchError, filter, map, mapTo, pluck, switchMap, tap } from 'rxjs/operators';
|
||||
import { combineLatest, firstValueFrom, forkJoin, Observable, of, Subject, throwError, timer } from 'rxjs';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
|
||||
@ -63,11 +63,22 @@ export class DossiersService extends EntitiesService<Dossier, IDossier> {
|
||||
);
|
||||
}
|
||||
|
||||
loadOnlyChanged(): Observable<ChangesDetails> {
|
||||
const load = (changes: DossierChanges) => forkJoin(changes.map(change => this._load(change.dossierId)));
|
||||
loadOnlyChanged(): Observable<DossierChanges> {
|
||||
const removeIfNotFound = (id: string) =>
|
||||
catchError((error: HttpErrorResponse) => {
|
||||
if (error.status === HttpStatusCode.NotFound) {
|
||||
this.remove(id);
|
||||
return of([]);
|
||||
}
|
||||
return throwError(() => error);
|
||||
});
|
||||
|
||||
const load = (changes: DossierChanges) =>
|
||||
changes.map(change => this._load(change.dossierId).pipe(removeIfNotFound(change.dossierId)));
|
||||
|
||||
return this.hasChangesDetails$().pipe(
|
||||
switchMap(changes => load(changes.dossierChanges).pipe(mapTo(changes))),
|
||||
pluck('dossierChanges'),
|
||||
switchMap(dossierChanges => forkJoin(load(dossierChanges)).pipe(mapTo(dossierChanges))),
|
||||
tap(() => this._updateLastChanged()),
|
||||
);
|
||||
}
|
||||
@ -122,16 +133,16 @@ export class DossiersService extends EntitiesService<Dossier, IDossier> {
|
||||
return this.all.filter(dossier => dossier.dossierStatusId === dossierStatusId).length;
|
||||
}
|
||||
|
||||
private _load(id: string, queryParams?: List<QueryParam>): Observable<Dossier> {
|
||||
private _load(id: string, queryParams?: List<QueryParam>): Observable<DossierStats[]> {
|
||||
return super._getOne([id], this._defaultModelPath, queryParams).pipe(
|
||||
map(entity => new Dossier(entity)),
|
||||
switchMap(dossier => this._dossierStatsService.getFor([dossier.dossierId]).pipe(mapTo(dossier))),
|
||||
tap(dossier => this.replace(dossier)),
|
||||
switchMap(dossier => this._dossierStatsService.getFor([dossier.dossierId])),
|
||||
);
|
||||
}
|
||||
|
||||
#emitFileChanges(changes: ChangesDetails): void {
|
||||
changes.dossierChanges.filter(change => change.fileChanges).forEach(change => this.dossierFileChanges$.next(change.dossierId));
|
||||
#emitFileChanges(dossierChanges: DossierChanges): void {
|
||||
dossierChanges.filter(change => change.fileChanges).forEach(change => this.dossierFileChanges$.next(change.dossierId));
|
||||
}
|
||||
|
||||
#computeStats(entities: List<Dossier>): IDossiersStats {
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit a9cddbf19b985c887bc772aec6fdd862d1dc848a
|
||||
Subproject commit ab4568eb9d6a099b23ce4df07702e3f834fd8a5b
|
||||
Loading…
x
Reference in New Issue
Block a user