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, isAdministratorUser,
SortMiddleware.middleware({ default: "-date" }), SortMiddleware.middleware({ default: "-date" }),
blogController.find({ blogController.find({
scopes: ['includeAllStates'], scopes: ['includeMultimedias', 'includeCategories'],
}) })
); );
routes.get('/admin/posts/:id', isLoggedUser, routes.get('/admin/posts/:id', isLoggedUser,
isAdministratorUser, isAdministratorUser,
blogController.findOne() blogController.findOne({
scopes: ['includeMultimedias', 'includeCategories'],
})
); );
routes.get('/admin/posts/:id/comments', isLoggedUser, routes.get('/admin/posts/:id/comments', isLoggedUser,

View File

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