diff options
| author | Andrew Lee <andrew@alee14.me> | 2025-03-03 11:42:27 -0500 |
|---|---|---|
| committer | Andrew Lee <andrew@alee14.me> | 2025-03-03 11:42:27 -0500 |
| commit | fd7f8eba960981482fabf350995bf753feebb176 (patch) | |
| tree | 2bd0c85b09a04ecd8e1f20fc409eb4b8a22289a7 /bot/src/api/routes | |
| parent | cf1382d88c5e3298923c8cb243b7bc5751e68b53 (diff) | |
| download | AleeBot-fd7f8eba960981482fabf350995bf753feebb176.tar.gz AleeBot-fd7f8eba960981482fabf350995bf753feebb176.tar.bz2 AleeBot-fd7f8eba960981482fabf350995bf753feebb176.zip | |
More commands ported; Almost all 2.x features have been added
Diffstat (limited to 'bot/src/api/routes')
| -rw-r--r-- | bot/src/api/routes/quotes.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/bot/src/api/routes/quotes.js b/bot/src/api/routes/quotes.js new file mode 100644 index 0000000..d39bb28 --- /dev/null +++ b/bot/src/api/routes/quotes.js @@ -0,0 +1,70 @@ +import { Router } from 'express'; +import { pendingQuote, quote as newQuote } from '../../models/quote.js'; + +export const quoteRouter = Router(); + +quoteRouter.get('/quotes/pending', 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'); + } +}); + +quoteRouter.post('/quotes/add', async (req, res) => { + const { author, authorImage, quote, year, submitterID } = req.body; + try { + await newQuote.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'); + } +}); + +quoteRouter.post('/quotes/approve', async (req, res) => { + const { id } = req.body; + try { + const quote = await pendingQuote.findByPk(id); + if (quote) { + await newQuote.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'); + } +}); + +quoteRouter.post('/quotes/reject', 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'); + } +}); |
