Vulcan/packages/nova-voting/lib/helpers.js
Xavier Cazalot 7f99b48953 devel - revert commits related to simpl-schema (#1537)
* Revert "add note link to issue in collection2 on mutation insert, remove debug console logs on mutation edit"

This reverts commit 7a15103de7.

* Revert "node simpl-schema + collection2-core: fix vote by specifying the right type of the array (dont use blackbox in the end!)"

This reverts commit e894c3224c.

* Revert "add graphql date type (fix problem with node simple schema), fix an update bug on date picker,  add edit check on custom post item, add `blackbox: true` for arrays field (validation problem with simple-schema)"

This reverts commit 9d84fbec98.

* Revert "use node `simpl-schema` by aldeed to replace `meteor/aldeed:simple-schema` ; use the meteor collection2 core package as recommended"

This reverts commit 016935f4fa.

* revert before node-simple-schema, fix obj.hasOwnProperty undefined error thrown by simple-schema & collection2

* CustomPostsItem: check on renderActions; withDocument/List: pollInterval 20seconds by default; DateTime form component enhancement + GraphQLDate type
2017-01-11 18:02:12 +01:00

24 lines
No EOL
906 B
JavaScript

/**
* @summary Check if a user has upvoted a document
* @param {Object} user
* @param {Object} document
* @returns {Boolean}
*/
const hasUpvoted = (user, document) => {
// note(apollo): check upvoters depending if the document is queried by mongo directly or fetched by an apollo resolver
return user && document.upvoters && !!document.upvoters.find(u => typeof u === 'string' ? u === user._id : u._id === user._id);
};
/**
* @summary Check if a user has downvoted a document
* @param {Object} user
* @param {Object} document
* @returns {Boolean}
*/
const hasDownvoted = (user, document) => {
// note(apollo): check downvoters depending if the document is queried by mongo directly or fetched by an apollo resolver
return user && document.downvoters && !!document.downvoters.find(u => typeof u === 'string' ? u === user._id : u._id === user._id);
};
export { hasUpvoted, hasDownvoted }