Fix artiste error when updating
This commit is contained in:
@@ -26,6 +26,7 @@ const isSlugExists = async existingSlug => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const jwennAwtisEpiId = async artistesIds => {
|
const jwennAwtisEpiId = async artistesIds => {
|
||||||
|
console.log('artistesIds', artistesIds)
|
||||||
if (artistesIds.length === 0) {
|
if (artistesIds.length === 0) {
|
||||||
throw new ValidationError('Champ obligatoire. Veuillez choisir au moins un artiste.');
|
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({
|
const previousParoles = await strapi.db.query('api::parole.parole').findOne({
|
||||||
where: {id},
|
where: {id},
|
||||||
populate: {difference: true}
|
populate: {difference: true, artistes: true}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (data.transcription && previousParoles.publishedAt) {
|
if (data.transcription && previousParoles.publishedAt) {
|
||||||
@@ -150,8 +151,14 @@ module.exports = {
|
|||||||
if(!data.publishedAt && data.titre && data.transcription) {
|
if(!data.publishedAt && data.titre && data.transcription) {
|
||||||
strapi.service('api::parole.parole').validateParoles(data.titre, data.transcription)
|
strapi.service('api::parole.parole').validateParoles(data.titre, data.transcription)
|
||||||
if (data.titre && !data.forceSlug) {
|
if (data.titre && !data.forceSlug) {
|
||||||
const artiste = await jwennAwtisEpiId(data.artistes.connect)
|
let artistes
|
||||||
data.slug = getSlug(artiste, data.titre)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user