From 626063d65a5f2ded0ee607a83f734163fc3a591e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Sat, 14 May 2022 23:48:18 +0400 Subject: [PATCH] Adapt lifecycles commentaire with translation and fix send email --- .../content-types/commentaire/lifecycles.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/api/commentaire/content-types/commentaire/lifecycles.js b/src/api/commentaire/content-types/commentaire/lifecycles.js index b5dd87a..d64837d 100644 --- a/src/api/commentaire/content-types/commentaire/lifecycles.js +++ b/src/api/commentaire/content-types/commentaire/lifecycles.js @@ -1,12 +1,12 @@ 'use strict'; const jwennTeksEpiId = async teksId => { - const paroles = await strapi.query('paroles').findOne({id: teksId}) + const paroles = await strapi.db.query('api::parole.parole').findOne({id: teksId}) return paroles } const jwennUserEpiId = async userId => { - const user = await strapi.query('user', 'users-permissions').findOne({id: userId}) + const user = await strapi.db.query('plugin::users-permissions.user').findOne({id: userId}) return user } @@ -14,26 +14,26 @@ module.exports = { beforeCreate: async event => { let {data} = event - if (data.kontni && data.paroles && data.user) { + if (data.contenu && data.parole && data.user) { const parole = await jwennTeksEpiId(data.parole) const user = await jwennUserEpiId(data.user) if(!parole || !user) { - throw strapi.errors.badRequest('Not found') + throw new NotFoundError('Introuvable') } } else { - throw strapi.errors.badRequest('Missing fields') + throw new ValidationError('Mauvaise requĂȘte') } }, afterCreate: async data => { if (data.user) { - strapi.services.email.send( - process.env.SMTP_FROM, - process.env.SMTP_SEND_TO, - `Nouveau commentaire de ${data.user.username}`, - data.kontni - ) + strapi.plugins['email'].services.email.send({ + from: process.env.SMTP_FROM, + to: process.env.SMTP_SEND_TO, + subject: `Nouveau commentaire de ${data.user.username}`, + html: data.contenu + }) } } };