Adapt lifecycles commentaire with translation and fix send email
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const jwennTeksEpiId = async teksId => {
|
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
|
return paroles
|
||||||
}
|
}
|
||||||
|
|
||||||
const jwennUserEpiId = async userId => {
|
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
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -14,26 +14,26 @@ module.exports = {
|
|||||||
beforeCreate: async event => {
|
beforeCreate: async event => {
|
||||||
let {data} = 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 parole = await jwennTeksEpiId(data.parole)
|
||||||
const user = await jwennUserEpiId(data.user)
|
const user = await jwennUserEpiId(data.user)
|
||||||
|
|
||||||
if(!parole || !user) {
|
if(!parole || !user) {
|
||||||
throw strapi.errors.badRequest('Not found')
|
throw new NotFoundError('Introuvable')
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw strapi.errors.badRequest('Missing fields')
|
throw new ValidationError('Mauvaise requête')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
afterCreate: async data => {
|
afterCreate: async data => {
|
||||||
if (data.user) {
|
if (data.user) {
|
||||||
strapi.services.email.send(
|
strapi.plugins['email'].services.email.send({
|
||||||
process.env.SMTP_FROM,
|
from: process.env.SMTP_FROM,
|
||||||
process.env.SMTP_SEND_TO,
|
to: process.env.SMTP_SEND_TO,
|
||||||
`Nouveau commentaire de ${data.user.username}`,
|
subject: `Nouveau commentaire de ${data.user.username}`,
|
||||||
data.kontni
|
html: data.contenu
|
||||||
)
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user