refactor private methods in dossiers service

This commit is contained in:
Dan Percic 2022-02-17 14:03:01 +02:00
parent a4458184f1
commit 7b7fd20cdf

View File

@ -33,7 +33,7 @@ const GENERIC_MSG = _('add-dossier-dialog.errors.generic');
providedIn: 'root',
})
export class DossiersService extends EntitiesService<Dossier, IDossier> {
readonly generalStats$ = this.all$.pipe(switchMap(entities => this._generalStats$(entities)));
readonly generalStats$ = this.all$.pipe(switchMap(entities => this.#generalStats$(entities)));
readonly dossierFileChanges$ = new Subject<string>();
constructor(
@ -47,7 +47,7 @@ export class DossiersService extends EntitiesService<Dossier, IDossier> {
timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL)
.pipe(
switchMap(() => this.loadOnlyChanged()),
tap(changes => this._emitFileChanges(changes)),
tap(changes => this.#emitFileChanges(changes)),
)
.subscribe();
}
@ -64,7 +64,7 @@ export class DossiersService extends EntitiesService<Dossier, IDossier> {
}
loadOnlyChanged(): Observable<ChangesDetails> {
const load = (changes: DossierChanges) => forkJoin(changes.map(change => this.load(change.dossierId)));
const load = (changes: DossierChanges) => forkJoin(changes.map(change => this._load(change.dossierId)));
return this.hasChangesDetails$().pipe(
switchMap(changes => load(changes.dossierChanges).pipe(mapTo(changes))),
@ -122,7 +122,7 @@ export class DossiersService extends EntitiesService<Dossier, IDossier> {
return this.all.filter(dossier => dossier.dossierStatusId === dossierStatusId).length;
}
load(id: string, queryParams?: List<QueryParam>): Observable<Dossier> {
private _load(id: string, queryParams?: List<QueryParam>): Observable<Dossier> {
return super._getOne([id], this._defaultModelPath, queryParams).pipe(
map(entity => new Dossier(entity)),
switchMap(dossier => this._dossierStatsService.getFor([dossier.dossierId]).pipe(mapTo(dossier))),
@ -130,11 +130,11 @@ export class DossiersService extends EntitiesService<Dossier, IDossier> {
);
}
private _emitFileChanges(changes: ChangesDetails): void {
#emitFileChanges(changes: ChangesDetails): void {
changes.dossierChanges.filter(change => change.fileChanges).forEach(change => this.dossierFileChanges$.next(change.dossierId));
}
private _computeStats(entities: List<Dossier>): IDossiersStats {
#computeStats(entities: List<Dossier>): IDossiersStats {
let totalAnalyzedPages = 0;
const totalPeople = new Set<string>();
@ -149,11 +149,11 @@ export class DossiersService extends EntitiesService<Dossier, IDossier> {
};
}
private _generalStats$(entities: List<Dossier>): Observable<IDossiersStats> {
#generalStats$(entities: List<Dossier>): Observable<IDossiersStats> {
const stats$ = entities.map(entity => this._dossierStatsService.watch$(entity.dossierId));
return combineLatest(stats$).pipe(
filter(stats => stats.every(s => !!s)),
map(() => this._computeStats(entities)),
map(() => this.#computeStats(entities)),
shareLast(),
);
}