mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 04:26:41 -04:00
37 lines
770 B
JavaScript
37 lines
770 B
JavaScript
import Users from 'meteor/vulcan:users';
|
|
import Votes from './votes/collection.js';
|
|
|
|
Users.addField([
|
|
/**
|
|
An array containing votes
|
|
*/
|
|
{
|
|
fieldName: 'votes',
|
|
fieldSchema: {
|
|
type: Array,
|
|
optional: true,
|
|
viewableBy: Users.owns,
|
|
resolveAs: {
|
|
type: '[Vote]',
|
|
arguments: 'collectionName: String',
|
|
resolver: async (user, args, context) => {
|
|
const selector = {userId: user._id};
|
|
if (args.collectionName) {
|
|
selector.collectionName = args.collectionName;
|
|
}
|
|
const votes = Votes.find(selector).fetch();
|
|
return votes;
|
|
}
|
|
},
|
|
}
|
|
},
|
|
{
|
|
fieldName: 'votes.$',
|
|
fieldSchema: {
|
|
type: Object,
|
|
optional: true
|
|
}
|
|
},
|
|
]);
|
|
|
|
|