Technician
This commit is contained in:
@@ -68,4 +68,41 @@ router.post('/upload-logo', upload.single('logo'), async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/settings/:key — liefert einen einzelnen Settings-Wert
|
||||
router.get('/:key', async (req, res) => {
|
||||
try {
|
||||
const result = await pool.query(
|
||||
'SELECT value FROM settings WHERE key = $1',
|
||||
[req.params.key]
|
||||
);
|
||||
if (result.rows.length === 0) {
|
||||
return res.json({ key: req.params.key, value: null });
|
||||
}
|
||||
res.json({ key: req.params.key, value: result.rows[0].value });
|
||||
} catch (error) {
|
||||
console.error('Error fetching setting:', error);
|
||||
res.status(500).json({ error: 'Error fetching setting' });
|
||||
}
|
||||
});
|
||||
|
||||
// PUT /api/settings/:key — setzt einen Settings-Wert (upsert)
|
||||
router.put('/:key', express.json(), async (req, res) => {
|
||||
const { value } = req.body;
|
||||
if (typeof value !== 'string') {
|
||||
return res.status(400).json({ error: 'value must be a string' });
|
||||
}
|
||||
try {
|
||||
await pool.query(
|
||||
`INSERT INTO settings (key, value)
|
||||
VALUES ($1, $2)
|
||||
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value`,
|
||||
[req.params.key, value]
|
||||
);
|
||||
res.json({ success: true, key: req.params.key, value });
|
||||
} catch (error) {
|
||||
console.error('Error saving setting:', error);
|
||||
res.status(500).json({ error: 'Error saving setting' });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user