diff options
Diffstat (limited to 'api/routes')
| -rw-r--r-- | api/routes/quotes.js | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/api/routes/quotes.js b/api/routes/quotes.js deleted file mode 100644 index 9c933f8..0000000 --- a/api/routes/quotes.js +++ /dev/null @@ -1,75 +0,0 @@ -const express = require('express'); -const quoteDB = require('../../models/quote.js'); - -const router = express.Router(); - -const pendingQuote = quoteDB.pendingQuote; -const approvedQuote = quoteDB.quote; - -router.get('/pending-quotes', async (req, res) => { - try { - const quotes = await pendingQuote.findAll(); - res.json(quotes); - } catch (error) { - console.error('Error fetching quotes:', error); - res.status(500).send('Internal Server Error'); - } -}); - -router.post('/add-quote', async (req, res) => { - const { author, authorImage, quote, year, submitterID } = req.body; - try { - await approvedQuote.create({ - author: author, - authorImage: authorImage, - quote: quote, - year: year, - submitter: submitterID - }); - res.status(200).send('Added a new quote'); - } catch (error) { - console.error('Something went wrong:', error); - res.status(500).send('Internal Server Error'); - } -}); - -router.post('/approve-quote', async (req, res) => { - const { id } = req.body; - try { - const quote = await pendingQuote.findByPk(id); - if (quote) { - await approvedQuote.create({ - author: quote.author, - authorImage: quote.authorImage, - quote: quote.quote, - year: quote.year, - submitter: quote.submitterID - }); - await pendingQuote.destroy({ where: { id } }); - res.status(200).send('Quote approved'); - } else { - res.status(404).send('Quote not found'); - } - } catch (error) { - console.error('Error approving quote:', error); - res.status(500).send('Internal Server Error'); - } -}); - -router.post('/reject-quote', async (req, res) => { - const { id } = req.body; - try { - const quote = await pendingQuote.findByPk(id); - if (quote) { - await pendingQuote.destroy({ where: { id } }); - res.status(200).send('Quote rejected'); - } else { - res.status(404).send('Quote not found'); - } - } catch (error) { - console.error('Error rejecting quote:', error); - res.status(500).send('Internal Server Error'); - } -}); - -module.exports = router; |
