2026-03-22 14:55:33 -05:00
|
|
|
import { Router } from 'express';
|
|
|
|
|
import * as connService from '../services/connectionService';
|
2026-03-27 13:42:35 -05:00
|
|
|
import { ok } from '../types/index';
|
2026-03-22 14:55:33 -05:00
|
|
|
|
|
|
|
|
const router = Router();
|
|
|
|
|
|
|
|
|
|
// POST /api/connections
|
|
|
|
|
router.post('/', async (req, res, next) => {
|
|
|
|
|
try {
|
2026-03-22 21:35:10 -05:00
|
|
|
const { fromPortId, toPortId, color, label, edgeType } = req.body;
|
|
|
|
|
const conn = await connService.createConnection({ fromPortId, toPortId, color, label, edgeType });
|
2026-03-27 13:42:35 -05:00
|
|
|
res.status(201).json(ok(conn));
|
2026-03-22 14:55:33 -05:00
|
|
|
} catch (err) {
|
|
|
|
|
next(err);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-22 21:35:10 -05:00
|
|
|
// PUT /api/connections/:id
|
|
|
|
|
router.put('/:id', async (req, res, next) => {
|
|
|
|
|
try {
|
|
|
|
|
const { color, label, edgeType } = req.body;
|
|
|
|
|
const conn = await connService.updateConnection(req.params.id, { color, label, edgeType });
|
2026-03-27 13:42:35 -05:00
|
|
|
res.json(ok(conn));
|
2026-03-22 21:35:10 -05:00
|
|
|
} catch (err) {
|
|
|
|
|
next(err);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-22 14:55:33 -05:00
|
|
|
// DELETE /api/connections/:id
|
|
|
|
|
router.delete('/:id', async (req, res, next) => {
|
|
|
|
|
try {
|
|
|
|
|
await connService.deleteConnection(req.params.id);
|
2026-03-27 13:42:35 -05:00
|
|
|
res.json(ok(null));
|
2026-03-22 14:55:33 -05:00
|
|
|
} catch (err) {
|
|
|
|
|
next(err);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// DELETE /api/connections/ports/:p1/:p2 (remove link between two specific ports)
|
|
|
|
|
router.delete('/ports/:p1/:p2', async (req, res, next) => {
|
|
|
|
|
try {
|
|
|
|
|
await connService.deleteByPorts(req.params.p1, req.params.p2);
|
2026-03-27 13:42:35 -05:00
|
|
|
res.json(ok(null));
|
2026-03-22 14:55:33 -05:00
|
|
|
} catch (err) {
|
|
|
|
|
next(err);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default router;
|