Move and update models to content-types
This commit is contained in:
@@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user