feat: throw ValidationError if stage has a duplicated name

This commit is contained in:
Marc-Roig 2023-07-17 11:03:36 +02:00
parent 27ed22ba71
commit f11aeda877
No known key found for this signature in database
GPG Key ID: FB4E2C43A0BEE249
2 changed files with 7 additions and 0 deletions

View File

@ -14,5 +14,6 @@ module.exports = {
'Youve reached the limit of workflows in your plan. Delete a workflow or contact Sales to enable more workflows.',
STAGES_LIMIT:
'Youve reached the limit of stages for this workflow in your plan. Try deleting some stages or contact Sales to enable more stages.',
DUPLICATED_STAGE_NAME: 'Stage names must be unique.',
},
};

View File

@ -1,5 +1,6 @@
'use strict';
const { uniq } = require('lodash/fp');
const { ValidationError } = require('@strapi/utils').errors;
const { getService } = require('../../utils');
const { ERRORS, MAX_WORKFLOWS, MAX_STAGES_PER_WORKFLOW } = require('../../constants/workflows');
@ -32,6 +33,11 @@ module.exports = ({ strapi }) => {
if (stages.length > this.limits.stagesPerWorkflow) {
throw new ValidationError(ERRORS.STAGES_LIMIT);
}
// Validate stage names are not duplicated
const stageNames = stages.map((stage) => stage.name);
if (uniq(stageNames).length !== stageNames.length) {
throw new ValidationError(ERRORS.DUPLICATED_STAGE_NAME);
}
},
async validateWorkflowCountStages(workflowId, countAddedStages = 0) {