diff --git a/src/api/artiste/content-types/artiste/lifecycle.js b/src/api/artiste/content-types/artiste/lifecycles.js similarity index 70% rename from src/api/artiste/content-types/artiste/lifecycle.js rename to src/api/artiste/content-types/artiste/lifecycles.js index cc00f87..ed71fc3 100644 --- a/src/api/artiste/content-types/artiste/lifecycle.js +++ b/src/api/artiste/content-types/artiste/lifecycles.js @@ -8,34 +8,37 @@ const slugify = require('slugify') const jwennTeksEpiId = async data => { - const teks = await strapi.query('paroles').find({id_in: data}) + const teks = await strapi.db.query('api::parole.parole').find({id_in: data}) return teks } const jwennAwtisEpiId = async id => { - const artiste = await strapi.query('artiste').find({id}) + const artiste = await strapi.db.query('api::artiste.artiste').findOne({id}) return artiste } module.exports = { beforeUpdate: async event => { - let {data} = event + console.log('event', event) + let {data} = event.params - if (!data.slug) { + + if (!data.slug || data.slug !== slugify(data.alias, {lower: true, remove: /[*#+~.()'"!:@]/g})) { data.slug = slugify(data.alias, {lower: true, remove: /[*#+~.()'"!:@]/g}) } }, beforeCreate: async event => { - let {data} = event + let {data} = event.params data.slug = slugify(data.alias, {lower: true, remove: /[*#+~.()'"!:@]/g}) }, afterUpdate: async event => { - let {data} = event + console.log('event', event) + let {data} = event.params const {id} = data const artiste = await jwennAwtisEpiId(id) - if (artiste.teks && artiste.paroles.length >= 1) { + if (artiste.paroles && artiste.paroles.length >= 1) { const paroles = await jwennTeksEpiId(artiste.paroles) Promise.all(paroles.map(async t => { const {id, tit, slug, artiste} = t diff --git a/src/extensions/documentation/documentation/1.0.0/full_documentation.json b/src/extensions/documentation/documentation/1.0.0/full_documentation.json index 4cfb2be..9bb9e0d 100644 --- a/src/extensions/documentation/documentation/1.0.0/full_documentation.json +++ b/src/extensions/documentation/documentation/1.0.0/full_documentation.json @@ -14,7 +14,7 @@ "name": "Apache 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.html" }, - "x-generation-date": "2022-05-12T15:07:13.371Z" + "x-generation-date": "2022-05-12T15:51:28.188Z" }, "x-strapi-config": { "path": "/documentation",