Skip to content

Commit

Permalink
New quotes are now added with max num_views
Browse files Browse the repository at this point in the history
  • Loading branch information
Jneville0815 committed Jan 2, 2024
1 parent 53c4ab5 commit f4551e6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions routes/userInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,16 @@ router.post('/:id/dailyReset', verify, async (req, res) => {
})

router.post('/:id/addQuote', verify, async (req, res) => {
const user = await User.findOne({ _id: req.params.id })

const views = user.quotes.map(quote => quote.num_views)

const quote = {
source: req.body.source,
quote: req.body.quote,
num_views: Math.max(...views)
}

const user = await User.findOne({ _id: req.params.id })

try {
user.quotes.push(quote)
user.save()
Expand Down

0 comments on commit f4551e6

Please sign in to comment.