Move and update models to content-types

This commit is contained in:
Cédric FAMIBELLE-PRONZOLA
2022-05-12 04:20:00 +04:00
parent 2737770ff7
commit f08459ffad
9 changed files with 248 additions and 228 deletions
-39
View File
@@ -1,39 +0,0 @@
'use strict';
const jwennTeksEpiId = async teksId => {
const teks = await strapi.query('teks').findOne({id: teksId})
return teks
}
const jwennUserEpiId = async userId => {
const user = await strapi.query('user', 'users-permissions').findOne({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 || !user) {
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
@@ -1,35 +0,0 @@
{
"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": {
"via": "komante",
"model": "teks"
},
"sentAt": {
"type": "datetime",
"required": true
}
}
}