import dashboardService from '../services/dashboardService.js'; function getHashedUserId(req) { return req.headers?.userid; } export default { async getConfig(req, res) { const hashedUserId = getHashedUserId(req); if (!hashedUserId) { return res.status(401).json({ error: 'Unauthorized' }); } try { const config = await dashboardService.getConfig(hashedUserId); res.json(config); } catch (error) { console.error('Dashboard getConfig:', error); res.status(500).json({ error: error.message || 'Internal server error' }); } }, async setConfig(req, res) { const hashedUserId = getHashedUserId(req); if (!hashedUserId) { return res.status(401).json({ error: 'Unauthorized' }); } const config = req.body; if (!config || typeof config !== 'object') { return res.status(400).json({ error: 'Invalid config' }); } try { const result = await dashboardService.setConfig(hashedUserId, config); res.json(result); } catch (error) { console.error('Dashboard setConfig:', error); res.status(500).json({ error: error.message || 'Internal server error' }); } } };