instanciate all workflows configured for an exam author based on different entities.

This commit is contained in:
Joao Correia
2025-02-05 12:37:53 +00:00
parent f4c7961caa
commit 6692c201e4
9 changed files with 129 additions and 67 deletions

View File

@@ -215,24 +215,32 @@ const LevelSettings: React.FC = () => {
});
const requestBody = await (async () => {
const handledExam = await getExamById("level", result.data.id);
const handledExam = await getExamById("writing", result.data.id);
return {
examAuthor: handledExam?.createdBy ?? "Unknown Author",
examEntities: handledExam?.entities ?? [],
examId: handledExam?.id ?? "Unknown ID",
examModule: "level"
examModule: "writing"
};
})();
await axios.post(`/api/approval-workflows`, requestBody)
.then(() => {
toast.success(`Approval Workflow for exam has been created`);
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.");
}
else {
toast.error("Something went wrong while creating approval workflow, please try again later.");
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."
);
}
});

View File

@@ -153,24 +153,32 @@ const ListeningSettings: React.FC = () => {
toast.success(`Submitted Exam ID: ${result.data.id}`);
const requestBody = await (async () => {
const handledExam = await getExamById("listening", result.data.id);
const handledExam = await getExamById("writing", result.data.id);
return {
examAuthor: handledExam?.createdBy ?? "Unknown Author",
examEntities: handledExam?.entities ?? [],
examId: handledExam?.id ?? "Unknown ID",
examModule: "listening"
examModule: "writing"
};
})();
await axios.post(`/api/approval-workflows`, requestBody)
.then(() => {
toast.success(`Approval Workflow for exam has been created`);
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.");
}
else {
toast.error("Something went wrong while creating approval workflow, please try again later.");
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."
);
}
});

View File

@@ -90,27 +90,35 @@ const ReadingSettings: React.FC = () => {
.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(() => {
toast.success(`Approval Workflow for exam has been created`);
.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((error) => {
if (error.response && error.response.status === 404) {
toast.error("No configured workflow found for examAuthor.");
toast.error("No configured workflow found for examAuthor for any of its entities.");
} else {
// This error could come from either of the requests
toast.error(error.response?.data?.error || "Something went wrong, please try again later.");
toast.error(
error.response?.data?.error ||
"Something went wrong, please try again later."
);
}
});
}

View File

@@ -197,24 +197,32 @@ const SpeakingSettings: React.FC = () => {
});
const requestBody = await (async () => {
const handledExam = await getExamById("speaking", result.data.id);
const handledExam = await getExamById("writing", result.data.id);
return {
examAuthor: handledExam?.createdBy ?? "Unknown Author",
examEntities: handledExam?.entities ?? [],
examId: handledExam?.id ?? "Unknown ID",
examModule: "speaking"
examModule: "writing"
};
})();
await axios.post(`/api/approval-workflows`, requestBody)
.then(() => {
toast.success(`Approval Workflow for exam has been created`);
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.");
}
else {
toast.error("Something went wrong while creating approval workflow, please try again later.");
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."
);
}
});

View File

@@ -144,23 +144,31 @@ const WritingSettings: React.FC = () => {
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(() => {
toast.success(`Approval Workflow for exam has been created`);
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.");
}
else {
toast.error("Something went wrong while creating approval workflow, please try again later.");
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."
);
}
});