Add komante collections
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
const jwennTeksEpiId = async teksId => {
|
||||
const teks = await strapi.query('teks').find({_id: teksId})
|
||||
return teks
|
||||
}
|
||||
|
||||
const jwennUserEpiId = async userId => {
|
||||
const user = await strapi.query('user', 'users-permissions').find({_id: userId})
|
||||
return user
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
lifecycles: {
|
||||
beforeCreate: async data => {
|
||||
if (data.kontni && data.teks && data.user) {
|
||||
const teks = await jwennTeksEpiId(data.teks)
|
||||
const user = await jwennUserEpiId(data.user)
|
||||
|
||||
if(!teks.length > 0 || !user.length > 0) {
|
||||
throw strapi.errors.badRequest('Not found')
|
||||
}
|
||||
|
||||
} else {
|
||||
throw strapi.errors.badRequest('Missing fields')
|
||||
}
|
||||
},
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user