Vulcan/packages/vulcan-voting/lib/modules/custom_fields.js

39 lines
889 B
JavaScript
Raw Normal View History

import { Connectors } from 'meteor/vulcan:core'; // import from vulcan:lib because vulcan:core isn't loaded yet
2017-09-29 09:19:23 +09:00
import Users from 'meteor/vulcan:users';
import Votes from './votes/collection.js';
2016-12-12 16:48:49 +09:00
Users.addField([
/**
An array containing votes
*/
{
fieldName: 'votes',
fieldSchema: {
type: Array,
optional: true,
2018-06-22 20:55:22 +09:00
canRead: Users.owns,
2017-07-08 11:36:27 +09:00
resolveAs: {
2017-07-08 11:43:49 +09:00
type: '[Vote]',
arguments: 'collectionName: String',
resolver: async (user, args, context) => {
const selector = {userId: user._id};
if (args.collectionName) {
selector.collectionName = args.collectionName;
}
const votes = await Connectors.find(Votes, selector);
return votes;
2017-07-08 11:36:27 +09:00
}
},
}
},
{
fieldName: 'votes.$',
fieldSchema: {
type: Object,
optional: true
}
},
]);
2016-02-17 12:54:18 +09:00