mirror of
https://github.com/vale981/Vulcan
synced 2025-03-09 12:16:37 -04:00
38 lines
1,018 B
JavaScript
38 lines
1,018 B
JavaScript
import Posts from "meteor/vulcan:posts";
|
|
import { getCategoriesAsOptions } from './schema.js';
|
|
|
|
Posts.addField([
|
|
{
|
|
fieldName: 'categories',
|
|
fieldSchema: {
|
|
type: Array,
|
|
control: "checkboxgroup",
|
|
optional: true,
|
|
insertableBy: ['members'],
|
|
editableBy: ['members'],
|
|
viewableBy: ['guests'],
|
|
form: {
|
|
noselect: true,
|
|
type: "bootstrap-category",
|
|
order: 50,
|
|
options: formProps => getCategoriesAsOptions(formProps.client),
|
|
},
|
|
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
|
|
}
|
|
}
|
|
]);
|