Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Envoyer en un batch les alertes Joi pour le métier (PIX-15124) #10503

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ const qcuElementSchema = Joi.object({
invalid: htmlSchema,
}),
solution: proposalIdSchema.required(),
}).custom((qcuElement, helpers) => {
}).external(async (qcuElement, helpers) => {
dianeCdrPix marked this conversation as resolved.
Show resolved Hide resolved
const hasGlobalFeedbacks = qcuElement.feedbacks !== undefined;
const hasSpecificFeedbacks = qcuElement.proposals.some((proposal) => proposal.feedback !== undefined);
if (hasGlobalFeedbacks && hasSpecificFeedbacks) {
return helpers.message('Un QCU ne peut pas avoir à la fois des feedbacks spécifiques et globales');
return helpers.error('Un QCU ne peut pas avoir à la fois des feedbacks spécifiques et globales');
}
if (hasSpecificFeedbacks) {
const someProposalsDoNotHaveSpecificFeedback = qcuElement.proposals.some(
(proposal) => proposal.feedback === undefined,
);
if (someProposalsDoNotHaveSpecificFeedback) {
return helpers.message('Dans ce QCU, au moins une proposition ne possède pas de feedback spécifique');
return helpers.error('Dans ce QCU, au moins une proposition ne possède pas de feedback spécifique');
}
}
if (!hasGlobalFeedbacks && !hasSpecificFeedbacks) {
return helpers.message("Dans ce QCU, il n'y a ni feedbacks spécifiques, ni feedbacks globales");
return helpers.error("Dans ce QCU, il n'y a ni feedbacks spécifiques, ni feedbacks globales");
}

return qcuElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,21 @@ const grainSchema = Joi.object({
],
}),
)
.custom((value, helpers) => {
.external(async (value, helpers) => {
const steppersInArray = value.filter(({ type }) => type === 'stepper');
if (steppersInArray.length > 1) {
return helpers.message("Il ne peut y avoir qu'un stepper par grain");
return helpers.error("Il ne peut y avoir qu'un stepper par grain");
}
return value;
})
.custom((value, helpers) => {
.external(async (value, helpers) => {
const steppersInArray = value.filter(({ type }) => type === 'stepper');
const elementsInArray = value.filter(({ type }) => type === 'element');
const containsAnswerableElement = elementsInArray.some(({ element }) =>
['qcu', 'qcm', 'qrocm'].includes(element.type),
);
if (steppersInArray.length === 1 && containsAnswerableElement) {
return helpers.message(
return helpers.error(
"Un grain ne peut pas être composé d'un composant 'stepper' et d'un composant 'element' répondable (QCU, QCM ou QROCM)",
);
}
Expand Down
Loading