diff --git a/src/api/parole/content-types/parole/lifecycles.js b/src/api/parole/content-types/parole/lifecycles.js index 704e372..f6a12db 100644 --- a/src/api/parole/content-types/parole/lifecycles.js +++ b/src/api/parole/content-types/parole/lifecycles.js @@ -189,26 +189,28 @@ module.exports = { const user = await jwennUserEpiId(data?.user?.id) const userAdmin = await jwennUserAdminEpiId(data?.createdBy) const superAdmin = await jwennSuperAdminEpiId(data?.createdBy) - const traductionsId = data.traductions.id + const traductionsId = data?.traductions?.id - const result = await strapi.db.query('api::parole.parole').findOne({ - where: { - traductions: { - id: { - $eq: traductionsId + if (traductionsId) { + const result = await strapi.db.query('api::parole.parole').findOne({ + where: { + traductions: { + id: { + $eq: traductionsId + } } - } - }, - populate: {traductions: true, artistes: true} - }) - - if (superAdmin && data.traductionAuto && result.traductions.francais && (!result.traductions.anglais || !result.traductions.espagnol || !result.traductions.allemand || !result.traductions.italien)) { - const traductions = await strapi.service('api::parole.parole').translateLyrics(result.traductions.francais) - await strapi.entityService.update('api::parole.parole', result.id, { - data: { - traductions - } + }, + populate: {traductions: true, artistes: true} }) + + if (superAdmin && data.traductionAuto && result.traductions.francais && (!result.traductions.anglais || !result.traductions.espagnol || !result.traductions.allemand || !result.traductions.italien)) { + const traductions = await strapi.service('api::parole.parole').translateLyrics(result.traductions.francais) + await strapi.entityService.update('api::parole.parole', result.id, { + data: { + traductions + } + }) + } } if (user) {