/
Krams
/
nodemon
Обзор
Документация
Войти
/
Krams
/
nodemon
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
backend/controllers/NodeController.js
80 строк
2 KB
Krams
first_commit
08 июн 2025, 12:17
08 июн 2025, 12:17
25d7395
Код
Авторство
О чём код?
import { getAllNodesNested, updateNode, getNodeById, getNodeLogsById, addNodeLog, deleteNodeLog, updateNodesInList } from '../services/NodeService.js'; // Получить все узлы вложенно export async function getAllNodesNestedController(req, res) { try { const data = await getAllNodesNested(); res.json(data); } catch (error) { res.status(500).json({ error: 'Ошибка при получении узлов' }); } } // Получить один узел по id export async function getNodeByIdController(req, res) { const { id } = req.params; console.log(id) try { const node = await getNodeById(id); console.log(node); res.json(node); } catch (error) { res.status(404).json({ error: 'Узел не найден' }); } } // Обновить узел export async function updateNodeController(req, res) { const id = parseInt(req.params.id, 10); const { mac, guid, state, comment } = req.body; if (!mac || !guid || typeof state !== 'string') { return res.status(400).json({ error: 'Неверные данные' }); } try { const result = await updateNode(id, { mac, guid, state, comment }); if (result.changes === 0) { return res.status(404).json({ error: 'Узел не найден' }); } res.json({ result }); } catch (error) { res.status(500).json({ error: 'Ошибка при обновлении узла' }); } } // Получить все логи узла по ID export async function getNodeLogsByIdController(req, res) { const { id } = req.params; console.log(id) try { const logs = await getNodeLogsById(id); console.log(logs); res.json(logs); } catch (error) { res.status(404).json({ error: 'Логи не найдены' }); } } // Добавить новый лог узла export async function addNodeLogController(req, res) { const { nodeId, mac, workerId, log } = req.body; const logId = await addNodeLog(nodeId, mac, workerId, log); res.json(logId); } // Удалить лог узла по ID export async function deleteNodeLogController(req, res) { const { id } = req.params; console.log(id); const result = await deleteNodeLog(id); res.json(result); } // Обновить узлы в списке export async function updateNodesInListController(req, res) { const { state, listId } = req.body; console.log(state, listId); const result = await updateNodesInList(state, listId); res.json(result); }