aboutsummaryrefslogtreecommitdiff
path: root/api/routes/quotes.js
diff options
context:
space:
mode:
authorAndrew Lee <andrew@alee14.me>2025-01-11 18:02:05 -0500
committerAndrew Lee <andrew@alee14.me>2025-01-11 18:02:05 -0500
commit7e65ae0e135098acad76b8081f34478b4efc077f (patch)
treeb7efc060fca4257a875a5a3e525e2733b6579040 /api/routes/quotes.js
parentf5de90ba89146008af78c16e798e216efccf0c50 (diff)
downloadAleeBot-7e65ae0e135098acad76b8081f34478b4efc077f.tar.gz
AleeBot-7e65ae0e135098acad76b8081f34478b4efc077f.tar.bz2
AleeBot-7e65ae0e135098acad76b8081f34478b4efc077f.zip
Cleaned up some code, author image now support attachments
Diffstat (limited to 'api/routes/quotes.js')
-rw-r--r--api/routes/quotes.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/api/routes/quotes.js b/api/routes/quotes.js
new file mode 100644
index 0000000..39aba7b
--- /dev/null
+++ b/api/routes/quotes.js
@@ -0,0 +1,58 @@
+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('/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;