2018-03-03 11:39:56 +09:00
|
|
|
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';
|
2017-10-05 10:16:28 +09:00
|
|
|
import Votes from './votes/collection.js';
|
2016-12-12 16:48:49 +09:00
|
|
|
|
2016-11-08 16:33:25 +09:00
|
|
|
Users.addField([
|
|
|
|
/**
|
2017-10-05 10:16:28 +09:00
|
|
|
An array containing votes
|
2016-11-08 16:33:25 +09:00
|
|
|
*/
|
|
|
|
{
|
2017-10-05 10:16:28 +09:00
|
|
|
fieldName: 'votes',
|
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: {
|
2017-07-08 11:43:49 +09:00
|
|
|
type: '[Vote]',
|
2017-10-05 10:16:28 +09:00
|
|
|
arguments: 'collectionName: String',
|
|
|
|
resolver: async (user, args, context) => {
|
|
|
|
const selector = {userId: user._id};
|
|
|
|
if (args.collectionName) {
|
|
|
|
selector.collectionName = args.collectionName;
|
|
|
|
}
|
2018-03-03 11:39:56 +09:00
|
|
|
const votes = await Connectors.find(Votes, selector);
|
2017-10-05 10:16:28 +09:00
|
|
|
return votes;
|
2017-07-08 11:36:27 +09:00
|
|
|
}
|
|
|
|
},
|
2016-11-08 16:33:25 +09:00
|
|
|
}
|
|
|
|
},
|
2017-03-16 01:25:08 +08:00
|
|
|
{
|
2017-10-05 10:16:28 +09:00
|
|
|
fieldName: 'votes.$',
|
2017-03-16 01:25:08 +08:00
|
|
|
fieldSchema: {
|
2017-10-05 10:16:28 +09:00
|
|
|
type: Object,
|
2017-03-16 01:25:08 +08:00
|
|
|
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
|
|
|
|