2017-07-09 20:38:57 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const passport = require('../../lib/passport');
|
|
|
|
const _ = require('../../lib/translate')._;
|
2017-07-09 21:16:47 +00:00
|
|
|
const reports = require('../../models/reports');
|
|
|
|
const reportProcessor = require('../../lib/report-processor');
|
2017-07-09 20:38:57 +00:00
|
|
|
|
|
|
|
const router = require('../../lib/router-async').create();
|
|
|
|
|
|
|
|
|
2017-07-09 21:16:47 +00:00
|
|
|
router.getAsync('/reports/:reportId', passport.loggedIn, async (req, res) => {
|
2017-07-11 09:28:44 +00:00
|
|
|
const report = await reports.getByIdWithUserFields(req.params.reportId);
|
2017-07-09 21:16:47 +00:00
|
|
|
report.hash = reports.hash(report);
|
|
|
|
return res.json(report);
|
2017-07-09 20:38:57 +00:00
|
|
|
});
|
|
|
|
|
2017-07-09 21:16:47 +00:00
|
|
|
router.postAsync('/reports', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
|
|
|
await reports.create(req.body);
|
2017-07-09 20:38:57 +00:00
|
|
|
return res.json();
|
|
|
|
});
|
|
|
|
|
2017-07-09 21:16:47 +00:00
|
|
|
router.putAsync('/reports/:reportId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
|
|
|
const report = req.body;
|
|
|
|
report.id = parseInt(req.params.reportId);
|
2017-07-09 20:38:57 +00:00
|
|
|
|
2017-07-09 21:16:47 +00:00
|
|
|
await reports.updateWithConsistencyCheck(report);
|
2017-07-09 20:38:57 +00:00
|
|
|
return res.json();
|
|
|
|
});
|
|
|
|
|
2017-07-09 21:16:47 +00:00
|
|
|
router.deleteAsync('/reports/:reportId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
|
|
|
await reports.remove(req.params.reportId);
|
2017-07-09 20:38:57 +00:00
|
|
|
return res.json();
|
|
|
|
});
|
|
|
|
|
2017-07-09 21:16:47 +00:00
|
|
|
router.postAsync('/reports-table', passport.loggedIn, async (req, res) => {
|
|
|
|
return res.json(await reports.listDTAjax(req.body));
|
2017-07-09 20:38:57 +00:00
|
|
|
});
|
|
|
|
|
2017-07-09 21:16:47 +00:00
|
|
|
router.postAsync('/report-start/:id', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
|
|
|
await reportProcessor.start(req.params.id);
|
|
|
|
// TODO
|
|
|
|
});
|
|
|
|
|
|
|
|
router.postAsync('/report-stop/:id', async (req, res) => {
|
|
|
|
await reportProcessor.stop(req.params.id);
|
|
|
|
// TODO
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-07-09 20:38:57 +00:00
|
|
|
|
|
|
|
module.exports = router;
|