'use strict'; /** * Post.js controller * * @description: A set of functions called "actions" for managing `Post`. */ module.exports = function (modelService) { return { /** * Retrieve post records. * * @return {Object|Array} */ find: async (ctx) => { if (ctx.query._q) { return modelService.search(ctx.query); } else { return modelService.fetchAll(ctx.query); } }, /** * Retrieve a post record. * * @return {Object} */ findOne: async (ctx) => { return modelService.fetch(ctx.params); }, /** * Count post records. * * @return {Number} */ count: async (ctx) => { return modelService.count(ctx.query); }, /** * Create a/an post record. * * @return {Object} */ create: async (ctx) => { return modelService.add(ctx.request.body); }, /** * Update a/an post record. * * @return {Object} */ update: async (ctx, next) => { return modelService.edit(ctx.params, ctx.request.body); }, /** * Destroy a/an post record. * * @return {Object} */ destroy: async (ctx, next) => { return modelService.remove(ctx.params); } }; }