mongoose-voting icon indicating copy to clipboard operation
mongoose-voting copied to clipboard

score?

Open ralyodio opened this issue 11 years ago • 9 comments

is there a way to tell the score?

Like if a post has 3 downvotes and 1 upvote the "score" would be -2.

ralyodio avatar Jun 09 '14 05:06 ralyodio

@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.

cristiandouce avatar Jun 09 '14 14:06 cristiandouce

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.

ralyodio avatar Jun 09 '14 17:06 ralyodio

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!

johnstonmatt avatar Sep 02 '14 22:09 johnstonmatt

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.

cristiandouce avatar Sep 07 '14 12:09 cristiandouce

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.

johnstonmatt avatar Sep 08 '14 15:09 johnstonmatt

Sure, thanks! Any PR would be reviewed and very welcome! :grinning:

cristiandouce avatar Sep 08 '14 16:09 cristiandouce

I think that virtual is could be a better fit for your needs

AlmogBaku avatar Jan 10 '15 15:01 AlmogBaku

Please merge https://github.com/cristiandouce/mongoose-voting/issues/9

bonesoul avatar May 09 '16 10:05 bonesoul

@raistlinthewiz will take a look tonight.

cristiandouce avatar May 09 '16 13:05 cristiandouce