add Get Db_version

This commit is contained in:
2026-03-29 19:04:08 +02:00
parent c1c3e0d3d9
commit 589185c76c
3 changed files with 35 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
const db = require('../config/db');
async function getDatabaseVersion(req, res) {
try {
const [rows] = await db.execute(`
SELECT database_version, last_update
FROM db_version
ORDER BY last_update DESC
LIMIT 1
`);
if (rows.length === 0) {
return res.status(404).json({ error: 'No database version found' });
}
res.json(rows[0]);
} catch (err) {
console.error('Error fetching database version:', err);
res.status(500).json({ error: 'Failed to fetch database version' });
}
}
module.exports = { getDatabaseVersion };
+4 -1
View File
@@ -21,4 +21,7 @@ app.use('/cardImage', cardImageRoutes); // <-- mount the new card image route
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});
});
const versionRoutes = require('./routes/versionRoutes');
app.use('/db-version', versionRoutes);
+8
View File
@@ -0,0 +1,8 @@
const express = require('express');
const router = express.Router();
const { getDatabaseVersion } = require('../controllers/versionController');
// GET /db-version
router.get('/', getDatabaseVersion);
module.exports = router;