From a49792c64615ea87d94c3f875fa2e86361fbaceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Famibelle-Pronzola?= Date: Sat, 22 Jul 2023 11:15:54 +0400 Subject: [PATCH] Fix jwennAwtisEpiId error --- src/api/parole/content-types/parole/lifecycles.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/api/parole/content-types/parole/lifecycles.js b/src/api/parole/content-types/parole/lifecycles.js index 9507a33..131e1c6 100644 --- a/src/api/parole/content-types/parole/lifecycles.js +++ b/src/api/parole/content-types/parole/lifecycles.js @@ -28,7 +28,6 @@ const isSlugExists = async existingSlug => { } const jwennAwtisEpiId = async artistesIds => { - console.log('artistesIds', artistesIds) if (artistesIds.length === 0) { throw new ApplicationError('Champ obligatoire. Veuillez choisir au moins un artiste.'); } @@ -37,7 +36,7 @@ const jwennAwtisEpiId = async artistesIds => { select: ['alias'], where: { id: { - $in: artistesIds.map(({id}) => id) + $in: artistesIds.map(id => id) } } }) @@ -122,8 +121,18 @@ module.exports = { data.userAdmin = userAdmin } + let artistesIds = [] + + if (data?.artistes?.connect) { + for (const artiste of data.artistes.connect) { + artistesIds.push(artiste.id) + } + } else { + artistesIds = data.artistes + } + if (data.titre && !data.forceSlug) { - const artiste = await jwennAwtisEpiId(data.artistes.connect) + const artiste = await jwennAwtisEpiId(artistesIds) data.slug = getSlug(artiste, data.titre) }