feat: implement user authentication and login modal, refactor backend
This commit is contained in:
35
web/backend/routes/workers.js
Normal file
35
web/backend/routes/workers.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import express from 'express';
|
||||
import { readJSON, writeJSON } from '../utils/fileUtils.js';
|
||||
import { PATHS } from '../config/constants.js';
|
||||
import { basicAuthMiddleware } from '../middlewares/auth.js';
|
||||
import { broadcast } from '../services/websocket.js';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// Obtener workers (requiere autenticación - solo administradores)
|
||||
router.get('/', basicAuthMiddleware, (req, res) => {
|
||||
try {
|
||||
const workers = readJSON(PATHS.WORKERS, { items: [], general: {}, disabled: [] });
|
||||
res.json(workers);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Actualizar workers (requiere autenticación)
|
||||
router.put('/', basicAuthMiddleware, (req, res) => {
|
||||
try {
|
||||
const workers = req.body;
|
||||
if (writeJSON(PATHS.WORKERS, workers)) {
|
||||
broadcast({ type: 'workers_updated', data: workers });
|
||||
res.json({ success: true });
|
||||
} else {
|
||||
res.status(500).json({ error: 'Error guardando workers' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user