Skip to content

Commit

Permalink
remove quality analysis information from datastore
Browse files Browse the repository at this point in the history
  • Loading branch information
eperedo committed Mar 14, 2024
1 parent a91d821 commit a011d59
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
25 changes: 16 additions & 9 deletions src/data/repositories/QualityAnalysisD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,25 @@ export class QualityAnalysisD2Repository implements QualityAnalysisRepository {
});
}

remove(id: Id[]): FutureData<void> {
remove(id: Id): FutureData<void> {
return apiToFuture(
this.api.tracker.post(
this.api.tracker.postAsync(
{ importStrategy: "DELETE" },
{ trackedEntities: id.map(id => ({ trackedEntity: id })) }
{ trackedEntities: [{ trackedEntity: id }] }
)
).flatMap(d2Response => {
if (d2Response.status === "ERROR") {
return Future.error(new Error(d2Response.message));
} else {
return Future.success(undefined);
}
).flatMap(d2JobResponse => {
return apiToFuture(
this.api.system.waitFor("TRACKER_IMPORT_JOB", d2JobResponse.response.id)
).flatMap(d2Response => {
if (d2Response?.status === "ERROR") {
return Future.error(new Error(d2Response.message));
} else {
const dataStore = this.api.dataStore(DATA_QUALITY_NAMESPACE);
return apiToFuture(dataStore.delete(id)).flatMap(() => {
return Future.success(undefined);
});
}
});
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/domain/repositories/QualityAnalysisRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface QualityAnalysisRepository {
get(options: QualityAnalysisOptions): FutureData<QualityAnalysisPaginated>;
getById(id: Id): FutureData<QualityAnalysis>;
save(qualityAnalysis: QualityAnalysis[]): FutureData<void>;
remove(id: Id[]): FutureData<void>;
remove(id: Id): FutureData<void>;
}

export type Pagination = {
Expand Down
10 changes: 9 additions & 1 deletion src/domain/usecases/RemoveQualityUseCase.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { FutureData } from "$/data/api-futures";
import { Id } from "$/domain/entities/Ref";
import { QualityAnalysisRepository } from "$/domain/repositories/QualityAnalysisRepository";
import { Future } from "$/domain/entities/generic/Future";

export class RemoveQualityUseCase {
constructor(private qualityAnalysisRepository: QualityAnalysisRepository) {}

execute(qualityAnalysisIds: Id[]): FutureData<void> {
return this.qualityAnalysisRepository.remove(qualityAnalysisIds);
const concurrencyRequest = 5;
const $requests = Future.parallel(
qualityAnalysisIds.map(issue => this.qualityAnalysisRepository.remove(issue)),
{ concurrency: concurrencyRequest }
);
return $requests.flatMap(() => {
return Future.success(undefined);
});
}
}

0 comments on commit a011d59

Please sign in to comment.