Comentarios para el blog

This commit is contained in:
David Arranz 2019-08-21 20:37:58 +02:00
parent dd8c6a38ff
commit 72946c6c01
2 changed files with 26 additions and 0 deletions

View File

@ -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' });
};

View File

@ -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',