CoreySutphin / reddit-clone

MIT License
1 stars 0 forks source link

Post score isn't being calculated correctly #36

Closed JosephWoodside closed 6 years ago

JosephWoodside commented 6 years ago

If a post has 3 upvotes and 1 downvote it's score is being calculated as 4, rather than 2. It looks like when downvotes are being calculated in the database they are being subtracted, allowing them to go below zero, so subtracting a negative number ends up adding downvotes to upvotes, resulting in the incorrect score.

A solution would be not let the number of downvotes be negative. Everytime a post is downvoted it should increment the downvotes.

CoreySutphin commented 6 years ago

Oh oops lol

CoreySutphin commented 6 years ago

Added a min value of 0 to post and comment upvotes/downvotes. Min downvote values were because I wiped the database improperly.