validateAlias to artiste
This commit is contained in:
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user