mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 00:39:49 +00:00
feat: throw ValidationError if stage has a duplicated name
This commit is contained in:
parent
27ed22ba71
commit
f11aeda877
@ -14,5 +14,6 @@ module.exports = {
|
||||
'You’ve reached the limit of workflows in your plan. Delete a workflow or contact Sales to enable more workflows.',
|
||||
STAGES_LIMIT:
|
||||
'You’ve 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.',
|
||||
},
|
||||
};
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user