feat: validation to update workflow

This commit is contained in:
Marc-Roig 2023-05-12 17:37:02 +02:00
parent ab40c6a80b
commit 8fceb4cc4d
No known key found for this signature in database
GPG Key ID: FB4E2C43A0BEE249

View File

@ -8,12 +8,6 @@ const stageObject = yup.object().shape({
color: yup.string().matches(/^#(?:[0-9a-fA-F]{3}){1,2}$/i), // hex color
});
const validateUpdateStagesSchema = yup
.array()
.of(stageObject)
.required()
.max(200, 'You can not create more than 200 stages');
const validateUpdateStageOnEntity = yup
.object()
.shape({
@ -23,20 +17,25 @@ const validateUpdateStageOnEntity = yup
const validateWorkflowCreateSchema = yup.object().shape({
name: yup.string().max(255).required(),
stages: yup.array().of(stageObject).min(1, 'Can not create a workflow without stages').required(),
stages: yup
.array()
.of(stageObject)
.min(1, 'Can not create a workflow without stages')
.max(200, 'Can not have more than 200 stages')
.required(),
});
const validateWorkflowUpdateSchema = yup.object().shape({
name: yup.string().max(255),
stages: yup.array().of(stageObject),
stages: yup
.array()
.of(stageObject)
.min(1, 'Can not create a workflow without stages')
.max(200, 'Can not have more than 200 stages'),
});
module.exports = {
validateWorkflowCreate: validateYupSchema(validateWorkflowCreateSchema),
validateUpdateStages: validateYupSchema(validateUpdateStagesSchema, {
strict: false,
stripUnknown: true,
}),
validateUpdateStageOnEntity: validateYupSchema(validateUpdateStageOnEntity),
validateWorkflowUpdate: validateYupSchema(validateWorkflowUpdateSchema),
};