Skip to content

Commit

Permalink
feat: do not allow creation of multiple facility forms in same OU
Browse files Browse the repository at this point in the history
  • Loading branch information
9sneha-n committed May 8, 2024
1 parent ef232f4 commit d03b738
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/domain/usecases/SaveFormDataUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,38 @@ export class SaveFormDataUseCase {
const ouId =
surveyFormType === "PPSSurveyForm" && orgUnitId === "" ? GLOBAL_OU_ID : orgUnitId;

//Do not allow creation of multiple Prevalence Facility Level Forms for the same facility.
if (surveyFormType === "PrevalenceFacilityLevelForm") {
return this.surveyReporsitory
.getSurveys(surveyFormType, programId, ouId, false)
.flatMap(surveys => {
if (surveys.length > 0) {
return Future.error(
new Error(
"Prevalence Facility Level Form already exists for this facility."
)
);
} else
return this.saveFormData(
surveyFormType,
questionnaire,
ouId,
programId,
eventId
);
});
}

return this.saveFormData(surveyFormType, questionnaire, ouId, programId, eventId);
}

saveFormData = (
surveyFormType: SURVEY_FORM_TYPES,
questionnaire: Questionnaire,
ouId: string,
programId: string,
eventId: string | undefined = undefined
): FutureData<void> => {
return this.surveyReporsitory
.saveFormData(questionnaire, "CREATE_AND_UPDATE", ouId, eventId, programId)
.flatMap((surveyId: Id | undefined) => {
Expand All @@ -46,7 +78,7 @@ export class SaveFormDataUseCase {
return Future.success(undefined);
}
});
}
};

saveCustomASTGuidelineToDatastore = (
surveyId: Id,
Expand Down

0 comments on commit d03b738

Please sign in to comment.