refactor private methods in dossiers service
This commit is contained in:
parent
a4458184f1
commit
7b7fd20cdf
@ -33,7 +33,7 @@ const GENERIC_MSG = _('add-dossier-dialog.errors.generic');
|
|||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class DossiersService extends EntitiesService<Dossier, IDossier> {
|
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>();
|
readonly dossierFileChanges$ = new Subject<string>();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -47,7 +47,7 @@ export class DossiersService extends EntitiesService<Dossier, IDossier> {
|
|||||||
timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL)
|
timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL)
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(() => this.loadOnlyChanged()),
|
switchMap(() => this.loadOnlyChanged()),
|
||||||
tap(changes => this._emitFileChanges(changes)),
|
tap(changes => this.#emitFileChanges(changes)),
|
||||||
)
|
)
|
||||||
.subscribe();
|
.subscribe();
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ export class DossiersService extends EntitiesService<Dossier, IDossier> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadOnlyChanged(): Observable<ChangesDetails> {
|
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(
|
return this.hasChangesDetails$().pipe(
|
||||||
switchMap(changes => load(changes.dossierChanges).pipe(mapTo(changes))),
|
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;
|
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(
|
return super._getOne([id], this._defaultModelPath, queryParams).pipe(
|
||||||
map(entity => new Dossier(entity)),
|
map(entity => new Dossier(entity)),
|
||||||
switchMap(dossier => this._dossierStatsService.getFor([dossier.dossierId]).pipe(mapTo(dossier))),
|
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));
|
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;
|
let totalAnalyzedPages = 0;
|
||||||
const totalPeople = new Set<string>();
|
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));
|
const stats$ = entities.map(entity => this._dossierStatsService.watch$(entity.dossierId));
|
||||||
return combineLatest(stats$).pipe(
|
return combineLatest(stats$).pipe(
|
||||||
filter(stats => stats.every(s => !!s)),
|
filter(stats => stats.every(s => !!s)),
|
||||||
map(() => this._computeStats(entities)),
|
map(() => this.#computeStats(entities)),
|
||||||
shareLast(),
|
shareLast(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user