2019-05-09 16:23:54 +00:00
|
|
|
/* global Post */
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const _ = require('lodash');
|
2019-05-23 09:40:50 +00:00
|
|
|
const { generateService, parseParamsToFindOptions, _debugModelInfo } = require('../../helpers/service.helper');
|
2019-05-09 16:23:54 +00:00
|
|
|
const models = require('../../core/models');
|
|
|
|
|
|
|
|
|
|
const extraMethods = {
|
2019-08-21 22:15:03 +00:00
|
|
|
afterCreate: async (post, values, context) => {
|
|
|
|
|
return await post.setCategories(values.categories.map(category => category.id));
|
|
|
|
|
},
|
2019-05-09 16:23:54 +00:00
|
|
|
|
2019-08-21 22:15:03 +00:00
|
|
|
afterUpdate: async (post, values, context) => {
|
|
|
|
|
return await post.setCategories(values.categories.map(category => category.id));
|
2019-05-23 09:40:50 +00:00
|
|
|
},
|
2019-05-09 16:23:54 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = generateService(models.Post, extraMethods);
|