app2-api/modules/entities/entity.service.js
2019-07-17 14:44:15 +02:00

33 lines
754 B
JavaScript

/* global Venue */
'use strict';
const _ = require('lodash');
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
const models = require('../../core/models');
const extraMethods = {
fetch: async (params, context) => {
const type = context.type;
const findOptions = parseParamsToFindOptions(params);
findOptions.include.push({
model: models.EntityType,
as: 'types',
where: { alias: type },
attributes: [],
});
try {
return await models.Entity.findAll(findOptions);
} catch (error) {
throw error;
}
}
};
module.exports = generateService(models.Entity, extraMethods);