Vulcan/packages/vulcan-categories/lib/custom_fields.js

39 lines
1,018 B
JavaScript
Raw Normal View History

2017-03-23 16:27:59 +09:00
import Posts from "meteor/vulcan:posts";
import { getCategoriesAsOptions } from './schema.js';
Posts.addField([
{
fieldName: 'categories',
fieldSchema: {
type: Array,
2016-02-25 17:44:43 +09:00
control: "checkboxgroup",
optional: true,
insertableBy: ['members'],
editableBy: ['members'],
viewableBy: ['guests'],
form: {
noselect: true,
type: "bootstrap-category",
2015-10-20 14:34:24 +09:00
order: 50,
options: formProps => getCategoriesAsOptions(formProps.client),
},
2017-07-08 11:36:27 +09:00
resolveAs: {
fieldName: 'categories',
type: '[Category]',
resolver: async (post, args, {currentUser, Users, Categories}) => {
if (!post.categories) return [];
const categories = _.compact(await Categories.loader.loadMany(post.categories));
return Users.restrictViewableFields(currentUser, Categories, categories);
}
}
}
},
{
fieldName: 'categories.$',
fieldSchema: {
type: String,
optional: true
}
}
]);