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) }