Merge branch 'master' of wopr.rodax-software.com:lqdvi/app2-api

This commit is contained in:
David Arranz 2019-08-21 20:04:18 +02:00
commit 1ae994b1ff
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

@ -26,12 +26,16 @@ module.exports = function (sequelize, DataTypes) {
},
link: {
type: DataTypes.STRING,
allowNull: false
allowNull: true
},
state: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: 'draft'
},
summary: {
type: DataTypes.STRING,
allowNull: true
},
}, {
tableName: 'posts',
@ -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,
}]
}
});