This commit is contained in:
David Arranz 2019-08-28 14:00:59 +02:00
parent d1cbf79c26
commit fc43cee157
2 changed files with 4 additions and 4 deletions

View File

@ -365,12 +365,12 @@ module.exports = function (sequelize, DataTypes) {
}
});
Event.addScope('onlyOfCity', (city) => {
Event.addScope('onlyOfLocation', (location) => {
return {
include: [{
model: sequelize.models.Location, as: 'location',
where: { city: {[Sequelize.Op.eq]: city} },
}],
where: { locationId: { [Sequelize.Op.eq]: location } },
}
});

View File

@ -29,13 +29,13 @@ routes.get('/events',
PaginateMiddleware.middleware(),
SortMiddleware.middleware({ default: "-init_date" }),
(req, res, next) => {
if (!req.body.city)
if (!req.body.locationId)
return eventController.find({
scopes: ['defaultScope', 'includeVenue', 'includeMultimedias', 'includeDetails'],
})(req, res, next)
else
return eventController.find({
scopes: ['defaultScope', 'includeVenue', 'includeMultimedias', 'includeDetails', { method: ['onlyOfCity', req.body.city] }]
scopes: ['defaultScope', 'includeVenue', 'includeMultimedias', 'includeDetails', { method: ['onlyOfLocation', req.body.locationId] }]
})(req, res, next);
}
);