Add komante collections

This commit is contained in:
Cédric FAMIBELLE-PRONZOLA
2021-06-22 21:45:40 +02:00
parent 0669b0b9e1
commit 2c57aa87df
10 changed files with 1673 additions and 1 deletions
+39
View File
@@ -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
)
}
}
}
};
+35
View File
@@ -0,0 +1,35 @@
{
"kind": "collectionType",
"collectionName": "komante",
"info": {
"name": "komante",
"description": ""
},
"options": {
"increments": true,
"timestamps": true,
"draftAndPublish": true,
"privateAttributes": [
"createdAt",
"updatedAt"
]
},
"attributes": {
"kontni": {
"type": "richtext",
"required": true
},
"user": {
"plugin": "users-permissions",
"model": "user"
},
"teks": {
"model": "teks",
"via": "komante"
},
"sentAt": {
"type": "datetime",
"required": true
}
}
}