app2-api/modules/entities/entity.service.js

68 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-07-08 11:11:40 +00:00
/* global Venue */
'use strict';
const _ = require('lodash');
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
const models = require('../../core/models');
2019-07-10 17:26:22 +00:00
const extraMethods = {
fetch: async (params, context) => {
const type = context.type;
const findOptions = parseParamsToFindOptions(params);
console.log('ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZz');
console.log(findOptions);
// findOptions.where = { 'name': '(Colegio Cristo Rey)'};
switch (type) {
case 'college':
// findOptions.where = Object.assign({},
// findOptions.where, {
// 'EntityType.alias' : 'college'
// });
break;
case 'partner':
// findOptions.where = Object.assign({},
// findOptions.where, {
// date: {
// [Sequelize.Op.gte]: moment().startOf('day').utc(),
// [Sequelize.Op.lt]: moment().add(1, 'days').startOf('day').utc(),
// }
// });
break;
default:
break;
}
// Incluir
findOptions.include.push({
model: models.EntityType, where: { alias: 'college' }, attributes: ['name'],
});
// findOptions.include.push({
// model: models.EventType,
// });
// findOptions.include.push({
// model: models.Venue,
// });
findOptions.where = Object.assign({},
findOptions.where, {
state: 'publish'
});
try {
return await models.Entity.findAll(findOptions);
} catch (error) {
throw error;
}
}
};
2019-07-08 11:11:40 +00:00
module.exports = generateService(models.Entity, extraMethods);