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 4787fdb30..4a680ef1e 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 @@ -2,7 +2,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 { combineLatest, firstValueFrom, Observable, of, Subject, throwError, timer } from 'rxjs'; +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'; import { DossierStatsService } from '@services/entity-services/dossier-stats.service'; @@ -62,13 +62,16 @@ export class DossiersService extends EntitiesService { } loadAllIfChanged(): Observable { - return this.hasChangesDetails$().pipe(switchMap(changes => this.loadAll().pipe(mapTo(changes)))); + return this.hasChangesDetails$().pipe( + switchMap(changes => forkJoin(changes.dossierChanges.map(change => this.load(change.dossierId))).pipe(mapTo(changes))), + ); } hasChangesDetails$(): Observable { const body = { value: this._lastCheckedForChanges.get('root') ?? '0' }; return this._post(body, `${this._defaultModelPath}/changes/details`).pipe( filter(changes => changes.dossierChanges.length > 0), + tap(() => this._updateLastChanged()), ); } @@ -115,6 +118,14 @@ export class DossiersService extends EntitiesService { return this.all.filter(dossier => dossier.dossierStatusId === dossierStatusId).length; } + 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)), + ); + } + private _emitFileChanges(changes: ChangesDetails): void { changes.dossierChanges.filter(change => change.fileChanges).forEach(change => this.dossierFileChanges$.next(change.dossierId)); }