/* global Post */
'use strict';

const _ = require('lodash');
const { generateService, parseParamsToFindOptions, _debugModelInfo } = require('../../helpers/service.helper');
const models = require('../../core/models');

const extraMethods = {
    afterCreate: async (post, values, context) => {
        return await post.setCategories(values.categories.map(category => category.id));
    },

    afterUpdate: async (post, values, context) => {
        return await post.setCategories(values.categories.map(category => category.id));
    },

}

module.exports = generateService(models.Post, extraMethods);