The namespace filter in campaigns was dropped (i.e. "Work with campaign's namespace"). Instead, we need a universal solution. For instance a namespace slector somewhere in the top-right corner, which should apply to everything (not just campaigns). Nevertheless, I kept the ...-by-namespace rest endpoints and related functions in models because they will be useful for implementing the universal namespace selection feature.
48 lines
No EOL
1.9 KiB
JavaScript
48 lines
No EOL
1.9 KiB
JavaScript
'use strict';
|
|
|
|
const passport = require('../../lib/passport');
|
|
const templates = require('../../models/templates');
|
|
|
|
const router = require('../../lib/router-async').create();
|
|
const {castToInteger} = require('../../lib/helpers');
|
|
const CampaignSender = require('../../lib/campaign-sender');
|
|
|
|
|
|
router.getAsync('/templates/:templateId', passport.loggedIn, async (req, res) => {
|
|
const template = await templates.getById(req.context, castToInteger(req.params.templateId));
|
|
template.hash = templates.hash(template);
|
|
return res.json(template);
|
|
});
|
|
|
|
router.postAsync('/templates', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
|
return res.json(await templates.create(req.context, req.body));
|
|
});
|
|
|
|
router.putAsync('/templates/:templateId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
|
const template = req.body;
|
|
template.id = castToInteger(req.params.templateId);
|
|
|
|
await templates.updateWithConsistencyCheck(req.context, template);
|
|
return res.json();
|
|
});
|
|
|
|
router.deleteAsync('/templates/:templateId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
|
await templates.remove(req.context, castToInteger(req.params.templateId));
|
|
return res.json();
|
|
});
|
|
|
|
router.postAsync('/templates-table', passport.loggedIn, async (req, res) => {
|
|
return res.json(await templates.listDTAjax(req.context, req.body));
|
|
});
|
|
|
|
router.postAsync('/templates-by-namespace-table/:namespaceId', passport.loggedIn, async (req, res) => {
|
|
return res.json(await templates.listByNamespaceDTAjax(req.context, castToInteger(req.params.namespaceId), req.body));
|
|
});
|
|
|
|
router.postAsync('/template-test-send', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
|
const data = req.body;
|
|
const result = await CampaignSender.testSend(req.context, data.listCid, data.subscriptionCid, data.campaignId, data.sendConfigurationId, data.html, data.text);
|
|
return res.json(result);
|
|
});
|
|
|
|
module.exports = router; |