- 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:
@@ -205,7 +205,12 @@ const LevelSettings: React.FC = () => {
|
||||
|
||||
const result = await axios.post('/api/exam/level', 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(audioMap.values()).forEach(url => {
|
||||
URL.revokeObjectURL(url);
|
||||
@@ -214,36 +219,6 @@ const LevelSettings: React.FC = () => {
|
||||
URL.revokeObjectURL(url);
|
||||
});
|
||||
|
||||
const requestBody = await (async () => {
|
||||
const handledExam = await getExamById("level", result.data.id);
|
||||
return {
|
||||
examAuthor: handledExam?.createdBy ?? "Unknown Author",
|
||||
examEntities: handledExam?.entities ?? [],
|
||||
examId: handledExam?.id ?? "Unknown ID",
|
||||
examModule: "level"
|
||||
};
|
||||
})();
|
||||
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) {
|
||||
console.error('Error submitting exam:', error);
|
||||
toast.error(
|
||||
|
||||
@@ -150,37 +150,12 @@ const ListeningSettings: React.FC = () => {
|
||||
|
||||
const result = await axios.post('/api/exam/listening', exam);
|
||||
playSound("sent");
|
||||
toast.success(`Submitted Exam ID: ${result.data.id}`);
|
||||
|
||||
const requestBody = await (async () => {
|
||||
const handledExam = await getExamById("listening", result.data.id);
|
||||
return {
|
||||
examAuthor: handledExam?.createdBy ?? "Unknown Author",
|
||||
examEntities: handledExam?.entities ?? [],
|
||||
examId: handledExam?.id ?? "Unknown ID",
|
||||
examModule: "listening"
|
||||
};
|
||||
})();
|
||||
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."
|
||||
);
|
||||
}
|
||||
});
|
||||
// Successfully submitted exam
|
||||
if (result.status === 200) {
|
||||
toast.success(result.data.message);
|
||||
} else if (result.status === 207) {
|
||||
toast.warning(result.data.message);
|
||||
}
|
||||
|
||||
} else {
|
||||
toast.error('No audio sections found in the exam! Please either import them or generate them.');
|
||||
|
||||
@@ -89,38 +89,17 @@ const ReadingSettings: React.FC = () => {
|
||||
axios.post(`/api/exam/reading`, exam)
|
||||
.then((result) => {
|
||||
playSound("sent");
|
||||
toast.success(`Submitted Exam ID: ${result.data.id}`);
|
||||
return getExamById("reading", result.data.id);
|
||||
})
|
||||
.then((handledExam) => {
|
||||
const requestBody = {
|
||||
examAuthor: handledExam?.createdBy ?? "Unknown Author",
|
||||
examEntities: handledExam?.entities ?? [],
|
||||
examId: handledExam?.id ?? "Unknown ID",
|
||||
examModule: "reading"
|
||||
};
|
||||
|
||||
return 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.`
|
||||
);
|
||||
// Successfully submitted exam
|
||||
if (result.status === 200) {
|
||||
toast.success(result.data.message);
|
||||
} else if (result.status === 207) {
|
||||
toast.warning(result.data.message);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error.response && error.response.status === 404) {
|
||||
toast.error("No configured workflow found for examAuthor for any of its entities.");
|
||||
} else {
|
||||
toast.error(
|
||||
error.response?.data?.error ||
|
||||
"Something went wrong, please try again later."
|
||||
);
|
||||
}
|
||||
});
|
||||
console.log(error);
|
||||
toast.error(error.response.data.error || "Something went wrong while submitting, please try again later.");
|
||||
})
|
||||
}
|
||||
|
||||
const preview = () => {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -140,37 +140,12 @@ const WritingSettings: React.FC = () => {
|
||||
|
||||
const result = await axios.post(`/api/exam/writing`, exam)
|
||||
playSound("sent");
|
||||
toast.success(`Submitted Exam ID: ${result.data.id}`);
|
||||
|
||||
const requestBody = await (async () => {
|
||||
const handledExam = await getExamById("writing", result.data.id);
|
||||
return {
|
||||
examAuthor: handledExam?.createdBy ?? "Unknown Author",
|
||||
examEntities: handledExam?.entities ?? [],
|
||||
examId: handledExam?.id ?? "Unknown ID",
|
||||
examModule: "writing"
|
||||
};
|
||||
})();
|
||||
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."
|
||||
);
|
||||
}
|
||||
});
|
||||
// Successfully submitted exam
|
||||
if (result.status === 200) {
|
||||
toast.success(result.data.message);
|
||||
} else if (result.status === 207) {
|
||||
toast.warning(result.data.message);
|
||||
}
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('Error submitting exam:', error);
|
||||
|
||||
Reference in New Issue
Block a user