From 91079d68d7e7f4d84a4360b8f1a00319b75b1840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Famibelle-Pronzola?= Date: Mon, 6 Mar 2023 09:42:28 +0400 Subject: [PATCH] Fix artiste error when updating --- src/api/parole/content-types/parole/lifecycles.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/api/parole/content-types/parole/lifecycles.js b/src/api/parole/content-types/parole/lifecycles.js index 1d64788..b5889ea 100644 --- a/src/api/parole/content-types/parole/lifecycles.js +++ b/src/api/parole/content-types/parole/lifecycles.js @@ -26,6 +26,7 @@ const isSlugExists = async existingSlug => { } const jwennAwtisEpiId = async artistesIds => { + console.log('artistesIds', artistesIds) if (artistesIds.length === 0) { throw new ValidationError('Champ obligatoire. Veuillez choisir au moins un artiste.'); } @@ -138,7 +139,7 @@ module.exports = { const previousParoles = await strapi.db.query('api::parole.parole').findOne({ where: {id}, - populate: {difference: true} + populate: {difference: true, artistes: true} }) if (data.transcription && previousParoles.publishedAt) { @@ -150,8 +151,14 @@ module.exports = { if(!data.publishedAt && data.titre && data.transcription) { strapi.service('api::parole.parole').validateParoles(data.titre, data.transcription) if (data.titre && !data.forceSlug) { - const artiste = await jwennAwtisEpiId(data.artistes.connect) - data.slug = getSlug(artiste, data.titre) + let artistes + if (data.artistes.connect.length === 0) { + artistes = previousParoles.artistes.map(a => a.alias).join('-') + } else { + artistes = await jwennAwtisEpiId(data.artistes.connect) + } + + data.slug = getSlug(artistes, data.titre) } }