Numeric conversions for all ids coming in as route req params. Infrastructure for proper error message when dependencies prevent entity deletion.
43 lines
No EOL
1.8 KiB
JavaScript
43 lines
No EOL
1.8 KiB
JavaScript
'use strict';
|
|
|
|
const passport = require('../../lib/passport');
|
|
const _ = require('../../lib/translate')._;
|
|
const reportTemplates = require('../../models/report-templates');
|
|
|
|
const router = require('../../lib/router-async').create();
|
|
const {castToInteger} = require('../../lib/helpers');
|
|
|
|
|
|
router.getAsync('/report-templates/:reportTemplateId', passport.loggedIn, async (req, res) => {
|
|
const reportTemplate = await reportTemplates.getById(req.context, castToInteger(req.params.reportTemplateId));
|
|
reportTemplate.hash = reportTemplates.hash(reportTemplate);
|
|
return res.json(reportTemplate);
|
|
});
|
|
|
|
router.postAsync('/report-templates', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
|
return res.json(await reportTemplates.create(req.context, req.body));
|
|
});
|
|
|
|
router.putAsync('/report-templates/:reportTemplateId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
|
const reportTemplate = req.body;
|
|
reportTemplate.id = castToInteger(req.params.reportTemplateId);
|
|
|
|
await reportTemplates.updateWithConsistencyCheck(req.context, reportTemplate);
|
|
return res.json();
|
|
});
|
|
|
|
router.deleteAsync('/report-templates/:reportTemplateId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
|
await reportTemplates.remove(req.context, castToInteger(req.params.reportTemplateId));
|
|
return res.json();
|
|
});
|
|
|
|
router.postAsync('/report-templates-table', passport.loggedIn, async (req, res) => {
|
|
return res.json(await reportTemplates.listDTAjax(req.context, req.body));
|
|
});
|
|
|
|
router.getAsync('/report-template-user-fields/:reportTemplateId', passport.loggedIn, async (req, res) => {
|
|
const userFields = await reportTemplates.getUserFieldsById(req.context, castToInteger(req.params.reportTemplateId));
|
|
return res.json(userFields);
|
|
});
|
|
|
|
module.exports = router; |