diff --git a/modules/comments/comment.model.js b/modules/comments/comment.model.js index a9adad9..88749ff 100644 --- a/modules/comments/comment.model.js +++ b/modules/comments/comment.model.js @@ -57,6 +57,15 @@ module.exports = function (sequelize, DataTypes) { } }); + Comment.addScope('onlyPosts', () => { + return { + where: { + entityName: 'post' + } + } + }); + + Comment.associate = function (models) { Comment.User = Comment.belongsTo(models.User, { foreignKey: 'userId', constraints: false, as: 'user' }); }; diff --git a/modules/comments/comment.routes.js b/modules/comments/comment.routes.js index 5196db2..6e232bd 100644 --- a/modules/comments/comment.routes.js +++ b/modules/comments/comment.routes.js @@ -75,6 +75,23 @@ routes.get('/admin/comments/events/:entityId', }), ); +routes.get('/admin/comments/posts/:entityId', + isAdministratorUser, + // PaginateMiddleware.middleware(), + SortMiddleware.middleware({ default: "createdAt" }), + commentController.find({ + scopes: ['defaultScope', 'onlyPosts'], + }), +); + +routes.get('/admin/comments/speakers/:entityId', + isAdministratorUser, + // PaginateMiddleware.middleware(), + SortMiddleware.middleware({ default: "createdAt" }), + commentController.find({ + scopes: ['defaultScope', 'onlySpeakers'], + }), +); // Borrado routes.delete('/admin/comments/:id',