Skip to content

Commit

Permalink
Delete quote api call added
Browse files Browse the repository at this point in the history
  • Loading branch information
Jneville0815 committed Jan 5, 2024
1 parent db87308 commit b56d7a0
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions routes/userInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,27 @@ router.post('/:id/addQuote', verify, async (req, res) => {
}
})

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

res.send(user.quotes)
})

router.get('/:id/getQuote', async (req, res) => {
router.delete('/:id/deleteQuote/:quoteId', verify, async (req, res) => {
const user = await User.findOne({ _id: req.params.id })
const quoteId = req.params.quoteId

try {
let i = user.quotes.findIndex((x) => x._id.toString() === quoteId)
user.quotes.splice(i, 1)
user.save()
res.send({ sent: true })
} catch (err) {
res.status(400).send(err)
}
})

router.get('/:id/getQuote', verify, async (req, res) => {
function getRandomObject(arr) {
if (arr.length === 0) {
return null
Expand Down Expand Up @@ -185,7 +199,7 @@ router.get('/:id/getQuote', async (req, res) => {

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

if(Math.random() > 0.25) {
if(Math.random() > 0.10) {
const median = getMedianOfViews(user.quotes)
let i = 0
while(true) {
Expand Down

0 comments on commit b56d7a0

Please sign in to comment.