feat(server): 添加公共路径认证中间件和批量操作功能
refactor(routes): 重新组织路由顺序并添加批量删除功能 - 在server.js中添加公共路径认证中间件 - 为cables、devicePorts等路由添加批量删除功能 - 重新组织路由顺序,将相关操作分组 - 添加工单导出功能
This commit is contained in:
+32
-30
@@ -500,36 +500,7 @@ router.put('/:cableId', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/:cableId', async (req, res) => {
|
||||
try {
|
||||
// 先获取接线信息,用于后续恢复端口状态
|
||||
const cable = await Cable.findByPk(req.params.cableId);
|
||||
|
||||
if (!cable) {
|
||||
return res.status(404).json({ error: '接线不存在' });
|
||||
}
|
||||
|
||||
const { sourceDeviceId, sourcePort, targetDeviceId, targetPort } = cable;
|
||||
|
||||
const deleted = await Cable.destroy({
|
||||
where: { cableId: req.params.cableId },
|
||||
});
|
||||
|
||||
if (deleted) {
|
||||
// 自动将源端口和目标端口状态恢复为free
|
||||
await freePort(sourceDeviceId, sourcePort);
|
||||
await freePort(targetDeviceId, targetPort);
|
||||
|
||||
res.status(204).json();
|
||||
} else {
|
||||
res.status(404).json({ error: '接线不存在' });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('删除接线失败:', error);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// 批量删除接线
|
||||
router.delete('/batch', async (req, res) => {
|
||||
try {
|
||||
const { cableIds } = req.body;
|
||||
@@ -563,6 +534,37 @@ router.delete('/batch', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 删除单个接线
|
||||
router.delete('/:cableId', async (req, res) => {
|
||||
try {
|
||||
// 先获取接线信息,用于后续恢复端口状态
|
||||
const cable = await Cable.findByPk(req.params.cableId);
|
||||
|
||||
if (!cable) {
|
||||
return res.status(404).json({ error: '接线不存在' });
|
||||
}
|
||||
|
||||
const { sourceDeviceId, sourcePort, targetDeviceId, targetPort } = cable;
|
||||
|
||||
const deleted = await Cable.destroy({
|
||||
where: { cableId: req.params.cableId },
|
||||
});
|
||||
|
||||
if (deleted) {
|
||||
// 自动将源端口和目标端口状态恢复为free
|
||||
await freePort(sourceDeviceId, sourcePort);
|
||||
await freePort(targetDeviceId, targetPort);
|
||||
|
||||
res.status(204).json();
|
||||
} else {
|
||||
res.status(404).json({ error: '接线不存在' });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('删除接线失败:', error);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/:cableId', async (req, res) => {
|
||||
try {
|
||||
const cable = await Cable.findByPk(req.params.cableId, {
|
||||
|
||||
Reference in New Issue
Block a user