diff --git a/apps/red-ui/src/app/services/entity-services/dossiers.service.ts b/apps/red-ui/src/app/services/entity-services/dossiers.service.ts index 5d7a7174b..0e48fc9c7 100644 --- a/apps/red-ui/src/app/services/entity-services/dossiers.service.ts +++ b/apps/red-ui/src/app/services/entity-services/dossiers.service.ts @@ -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 { ); } - loadOnlyChanged(): Observable { - const load = (changes: DossierChanges) => forkJoin(changes.map(change => this._load(change.dossierId))); + loadOnlyChanged(): Observable { + 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 { return this.all.filter(dossier => dossier.dossierStatusId === dossierStatusId).length; } - private _load(id: string, queryParams?: List): Observable { + private _load(id: string, queryParams?: List): Observable { 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): IDossiersStats { diff --git a/libs/common-ui b/libs/common-ui index a9cddbf19..ab4568eb9 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit a9cddbf19b985c887bc772aec6fdd862d1dc848a +Subproject commit ab4568eb9d6a099b23ce4df07702e3f834fd8a5b