Rename komant to commentaire
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
const jwennTeksEpiId = async teksId => {
|
||||
const paroles = await strapi.query('paroles').findOne({id: teksId})
|
||||
return paroles
|
||||
}
|
||||
|
||||
const jwennUserEpiId = async userId => {
|
||||
const user = await strapi.query('user', 'users-permissions').findOne({id: userId})
|
||||
return user
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
beforeCreate: async event => {
|
||||
let {data} = event
|
||||
|
||||
if (data.kontni && data.paroles && data.user) {
|
||||
const parole = await jwennTeksEpiId(data.parole)
|
||||
const user = await jwennUserEpiId(data.user)
|
||||
|
||||
if(!parole || !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
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"kind": "collectionType",
|
||||
"collectionName": "commentaires",
|
||||
"info": {
|
||||
"singularName": "commentaire",
|
||||
"pluralName": "commentaires",
|
||||
"displayName": "Commentaire",
|
||||
"description": ""
|
||||
},
|
||||
"options": {
|
||||
"draftAndPublish": true
|
||||
},
|
||||
"pluginOptions": {},
|
||||
"attributes": {
|
||||
"kontni": {
|
||||
"type": "richtext",
|
||||
"required": true
|
||||
},
|
||||
"sentAt": {
|
||||
"type": "datetime",
|
||||
"required": true
|
||||
},
|
||||
"user": {
|
||||
"type": "relation",
|
||||
"relation": "oneToOne",
|
||||
"target": "plugin::users-permissions.user"
|
||||
},
|
||||
"parole": {
|
||||
"type": "relation",
|
||||
"relation": "oneToOne",
|
||||
"target": "api::parole.parole"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const { createCoreController } = require('@strapi/strapi').factories;
|
||||
|
||||
module.exports = createCoreController('api::commentaire.commentaire')
|
||||
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const { createCoreRouter } = require('@strapi/strapi').factories;
|
||||
|
||||
module.exports = createCoreRouter('api::commentaire.commentaire')
|
||||
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const { createCoreService } = require('@strapi/strapi').factories;
|
||||
|
||||
module.exports = createCoreService('api::commentaire.commentaire');
|
||||
Reference in New Issue
Block a user