feat: validate workflow assignedCT update

This commit is contained in:
Marc-Roig 2023-05-15 10:27:51 +02:00
parent 1f90e94d78
commit 1b1cb9f899
No known key found for this signature in database
GPG Key ID: FB4E2C43A0BEE249

View File

@ -15,6 +15,14 @@ const validateUpdateStageOnEntity = yup
}) })
.required(); .required();
const validateAssignedContentTypes = yup.array().of(
yup.string().test({
name: 'content-type-exists',
message: (value) => `Content type ${value.originalValue} does not exist`,
test: (uid) => strapi.getModel(uid),
})
);
const validateWorkflowCreateSchema = yup.object().shape({ const validateWorkflowCreateSchema = yup.object().shape({
name: yup.string().max(255).required(), name: yup.string().max(255).required(),
stages: yup stages: yup
@ -23,6 +31,7 @@ const validateWorkflowCreateSchema = yup.object().shape({
.min(1, 'Can not create a workflow without stages') .min(1, 'Can not create a workflow without stages')
.max(200, 'Can not have more than 200 stages') .max(200, 'Can not have more than 200 stages')
.required(), .required(),
assignedContentTypes: validateAssignedContentTypes,
}); });
const validateWorkflowUpdateSchema = yup.object().shape({ const validateWorkflowUpdateSchema = yup.object().shape({
@ -30,8 +39,9 @@ const validateWorkflowUpdateSchema = yup.object().shape({
stages: yup stages: yup
.array() .array()
.of(stageObject) .of(stageObject)
.min(1, 'Can not create a workflow without stages') .min(1, 'Can not update a workflow without stages')
.max(200, 'Can not have more than 200 stages'), .max(200, 'Can not have more than 200 stages'),
assignedContentTypes: validateAssignedContentTypes,
}); });
module.exports = { module.exports = {