diff --git a/src/data/repositories/QualityAnalysisD2Repository.ts b/src/data/repositories/QualityAnalysisD2Repository.ts index 174f890..4d8270f 100644 --- a/src/data/repositories/QualityAnalysisD2Repository.ts +++ b/src/data/repositories/QualityAnalysisD2Repository.ts @@ -134,18 +134,25 @@ export class QualityAnalysisD2Repository implements QualityAnalysisRepository { }); } - remove(id: Id[]): FutureData { + remove(id: Id): FutureData { 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); + }); + } + }); }); } diff --git a/src/domain/repositories/QualityAnalysisRepository.ts b/src/domain/repositories/QualityAnalysisRepository.ts index 4258bd7..ae856f0 100644 --- a/src/domain/repositories/QualityAnalysisRepository.ts +++ b/src/domain/repositories/QualityAnalysisRepository.ts @@ -7,7 +7,7 @@ export interface QualityAnalysisRepository { get(options: QualityAnalysisOptions): FutureData; getById(id: Id): FutureData; save(qualityAnalysis: QualityAnalysis[]): FutureData; - remove(id: Id[]): FutureData; + remove(id: Id): FutureData; } export type Pagination = { diff --git a/src/domain/usecases/RemoveQualityUseCase.ts b/src/domain/usecases/RemoveQualityUseCase.ts index 7fdedb6..bf60ec3 100644 --- a/src/domain/usecases/RemoveQualityUseCase.ts +++ b/src/domain/usecases/RemoveQualityUseCase.ts @@ -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 { - 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); + }); } }