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

60 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-03-23 16:27:59 +09:00
import Posts from "meteor/vulcan:posts";
import Users from "meteor/vulcan:users";
Users.addField([
/**
Count of the user's comments
*/
{
fieldName: "commentCount",
fieldSchema: {
type: Number,
optional: true,
defaultValue: 0,
viewableBy: ['guests'],
}
}
]);
2016-02-17 11:28:00 +09:00
Posts.addField([
/**
Count of the post's comments
*/
{
fieldName: "commentCount",
fieldSchema: {
type: Number,
optional: true,
defaultValue: 0,
viewableBy: ['guests'],
2016-02-17 11:28:00 +09:00
}
},
/**
An array containing the `_id`s of commenters
*/
{
fieldName: "commenters",
fieldSchema: {
type: Array,
2016-02-17 11:28:00 +09:00
optional: true,
2017-07-08 11:36:27 +09:00
resolveAs: {
fieldName: 'commenters',
type: '[User]',
resolver: async (post, args, {currentUser, Users}) => {
if (!post.commenters) return [];
const commenters = await Users.loader.loadMany(post.commenters);
return Users.restrictViewableFields(currentUser, Users, commenters);
},
},
viewableBy: ['guests'],
2016-02-17 11:28:00 +09:00
}
},
{
fieldName: "commenters.$",
fieldSchema: {
type: String,
optional: true
}
}
2016-02-17 11:28:00 +09:00
]);