import { Router } from 'express'; import { PrismaClient } from '@prisma/client'; const router = Router(); const prisma = new PrismaClient(); // GET all host configurations router.get('/hosts', async (req, res) => { try { const hosts = await prisma.hostConfig.findMany(); res.json({ status: 'success', hosts }); } catch (error) { res.status(500).json({ status: 'error', message: 'Failed to fetch host configs' }); } }); // POST a new host configuration router.post('/hosts', async (req, res) => { try { const host = await prisma.hostConfig.create({ data: req.body }); res.json({ status: 'success', host }); } catch (error) { res.status(400).json({ status: 'error', message: 'Failed to create host config. Ensure name is unique.' }); } }); // PUT (update) a host configuration router.put('/hosts/:id', async (req, res) => { try { const host = await prisma.hostConfig.update({ where: { id: req.params.id }, data: req.body, }); res.json({ status: 'success', host }); } catch (error) { res.status(400).json({ status: 'error', message: 'Failed to update host config' }); } }); // DELETE a host configuration router.delete('/hosts/:id', async (req, res) => { try { await prisma.hostConfig.delete({ where: { id: req.params.id } }); res.json({ status: 'success' }); } catch (error) { res.status(400).json({ status: 'error', message: 'Failed to delete host config' }); } }); export default router;