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

55 lines
979 B
JavaScript
Raw Normal View History

2016-06-23 11:40:35 +09:00
import Posts from "meteor/nova:posts";
2016-06-23 15:00:58 +09:00
import Users from "meteor/nova:users";
const alwaysPublic = user => true;
Users.addField([
/**
Count of the user's comments
*/
{
fieldName: "__commentCount",
fieldSchema: {
type: Number,
optional: true,
publish: true,
defaultValue: 0,
viewableIf: alwaysPublic,
}
}
]);
2016-02-17 11:28:00 +09:00
Posts.addField([
/**
Count of the post's comments
*/
{
fieldName: "commentCount",
fieldSchema: {
type: Number,
optional: true,
2016-04-14 09:54:41 +09:00
publish: true,
defaultValue: 0,
viewableIf: alwaysPublic,
2016-02-17 11:28:00 +09:00
}
},
/**
An array containing the `_id`s of commenters
*/
{
fieldName: "commenters",
fieldSchema: {
type: [String],
optional: true,
publish: true,
join: {
joinAs: "commentersArray",
2016-02-26 13:05:12 +09:00
collection: () => Users,
2016-02-25 17:44:43 +09:00
limit: 4
},
resolveAs: 'commenters: [User]',
viewableIf: alwaysPublic,
2016-02-17 11:28:00 +09:00
}
}
]);