2020-12-18 19:23:21 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const slugify = require('slugify')
|
|
|
|
|
|
|
|
|
|
const jwennAwtisEpiId = async data => {
|
|
|
|
|
const awtis = await strapi.query('awtis').find({_id: data})
|
|
|
|
|
return awtis.map(a => a.alias).join('-')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
lifecycles: {
|
|
|
|
|
beforeCreate: async data => {
|
|
|
|
|
if (data.tit) {
|
|
|
|
|
const awtis = await jwennAwtisEpiId(data.awtis)
|
|
|
|
|
data.slug = slugify(`${awtis}-${data.tit}`, {lower: true, remove: /[*#+~.()'"!:@]/g})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
beforeUpdate: async (params, data) => {
|
|
|
|
|
if (data.tit) {
|
|
|
|
|
const awtis = await jwennAwtisEpiId(data.awtis)
|
|
|
|
|
data.slug = slugify(`${awtis}-${data.tit}`, {lower: true, remove: /[*#+~.()'"!:@]/g})
|
|
|
|
|
}
|
2021-05-24 18:57:12 +02:00
|
|
|
},
|
|
|
|
|
afterCreate: async data => {
|
|
|
|
|
if (data.user) {
|
|
|
|
|
strapi.services.email.send(
|
|
|
|
|
process.env.SMTP_FROM,
|
|
|
|
|
process.env.SMTP_SEND_TO,
|
|
|
|
|
`Nouveau texte de ${data.user.username} : "${data.tit}"`,
|
|
|
|
|
`Le titre "${data.tit}" a été soumis depuis le site.`
|
|
|
|
|
)
|
|
|
|
|
}
|
2020-12-18 19:23:21 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|