- Fix bug where workflows were being created again after exam update

- Moved createWorkflows function into an helper file instead of a post request.
- Moved the workflow creation logic into the post of exam creation instead of a seperate post in each exam module
This commit is contained in:
Joao Correia
2025-02-06 13:16:32 +00:00
parent c3849518fb
commit 752881df41
8 changed files with 112 additions and 222 deletions

View File

@@ -190,41 +190,16 @@ const SpeakingSettings: React.FC = () => {
const result = await axios.post('/api/exam/speaking', exam);
playSound("sent");
toast.success(`Submitted Exam ID: ${result.data.id}`);
// Successfully submitted exam
if (result.status === 200) {
toast.success(result.data.message);
} else if (result.status === 207) {
toast.warning(result.data.message);
}
Array.from(urlMap.values()).forEach(url => {
URL.revokeObjectURL(url);
});
const requestBody = await (async () => {
const handledExam = await getExamById("speaking", result.data.id);
return {
examAuthor: handledExam?.createdBy ?? "Unknown Author",
examEntities: handledExam?.entities ?? [],
examId: handledExam?.id ?? "Unknown ID",
examModule: "speaking"
};
})();
await axios
.post(`/api/approval-workflows`, requestBody)
.then((response) => {
if (response.status === 200) {
toast.success(`Approval Workflows for exam have been successfully created`);
} else if (response.status === 207) {
toast.warning(
`Approval Workflows were partially created. Exam author might not have a configured workflow for all its entities.`
);
}
})
.catch((reason) => {
if (reason.response?.status === 404) {
toast.error("No configured workflow found for examAuthor for any of its entities.");
} else {
toast.error(
"Something went wrong while creating approval workflow, please try again later."
);
}
});
} catch (error: any) {
toast.error(