mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 04:26:41 -04:00
59 lines
1.2 KiB
JavaScript
59 lines
1.2 KiB
JavaScript
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'],
|
|
}
|
|
}
|
|
]);
|
|
|
|
Posts.addField([
|
|
/**
|
|
Count of the post's comments
|
|
*/
|
|
{
|
|
fieldName: "commentCount",
|
|
fieldSchema: {
|
|
type: Number,
|
|
optional: true,
|
|
defaultValue: 0,
|
|
viewableBy: ['guests'],
|
|
}
|
|
},
|
|
/**
|
|
An array containing the `_id`s of commenters
|
|
*/
|
|
{
|
|
fieldName: "commenters",
|
|
fieldSchema: {
|
|
type: Array,
|
|
optional: true,
|
|
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'],
|
|
}
|
|
},
|
|
{
|
|
fieldName: "commenters.$",
|
|
fieldSchema: {
|
|
type: String,
|
|
optional: true
|
|
}
|
|
}
|
|
]);
|