34 lines
836 B
JavaScript
34 lines
836 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, where: { alias: type }, attributes: [],
|
|
});
|
|
|
|
findOptions.where = Object.assign({},
|
|
findOptions.where, {
|
|
state: 'publish'
|
|
});
|
|
|
|
try {
|
|
return await models.Entity.findAndCountAll(findOptions);
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
module.exports = generateService(models.Entity, extraMethods); |