Sergei 7d9e7e37bf Remove console.log statements and add structured logging
Created a centralized logger utility (src/utils/logger.js) that provides:
- Structured logging with context labels
- Log levels (ERROR, WARN, INFO, DEBUG)
- Environment-based log level control via LOG_LEVEL env variable
- Consistent timestamp and JSON data formatting

Removed console.log/error/warn statements from:
- All service files (mqtt, notifications, legacyAPI, email, storage, subscription-sync)
- All route handlers (auth, beneficiaries, deployments, webhook, admin, etc)
- Controllers (dashboard, auth, alarm)
- Database connection handler
- Main server file (index.js)

Preserved:
- Critical startup validation error for JWT_SECRET in index.js

Benefits:
- Production-ready logging that can be easily integrated with log aggregation services
- Reduced noise in production logs
- Easier debugging with structured context and data
- Configurable log levels per environment

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-29 11:58:06 -08:00

65 lines
1.6 KiB
JavaScript

const { supabase } = require('../config/supabase');
const { verifyToken } = require('../middleware/auth');
// POST: dashboard_list - get all deployments for dashboard
exports.list = async (req, res) => {
const { user_name, token, user_id, date } = req.body;
try {
// Get all deployments
const { data: deployments, error } = await supabase
.from('deployments')
.select('*')
.order('deployment_id', { ascending: true });
if (error) {
return res.status(500).json({ error: error.message });
}
return res.json(deployments);
} catch (error) {
return res.status(500).json({ error: error.message });
}
};
// POST: dashboard_single - get single deployment details
exports.single = async (req, res) => {
const { user_name, token, date, deployment_id, nonce } = req.body;
try {
// Get deployment
const { data: deployment, error } = await supabase
.from('deployments')
.select('*')
.eq('deployment_id', deployment_id)
.single();
if (error) {
return res.status(404).json({ error: 'Deployment not found' });
}
// Get devices for this deployment
const { data: devices } = await supabase
.from('devices')
.select('*')
.eq('deployment_id', deployment_id);
// Get deployment details
const { data: details } = await supabase
.from('deployment_details')
.select('*')
.eq('deployment_id', deployment_id)
.single();
return res.json({
deployment,
devices: devices || [],
details: details || null
});
} catch (error) {
return res.status(500).json({ error: error.message });
}
};