diff options
Diffstat (limited to 'bot/src/api/routes')
| -rw-r--r-- | bot/src/api/routes/auth.js | 14 | ||||
| -rw-r--r-- | bot/src/api/routes/quotes.js | 18 | ||||
| -rw-r--r-- | bot/src/api/routes/settings.js | 10 |
3 files changed, 21 insertions, 21 deletions
diff --git a/bot/src/api/routes/auth.js b/bot/src/api/routes/auth.js index 224a2d1..81a3e40 100644 --- a/bot/src/api/routes/auth.js +++ b/bot/src/api/routes/auth.js @@ -6,7 +6,7 @@ import dotenv from 'dotenv'; dotenv.config(); // Check if required environment variables are set -const requiredEnvVars = ['JWT_SECRET', 'AUTH_USERNAME', 'AUTH_PASSWORD_HASH']; +const requiredEnvVars = ['JWT_SECRET', 'API_USERNAME', 'API_PASSWORD_HASH']; const missingVars = requiredEnvVars.filter(varName => !process.env[varName]); if (missingVars.length > 0) { console.error(`Missing required environment variables: ${missingVars.join(', ')}`); @@ -22,18 +22,18 @@ export function authRouter() { const { username, password } = req.body; if (!username || !password) { - return res.status(400).json({ error: 'Username and password are required' }); + return res.status(400).json({ message: 'Username and password are required' }); } // Check against environment variables if (username !== process.env.API_USERNAME) { - return res.status(401).json({ error: 'Invalid credentials' }); + return res.status(401).json({ message: 'Invalid credentials' }); } // Verify password const isPasswordValid = await bcrypt.compare(password, process.env.API_PASSWORD_HASH); if (!isPasswordValid) { - return res.status(401).json({ error: 'Invalid credentials' }); + return res.status(401).json({ message: 'Invalid credentials' }); } // Generate JWT token @@ -46,7 +46,7 @@ export function authRouter() { res.json({ token }); } catch (error) { console.error('Login error:', error); - res.status(500).json({ error: 'Internal server error' }); + res.status(500).json({ message: 'Internal server error' }); } }); @@ -58,7 +58,7 @@ export function verifyToken(req, res, next) { const authHeader = req.headers.authorization; if (!authHeader || !authHeader.startsWith('Bearer ')) { - return res.status(401).json({ error: 'No token provided' }); + return res.status(401).json({ message: 'Unauthorized' }); } const token = authHeader.split(' ')[1]; @@ -68,6 +68,6 @@ export function verifyToken(req, res, next) { req.user = decoded; next(); } catch { - return res.status(403).json({ error: 'Invalid or expired token' }); + return res.status(403).json({ message: 'Invalid or expired token' }); } } diff --git a/bot/src/api/routes/quotes.js b/bot/src/api/routes/quotes.js index 7f9f255..f362d7e 100644 --- a/bot/src/api/routes/quotes.js +++ b/bot/src/api/routes/quotes.js @@ -10,7 +10,7 @@ quoteRouter.get('/quotes/pending', verifyToken, async (req, res) => { res.json(quotes); } catch (error) { console.error('Error fetching quotes:', error); - res.status(500).send('Internal Server Error'); + res.status(500).send({ message: 'Internal Server Error' }); } }); @@ -24,10 +24,10 @@ quoteRouter.post('/quotes/add', verifyToken, async (req, res) => { year: year, submitter: submitterID }); - res.status(200).send('Added a new quote'); + res.status(200).send({ message: 'Added a new quote' }); } catch (error) { console.error('Something went wrong:', error); - res.status(500).send('Internal Server Error'); + res.status(500).send({ message: 'Internal Server Error' }); } }); @@ -44,13 +44,13 @@ quoteRouter.post('/quotes/approve', verifyToken, async (req, res) => { submitter: quote.submitterID }); await pendingQuote.destroy({ where: { id } }); - res.status(200).send('Quote approved'); + res.status(200).send({ message: 'Quote approved' }); } else { - res.status(404).send('Quote not found'); + res.status(404).send({ message: 'Quote not found' }); } } catch (error) { console.error('Error approving quote:', error); - res.status(500).send('Internal Server Error'); + res.status(500).send({ message: 'Internal Server Error' }); } }); @@ -60,12 +60,12 @@ quoteRouter.post('/quotes/reject', verifyToken, async (req, res) => { const quote = await pendingQuote.findByPk(id); if (quote) { await pendingQuote.destroy({ where: { id } }); - res.status(200).send('Quote rejected'); + res.status(200).send({ message: 'Quote rejected' }); } else { - res.status(404).send('Quote not found'); + res.status(404).send({ message: 'Quote not found' }); } } catch (error) { console.error('Error rejecting quote:', error); - res.status(500).send('Internal Server Error'); + res.status(500).send({ message: 'Internal Server Error' }); } }); diff --git a/bot/src/api/routes/settings.js b/bot/src/api/routes/settings.js index bdef633..794d302 100644 --- a/bot/src/api/routes/settings.js +++ b/bot/src/api/routes/settings.js @@ -6,7 +6,7 @@ import { verifyToken } from './auth.js'; export function settingsRouter(client) { const router = Router(); - router.get('/settings/guild/:id', verifyToken, async (req, res) => { + router.get('/settings/guilds/:id', verifyToken, async (req, res) => { try { const settings = await guildSettings.findOne({ where: { guildID: req.params.id } }); @@ -38,11 +38,11 @@ export function settingsRouter(client) { }); } catch (e) { console.error('Error fetching settings:', e); - res.status(500).send('Internal Server Error'); + res.status(500).send({ message: 'Internal Server Error' }); } }); - router.post('/settings/guild/:id', verifyToken, async (req, res) => { + router.post('/settings/guilds/:id', verifyToken, async (req, res) => { try { const guildID = req.params.id; const { ...newSettings } = req.body; @@ -51,11 +51,11 @@ export function settingsRouter(client) { const updatedSettings = await guildSettings.findOne({ where: { guildID: guildID } }); res.json(updatedSettings); } else { - res.status(404).send('Settings not found'); + res.status(404).send({ message: 'Settings not found' }); } } catch (e) { console.error('Error updating settings:', e); - res.status(500).send('Internal Server Error'); + res.status(500).send({ message: 'Internal Server Error' }); } }); |
