validateAlias to artiste

This commit is contained in:
Cédric FAMIBELLE-PRONZOLA
2022-05-15 00:33:58 +04:00
parent 45867a01e4
commit 9de6e44343
@@ -5,6 +5,7 @@
* to customize this model
*/
const { ValidationError } = require("@strapi/utils").errors
const slugify = require('slugify')
const jwennTeksEpiId = async data => {
@@ -17,11 +18,19 @@ const jwennAwtisEpiId = async id => {
return artiste
}
const validateArtiste = alias => {
if (!alias || alias.trim().length === 0) {
throw new ValidationError('Champ obligatoire. Veuillez choisir un alias.');
}
}
module.exports = {
beforeUpdate: async event => {
let {data} = event.params
if(!data.publishedAt) {
validateArtiste(data.alias)
if (!data.slug || data.slug !== slugify(data.alias, {lower: true, remove: /[*#+~.()'"!:@]/g})) {
data.slug = slugify(data.alias, {lower: true, remove: /[*#+~.()'"!:@]/g})
}
@@ -30,6 +39,8 @@ module.exports = {
beforeCreate: async event => {
let {data} = event.params
validateArtiste(data.alias)
data.slug = slugify(data.alias, {lower: true, remove: /[*#+~.()'"!:@]/g})
},
afterUpdate: async event => {