mirror of
https://github.com/vale981/Vulcan
synced 2025-03-07 02:21:43 -05:00
41 lines
999 B
JavaScript
41 lines
999 B
JavaScript
import Users from "meteor/vulcan:users";
|
|
|
|
Users.addField([
|
|
/**
|
|
Count of the user's posts
|
|
*/
|
|
{
|
|
fieldName: "postCount",
|
|
fieldSchema: {
|
|
type: Number,
|
|
optional: true,
|
|
defaultValue: 0,
|
|
viewableBy: ['guests'],
|
|
}
|
|
},
|
|
/**
|
|
The user's associated posts (GraphQL only)
|
|
*/
|
|
{
|
|
fieldName: "posts",
|
|
fieldSchema: {
|
|
type: Array,
|
|
optional: true,
|
|
viewableBy: ['guests'],
|
|
resolveAs: {
|
|
fieldName: 'posts',
|
|
arguments: 'limit: Int = 5',
|
|
type: '[Post]',
|
|
resolver: (user, { limit }, { currentUser, Users, Posts }) => {
|
|
const posts = Posts.find({ userId: user._id }, { limit }).fetch();
|
|
|
|
// restrict documents fields
|
|
const viewablePosts = _.filter(posts, post => Posts.checkAccess(currentUser, post));
|
|
const restrictedPosts = Users.restrictViewableFields(currentUser, Posts, viewablePosts);
|
|
|
|
return restrictedPosts;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]);
|