Send email to user after publishing teks

This commit is contained in:
Cédric FAMIBELLE-PRONZOLA
2021-05-30 12:00:39 +02:00
parent 4ed4100553
commit 0284b78c51
2 changed files with 20 additions and 0 deletions
+2
View File
@@ -20,3 +20,5 @@ SMTP_PASSWORD=
SMTP_FROM= SMTP_FROM=
SMTP_REPLY_TO= SMTP_REPLY_TO=
SMTP_SEND_TO= SMTP_SEND_TO=
WEBSITE_URL=http://localhost:3000
+18
View File
@@ -20,6 +20,24 @@ module.exports = {
const awtis = await jwennAwtisEpiId(data.awtis) const awtis = await jwennAwtisEpiId(data.awtis)
data.slug = slugify(`${awtis}-${data.tit}`, {lower: true, remove: /[*#+~.()'"!:@]/g}) data.slug = slugify(`${awtis}-${data.tit}`, {lower: true, remove: /[*#+~.()'"!:@]/g})
} }
if (data.published_at != null) {
const {_id} = params
const previousData = await strapi.query('teks').findOne({_id})
const previousPublishedAt = previousData.published_at
const currentPublished_at = data.published_at
if (currentPublished_at != previousPublishedAt) {
if (previousData.user) {
strapi.services.email.send(
process.env.SMTP_FROM,
previousData.user.email,
`Publication de "${previousData.tit}"`,
`Le titre que vous avez soumis, "${previousData.tit}" a été publié sur le site.
Vous pouvez le trouver à l'adresse ${process.env.WEBSITE_URL}/teks/${previousData.slug}`
)
}
}
}
}, },
afterCreate: async data => { afterCreate: async data => {
if (data.user) { if (data.user) {