Files
nuitdelinfo2023/api/routes/themes.js
2023-12-08 02:31:33 +01:00

27 lines
963 B
JavaScript

import express from 'express';
import { verifyToken } from '../modules/token.js';
import { respondWithStatus, respondWithStatusJSON } from '../modules/requestHandler.js';
import { pool } from '../modules/database.js';
const router = express.Router();
// send list of themes
router.get('/', verifyToken, async (req, res) => {
const [rows] = await pool.execute('SELECT * FROM themes');
if (!rows.length) return await respondWithStatus(res, 404, 'There are no themes');
return await respondWithStatusJSON(res, 200, {
message: 'Successfully retrieved themes',
themes: rows,
});
});
router.get('/:id', verifyToken, async (req, res) => {
const [rows] = await pool.execute('SELECT * FROM themes WHERE id = ? LIMIT 1', [req.params.id]);
if (!rows.length) return await respondWithStatus(res, 404, 'Theme not found');
return await respondWithStatusJSON(res, 200, {
message: 'Successfully retrieved theme',
themes: rows[0],
});
});
export default router;