Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
mudroljub committed Dec 13, 2024
1 parent 19494f2 commit 2e31835
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/services/QuoteService.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ const deleteQuote = async id => {

const applyVote = async(quoteId, newVote) => {
const quote = await Quote.findById(quoteId)
const { numberOfVotes, rating } = quote
if (!quote) throw new Error('Quote not found')

const { numberOfVotes, rating } = quote
const newRating = (rating * numberOfVotes + newVote) / (numberOfVotes + 1)

const newQuote = await Quote.findOneAndUpdate(
Expand All @@ -63,7 +64,6 @@ const applyVote = async(quoteId, newVote) => {
{ new: true }
)

if (!newQuote) throw new Error('Quote not found')
return newQuote
}

Expand Down

0 comments on commit 2e31835

Please sign in to comment.