73 lines
No EOL
1.7 KiB
JavaScript
73 lines
No EOL
1.7 KiB
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
const { analyticsRepository } = require('../repositories');
|
|
|
|
/**
|
|
* GET /api/plugins/financials/analytics
|
|
* Get comprehensive financial analytics
|
|
*/
|
|
router.get('/', async (req, res) => {
|
|
try {
|
|
const { site_id, start_date, end_date } = req.query;
|
|
|
|
if (!site_id) {
|
|
return res.status(400).json({
|
|
success: false,
|
|
error: 'Missing required parameter: site_id'
|
|
});
|
|
}
|
|
|
|
const options = {};
|
|
if (start_date) options.start_date = start_date;
|
|
if (end_date) options.end_date = end_date;
|
|
|
|
const analytics = await analyticsRepository.getFinancialAnalytics(site_id, options);
|
|
|
|
res.json({
|
|
success: true,
|
|
data: analytics,
|
|
message: 'Analytics retrieved successfully'
|
|
});
|
|
} catch (error) {
|
|
console.error('Failed to get analytics:', error);
|
|
res.status(500).json({
|
|
success: false,
|
|
error: 'Failed to retrieve analytics',
|
|
message: error.message
|
|
});
|
|
}
|
|
});
|
|
|
|
/**
|
|
* GET /api/plugins/financials/analytics/hoa
|
|
* Get HOA-specific metrics
|
|
*/
|
|
router.get('/hoa', async (req, res) => {
|
|
try {
|
|
const { site_id } = req.query;
|
|
|
|
if (!site_id) {
|
|
return res.status(400).json({
|
|
success: false,
|
|
error: 'Missing required parameter: site_id'
|
|
});
|
|
}
|
|
|
|
const metrics = await analyticsRepository.getHOAMetrics(site_id);
|
|
|
|
res.json({
|
|
success: true,
|
|
data: metrics,
|
|
message: 'HOA metrics retrieved successfully'
|
|
});
|
|
} catch (error) {
|
|
console.error('Failed to get HOA metrics:', error);
|
|
res.status(500).json({
|
|
success: false,
|
|
error: 'Failed to retrieve HOA metrics',
|
|
message: error.message
|
|
});
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|