Skip to content

Commit

Permalink
Merge pull request strapi#11683 from strapi/v4/unique-validator
Browse files Browse the repository at this point in the history
[v4] add `unique` validator
  • Loading branch information
alexandrebodin authored Nov 29, 2021
2 parents e8867ad + 652cac0 commit 3e9e3f1
Show file tree
Hide file tree
Showing 8 changed files with 1,752 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const advancedForm = {
id: getTrad('form.attribute.item.settings.name'),
defaultMessage: 'Settings',
},
items: [options.required, options.unique, options.private],
items: [options.required, options.private],
},
],
};
Expand Down Expand Up @@ -209,7 +209,7 @@ const advancedForm = {
id: getTrad('form.attribute.item.settings.name'),
defaultMessage: 'Settings',
},
items: [options.required, options.unique, options.private],
items: [options.required, options.private],
},
],
};
Expand All @@ -222,7 +222,7 @@ const advancedForm = {
id: getTrad('form.attribute.item.settings.name'),
defaultMessage: 'Settings',
},
items: [options.required, options.unique, options.private],
items: [options.required, options.private],
},
],
};
Expand Down Expand Up @@ -297,13 +297,7 @@ const advancedForm = {
id: getTrad('form.attribute.item.settings.name'),
defaultMessage: 'Settings',
},
items: [
options.required,
options.unique,
options.maxLength,
options.minLength,
options.private,
],
items: [options.required, options.maxLength, options.minLength, options.private],
},
],
};
Expand All @@ -330,13 +324,7 @@ const advancedForm = {
id: getTrad('form.attribute.item.settings.name'),
defaultMessage: 'Settings',
},
items: [
options.required,
options.unique,
options.maxLength,
options.minLength,
options.private,
],
items: [options.required, options.maxLength, options.minLength, options.private],
},
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const getTypeShape = (attribute, { modelType, attributes } = {}) => {
return {
multiple: yup.boolean(),
required: validators.required,
unique: validators.unique,
allowedTypes: yup
.array()
.of(yup.string().oneOf(['images', 'videos', 'files']))
Expand Down Expand Up @@ -129,7 +128,6 @@ const getTypeShape = (attribute, { modelType, attributes } = {}) => {
return {
default: yup.mixed().test(isValidDefaultJSON),
required: validators.required,
unique: validators.unique,
};
}
case 'enumeration': {
Expand All @@ -148,7 +146,6 @@ const getTypeShape = (attribute, { modelType, attributes } = {}) => {
default: yup.string().when('enum', enumVal => yup.string().oneOf(enumVal)),
enumName: yup.string().test(isValidName),
required: validators.required,
unique: validators.unique,
};
}
case 'password': {
Expand Down Expand Up @@ -225,7 +222,6 @@ const getTypeShape = (attribute, { modelType, attributes } = {}) => {
return {
default: yup.boolean(),
required: validators.required,
unique: validators.unique,
};
}

Expand Down
11 changes: 8 additions & 3 deletions packages/core/strapi/lib/services/entity-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,14 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })

const isDraft = contentTypesUtils.isDraft(entityToUpdate, model);

const validData = await entityValidator.validateEntityUpdate(model, data, {
isDraft,
});
const validData = await entityValidator.validateEntityUpdate(
model,
data,
{
isDraft,
},
entityToUpdate
);

const query = transformParamsToQuery(uid, pickSelectionParams(wrappedParams));

Expand Down
Loading

0 comments on commit 3e9e3f1

Please sign in to comment.