RED-10483 - stop making additional dossier requests which leads to "Dossier not found" error when dossier is already deleted
This commit is contained in:
parent
8cba3658f7
commit
e4bd2eac67
@ -1,5 +1,5 @@
|
|||||||
import { GenericService, ROOT_CHANGES_KEY } from '@iqser/common-ui';
|
import { GenericService, ROOT_CHANGES_KEY } from '@iqser/common-ui';
|
||||||
import { Dossier, DossierStats, IChangesDetails } from '@red/domain';
|
import { Dossier, IChangesDetails, IDossierChanges } from '@red/domain';
|
||||||
import { forkJoin, Observable, Subscription, timer } from 'rxjs';
|
import { forkJoin, Observable, Subscription, timer } from 'rxjs';
|
||||||
import { filter, map, switchMap, take, tap } from 'rxjs/operators';
|
import { filter, map, switchMap, take, tap } from 'rxjs/operators';
|
||||||
import { NGXLogger } from 'ngx-logger';
|
import { NGXLogger } from 'ngx-logger';
|
||||||
@ -24,17 +24,18 @@ export class DossiersChangesService extends GenericService<Dossier> implements O
|
|||||||
protected readonly _defaultModelPath = 'dossier';
|
protected readonly _defaultModelPath = 'dossier';
|
||||||
|
|
||||||
loadOnlyChanged(): Observable<IChangesDetails> {
|
loadOnlyChanged(): Observable<IChangesDetails> {
|
||||||
const load = (changes: IChangesDetails) => this.#load(changes.dossierChanges.map(d => d.dossierId));
|
const load = (changes: IChangesDetails) => this.#load(this.#mapDossierChanges(changes.dossierChanges));
|
||||||
|
|
||||||
const loadStats = (change: IChangesDetails) => {
|
const loadStats = (change: IChangesDetails) => {
|
||||||
const dossierStatsToLoad = new Set<string>();
|
const dossierStatsToLoad = new Set<string>();
|
||||||
change.dossierChanges.forEach(dossierChange => dossierStatsToLoad.add(dossierChange.dossierId));
|
change.dossierChanges.forEach(dossierChange => dossierStatsToLoad.add(dossierChange.dossierId));
|
||||||
change.fileChanges.forEach(fileChange => dossierStatsToLoad.add(fileChange.dossierId));
|
change.fileChanges.forEach(fileChange => dossierStatsToLoad.add(fileChange.dossierId));
|
||||||
return this.#dossierStatsService.getFor(Array.from(dossierStatsToLoad));
|
const dossierIds = this.#filterDossierIds(Array.from(dossierStatsToLoad));
|
||||||
|
return this.#dossierStatsService.getFor(dossierIds);
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.hasChangesDetails$().pipe(
|
return this.hasChangesDetails$().pipe(
|
||||||
tap(changes => this.#logger.info('[DOSSIERS_CHANGES] Found changes', changes)),
|
tap(changes => console.log('[DOSSIERS_CHANGES] Found changes', changes)),
|
||||||
switchMap(dossierChanges =>
|
switchMap(dossierChanges =>
|
||||||
forkJoin([load(dossierChanges), loadStats(dossierChanges), this.#dashboardStatsService.loadAll().pipe(take(1))]).pipe(
|
forkJoin([load(dossierChanges), loadStats(dossierChanges), this.#dashboardStatsService.loadAll().pipe(take(1))]).pipe(
|
||||||
map(() => dossierChanges),
|
map(() => dossierChanges),
|
||||||
@ -97,4 +98,13 @@ export class DossiersChangesService extends GenericService<Dossier> implements O
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#filterDossierIds(ids: string[]) {
|
||||||
|
return ids.filter(id => this.#dashboardStatsService.all.find(stats => stats.dossiersInTemplate.includes(id)));
|
||||||
|
}
|
||||||
|
|
||||||
|
#mapDossierChanges(dossierChanges: IDossierChanges | string[]): string[] {
|
||||||
|
const dossierIds = dossierChanges.map(change => change.dossierId);
|
||||||
|
return this.#filterDossierIds(dossierIds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { inject, Injectable } from '@angular/core';
|
import { inject, Injectable } from '@angular/core';
|
||||||
import { StatsService } from '@iqser/common-ui';
|
import { StatsService } from '@iqser/common-ui';
|
||||||
import { DOSSIER_ID, DossierStats, IDossierStats } from '@red/domain';
|
import { DashboardStats, DOSSIER_ID, DossierStats, IDossierStats } from '@red/domain';
|
||||||
import { Observable, of } from 'rxjs';
|
import { Observable, of } from 'rxjs';
|
||||||
import { UserService } from '@users/user.service';
|
import { UserService } from '@users/user.service';
|
||||||
import { NGXLogger } from 'ngx-logger';
|
import { NGXLogger } from 'ngx-logger';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user