This commit is contained in:
David Arranz 2019-08-21 16:04:34 +02:00
parent 4af14ffb22
commit 5558ea1684
2 changed files with 16 additions and 9 deletions

View File

@ -45,13 +45,15 @@ routes.get('/admin/posts',
isAdministratorUser,
SortMiddleware.middleware({ default: "-date" }),
blogController.find({
scopes: ['includeAllStates'],
scopes: ['includeMultimedias', 'includeCategories'],
})
);
routes.get('/admin/posts/:id', isLoggedUser,
isAdministratorUser,
blogController.findOne()
blogController.findOne({
scopes: ['includeMultimedias', 'includeCategories'],
})
);
routes.get('/admin/posts/:id/comments', isLoggedUser,

View File

@ -20,13 +20,17 @@ module.exports = function (sequelize, DataTypes) {
type: DataTypes.STRING,
allowNull: false
},
summary: {
type: DataTypes.TEXT,
allowNull: false
},
content: {
type: DataTypes.TEXT,
allowNull: false
},
link: {
type: DataTypes.STRING,
allowNull: false
allowNull: true
},
state: {
type: DataTypes.STRING,
@ -65,14 +69,15 @@ module.exports = function (sequelize, DataTypes) {
foreignKey: 'entityId',
as: { singular: 'comment', plural: 'comments' }
});
};
Post.addScope('includeAllStates', () => {
return {
where: {
state: ['publish', 'draft']
},
Post.addScope('includeCategories', () => {
return {
include: [{
model: sequelize.models.Category,
as: 'categories',
required: false,
}]
}
});