validateAlias to artiste
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
* to customize this model
|
* to customize this model
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const { ValidationError } = require("@strapi/utils").errors
|
||||||
const slugify = require('slugify')
|
const slugify = require('slugify')
|
||||||
|
|
||||||
const jwennTeksEpiId = async data => {
|
const jwennTeksEpiId = async data => {
|
||||||
@@ -17,11 +18,19 @@ const jwennAwtisEpiId = async id => {
|
|||||||
return artiste
|
return artiste
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const validateArtiste = alias => {
|
||||||
|
if (!alias || alias.trim().length === 0) {
|
||||||
|
throw new ValidationError('Champ obligatoire. Veuillez choisir un alias.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
beforeUpdate: async event => {
|
beforeUpdate: async event => {
|
||||||
let {data} = event.params
|
let {data} = event.params
|
||||||
|
|
||||||
if(!data.publishedAt) {
|
if(!data.publishedAt) {
|
||||||
|
validateArtiste(data.alias)
|
||||||
|
|
||||||
if (!data.slug || data.slug !== slugify(data.alias, {lower: true, remove: /[*#+~.()'"!:@]/g})) {
|
if (!data.slug || data.slug !== slugify(data.alias, {lower: true, remove: /[*#+~.()'"!:@]/g})) {
|
||||||
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 => {
|
beforeCreate: async event => {
|
||||||
let {data} = event.params
|
let {data} = event.params
|
||||||
|
|
||||||
|
validateArtiste(data.alias)
|
||||||
|
|
||||||
data.slug = slugify(data.alias, {lower: true, remove: /[*#+~.()'"!:@]/g})
|
data.slug = slugify(data.alias, {lower: true, remove: /[*#+~.()'"!:@]/g})
|
||||||
},
|
},
|
||||||
afterUpdate: async event => {
|
afterUpdate: async event => {
|
||||||
|
|||||||
Reference in New Issue
Block a user