generated from EyeSeeTea/dhis2-app-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: delete custom ast guideline from datastore on prevelance survey …
…form deletion
- Loading branch information
Showing
7 changed files
with
71 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,37 @@ | ||
import { FutureData } from "../../data/api-futures"; | ||
import { SURVEY_FORM_TYPES } from "../entities/Survey"; | ||
import { Id } from "../entities/Ref"; | ||
|
||
import { SurveyRepository } from "../repositories/SurveyRepository"; | ||
import { getProgramId } from "../utils/PPSProgramsHelper"; | ||
import { Future } from "../entities/generic/Future"; | ||
import { ASTGUIDELINE_TYPES } from "../entities/ASTGuidelines"; | ||
import { ASTGuidelinesRepository } from "../repositories/ASTGuidelinesRepository"; | ||
|
||
export class DeleteSurveyUseCase { | ||
constructor(private surveyReporsitory: SurveyRepository) {} | ||
constructor( | ||
private surveyReporsitory: SurveyRepository, | ||
private astGuidelinesRepository: ASTGuidelinesRepository | ||
) {} | ||
|
||
public execute(surveyFormType: SURVEY_FORM_TYPES, orgUnitId: Id, id: Id): FutureData<void> { | ||
public execute( | ||
surveyFormType: SURVEY_FORM_TYPES, | ||
orgUnitId: Id, | ||
id: Id, | ||
astGuidelineType?: ASTGUIDELINE_TYPES | ||
): FutureData<void> { | ||
const programId = getProgramId(surveyFormType); | ||
return this.surveyReporsitory.deleteSurvey(id, orgUnitId, programId); | ||
return this.surveyReporsitory.deleteSurvey(id, orgUnitId, programId).flatMap(() => { | ||
if (surveyFormType === "PrevalenceSurveyForm" && astGuidelineType === "CUSTOM") { | ||
return this.astGuidelinesRepository | ||
.deleteCustomASTGuideline(id) | ||
.flatMap((deleted: boolean) => { | ||
if (deleted) return Future.success(undefined); | ||
else | ||
return Future.error( | ||
new Error("Error deleting the custom AST guideline in datastore") | ||
); | ||
}); | ||
} else return Future.success(undefined); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters