48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
/* global Venue */
|
|
'use strict';
|
|
|
|
const _ = require('lodash');
|
|
const moment = require('moment');
|
|
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
|
|
const Sequelize = require('sequelize');
|
|
const models = require('../../core/models');
|
|
|
|
const extraMethods = {
|
|
fetchNext: async (params, context) => {
|
|
const findOptions = parseParamsToFindOptions(params);
|
|
|
|
findOptions.where.push({
|
|
date: {
|
|
[Sequelize.Op.gte]: moment().add(1, 'days').startOf('day').utc()
|
|
}
|
|
});
|
|
|
|
|
|
// Incluir
|
|
findOptions.include.push({
|
|
model: models.EventSchedule,
|
|
});
|
|
findOptions.include.push({
|
|
model: models.EventType,
|
|
});
|
|
findOptions.include.push({
|
|
model: models.Venue,
|
|
});
|
|
|
|
|
|
// Solo eventos publicados
|
|
findOptions.where.push({
|
|
state: 'publish'
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
return await models.Event.findAll(findOptions);
|
|
} catch(error) {
|
|
throw error;
|
|
}
|
|
}
|
|
};
|
|
|
|
module.exports = generateService(models.Event, extraMethods); |