mongoose-voting
mongoose-voting copied to clipboard
score?
is there a way to tell the score?
Like if a post has 3 downvotes and 1 upvote the "score" would be -2.
@chovy ~~Not right now~~ (yes, but not by a single method). But I think I could add it by the night. It's been requested more than once.
You could get that number now by var score = comment.upvotes() - comment.downvotes().
This would allow you to weight those values any way you like.
Yeah, i started thinking last night, its more flexible by providing the arrays you do provides. Allows you to customize the display of a count in whatever way you want.
An option to include score would be really helpful, it would permit query.sort ('-score') which I think means sort from top voted. If you don't feel like it is a good fit, do you have any suggestions for implementation? I think I would like it to be updated on each .upvote() or .downvote(). Thanks for your work so far!
Hi @johnstonmatt. You could also have a pre save hook and do any transformation for the .score property on your model. You may as well define it the way you prefer as long as it's not attached to the plugin.
I was thinking on maybe supporting a function transformation at the config level for that. But it would end doing the same thing.
Let me know if that works fine.
A pre save hook sounds like exactly what I want, I'll try to implement that myself. Thanks for your help, and for sharing your work. If I make any interesting optimizations or discoveries in my implementation I will share them.
Sure, thanks! Any PR would be reviewed and very welcome! :grinning:
I think that virtual is could be a better fit for your needs
Please merge https://github.com/cristiandouce/mongoose-voting/issues/9
@raistlinthewiz will take a look tonight.