2017-03-16 01:25:08 +08:00
|
|
|
import SimpleSchema from 'simpl-schema';
|
|
|
|
|
2017-09-29 09:19:23 +09:00
|
|
|
import Users from 'meteor/vulcan:users';
|
|
|
|
|
2016-12-12 16:48:49 +09:00
|
|
|
/**
|
|
|
|
* @summary Vote schema
|
|
|
|
* @type {SimpleSchema}
|
|
|
|
*/
|
|
|
|
const voteSchema = new SimpleSchema({
|
|
|
|
itemId: {
|
|
|
|
type: String
|
|
|
|
},
|
|
|
|
power: {
|
|
|
|
type: Number,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
votedAt: {
|
2017-03-16 01:25:08 +08:00
|
|
|
type: Date,
|
2016-12-12 16:48:49 +09:00
|
|
|
optional: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-08 16:33:25 +09:00
|
|
|
Users.addField([
|
|
|
|
/**
|
|
|
|
An array containing comments upvotes
|
|
|
|
*/
|
|
|
|
{
|
2017-01-18 10:18:33 +09:00
|
|
|
fieldName: 'upvotedComments',
|
2016-11-08 16:33:25 +09:00
|
|
|
fieldSchema: {
|
2017-03-16 01:25:08 +08:00
|
|
|
type: Array,
|
2016-11-08 16:33:25 +09:00
|
|
|
optional: true,
|
2017-04-29 12:33:05 +09:00
|
|
|
viewableBy: Users.owns,
|
2017-07-08 11:36:27 +09:00
|
|
|
resolveAs: {
|
|
|
|
fieldName: 'upvotedComments',
|
2017-07-08 11:43:49 +09:00
|
|
|
type: '[Vote]',
|
2017-07-08 11:36:27 +09:00
|
|
|
resolver: async (user, args, {currentUser, Users, Comments}) => {
|
|
|
|
if (!user.upvotedComments) return [];
|
|
|
|
const comments = await Comments.loader.loadMany(user.upvotedComments);
|
|
|
|
return Users.restrictViewableFields(currentUser, Comments, comments);
|
|
|
|
}
|
|
|
|
},
|
2016-11-08 16:33:25 +09:00
|
|
|
}
|
|
|
|
},
|
2017-03-16 01:25:08 +08:00
|
|
|
{
|
|
|
|
fieldName: 'upvotedComments.$',
|
|
|
|
fieldSchema: {
|
|
|
|
type: voteSchema,
|
|
|
|
optional: true
|
|
|
|
}
|
|
|
|
},
|
2016-11-08 16:33:25 +09:00
|
|
|
/**
|
|
|
|
An array containing posts upvotes
|
|
|
|
*/
|
|
|
|
{
|
2017-01-18 10:18:33 +09:00
|
|
|
fieldName: 'upvotedPosts',
|
2016-11-08 16:33:25 +09:00
|
|
|
fieldSchema: {
|
2017-03-16 01:25:08 +08:00
|
|
|
type: Array,
|
2016-11-08 16:33:25 +09:00
|
|
|
optional: true,
|
2017-04-29 12:33:05 +09:00
|
|
|
viewableBy: Users.owns,
|
2017-07-08 11:36:27 +09:00
|
|
|
resolveAs: {
|
|
|
|
fieldName: 'upvotedPosts',
|
2017-07-08 11:43:49 +09:00
|
|
|
type: '[Vote]',
|
2017-07-08 11:36:27 +09:00
|
|
|
resolver: async (user, args, {currentUser, Users, Posts}) => {
|
|
|
|
if (!user.upvotedPosts) return [];
|
|
|
|
const posts = await Posts.loader.loadMany(user.upvotedPosts);
|
|
|
|
return Users.restrictViewableFields(currentUser, Posts, posts);
|
|
|
|
}
|
|
|
|
},
|
2016-11-08 16:33:25 +09:00
|
|
|
}
|
|
|
|
},
|
2017-03-16 01:25:08 +08:00
|
|
|
{
|
|
|
|
fieldName: 'upvotedPosts.$',
|
|
|
|
fieldSchema: {
|
|
|
|
type: voteSchema,
|
|
|
|
optional: true
|
|
|
|
}
|
|
|
|
},
|
2016-11-08 16:33:25 +09:00
|
|
|
/**
|
|
|
|
An array containing comment downvotes
|
|
|
|
*/
|
|
|
|
{
|
2017-01-18 10:18:33 +09:00
|
|
|
fieldName: 'downvotedComments',
|
2016-11-08 16:33:25 +09:00
|
|
|
fieldSchema: {
|
2017-03-16 01:25:08 +08:00
|
|
|
type: Array,
|
2016-11-08 16:33:25 +09:00
|
|
|
optional: true,
|
2017-04-29 12:33:05 +09:00
|
|
|
viewableBy: Users.owns,
|
2017-07-08 11:36:27 +09:00
|
|
|
resolveAs: {
|
|
|
|
fieldName: 'downvotedComments',
|
2017-07-08 11:43:49 +09:00
|
|
|
type: '[Vote]',
|
2017-07-08 11:36:27 +09:00
|
|
|
resolver: async (user, args, {currentUser, Users, Comments}) => {
|
|
|
|
if (!user.downvotedComments) return [];
|
|
|
|
const comments = await Comments.loader.loadMany(user.downvotedComments);
|
|
|
|
return Users.restrictViewableFields(currentUser, Comments, comments);
|
|
|
|
}
|
|
|
|
},
|
2016-11-08 16:33:25 +09:00
|
|
|
}
|
|
|
|
},
|
2017-03-16 01:25:08 +08:00
|
|
|
{
|
|
|
|
fieldName: 'downvotedComments.$',
|
|
|
|
fieldSchema: {
|
|
|
|
type: voteSchema,
|
|
|
|
optional: true
|
|
|
|
}
|
|
|
|
},
|
2016-11-08 16:33:25 +09:00
|
|
|
/**
|
|
|
|
An array containing posts downvotes
|
|
|
|
*/
|
2017-03-16 01:25:08 +08:00
|
|
|
{
|
2017-01-18 10:18:33 +09:00
|
|
|
fieldName: 'downvotedPosts',
|
2016-11-08 16:33:25 +09:00
|
|
|
fieldSchema: {
|
2017-03-16 01:25:08 +08:00
|
|
|
type: Array,
|
2016-11-08 16:33:25 +09:00
|
|
|
optional: true,
|
2017-04-29 12:33:05 +09:00
|
|
|
viewableBy: Users.owns,
|
2017-07-08 11:36:27 +09:00
|
|
|
resolveAs: {
|
|
|
|
fieldName: 'downvotedPosts',
|
2017-07-08 11:43:49 +09:00
|
|
|
type: '[Vote]',
|
2017-07-08 11:36:27 +09:00
|
|
|
resolver: async (user, args, {currentUser, Users, Posts}) => {
|
|
|
|
if (!user.downvotedPosts) return [];
|
|
|
|
const posts = await Posts.loader.loadMany(user.downvotedPosts);
|
|
|
|
return Users.restrictViewableFields(currentUser, Posts, posts);
|
|
|
|
}
|
|
|
|
},
|
2016-11-08 16:33:25 +09:00
|
|
|
}
|
|
|
|
},
|
2017-03-16 01:25:08 +08:00
|
|
|
{
|
|
|
|
fieldName: 'downvotedPosts.$',
|
|
|
|
fieldSchema: {
|
|
|
|
type: voteSchema,
|
|
|
|
optional: true
|
|
|
|
}
|
|
|
|
}
|
2016-11-08 16:33:25 +09:00
|
|
|
]);
|
2016-02-17 12:54:18 +09:00
|
|
|
|
2017-01-11 18:02:12 +01:00
|
|
|
|