45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
const express = require('express');
|
|
const { protect } = require('../middleware/auth');
|
|
const database = require('../config/database');
|
|
const logger = require('../utils/logger');
|
|
|
|
const router = express.Router();
|
|
|
|
// Get healing actions
|
|
router.get('/', protect, async (req, res) => {
|
|
try {
|
|
const { page = 1, limit = 50, status, device_id } = req.query;
|
|
const offset = (page - 1) * limit;
|
|
|
|
let query = 'SELECT * FROM healing_actions WHERE 1=1';
|
|
const params = [];
|
|
|
|
if (status) {
|
|
query += ' AND status = ?';
|
|
params.push(status);
|
|
}
|
|
|
|
if (device_id) {
|
|
query += ' AND device_id = ?';
|
|
params.push(device_id);
|
|
}
|
|
|
|
query += ' ORDER BY created_at DESC LIMIT ? OFFSET ?';
|
|
params.push(parseInt(limit), offset);
|
|
|
|
const actions = await database.query(query, params);
|
|
|
|
res.json({
|
|
success: true,
|
|
data: actions
|
|
});
|
|
} catch (error) {
|
|
logger.error('Get healing actions error:', error);
|
|
res.status(500).json({
|
|
success: false,
|
|
message: 'Failed to get healing actions'
|
|
});
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|