2017-07-11 09:28:44 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const passport = require('../../lib/passport');
|
|
|
|
const campaigns = require('../../models/campaigns');
|
|
|
|
|
|
|
|
const router = require('../../lib/router-async').create();
|
|
|
|
|
|
|
|
|
|
|
|
router.postAsync('/campaigns-table', passport.loggedIn, async (req, res) => {
|
2017-08-13 18:11:58 +00:00
|
|
|
return res.json(await campaigns.listDTAjax(req.context, req.body));
|
2017-07-11 09:28:44 +00:00
|
|
|
});
|
|
|
|
|
2018-08-03 11:35:55 +00:00
|
|
|
router.postAsync('/campaigns-with-content-table', passport.loggedIn, async (req, res) => {
|
|
|
|
return res.json(await campaigns.listWithContentDTAjax(req.context, req.body));
|
|
|
|
});
|
|
|
|
|
2018-09-02 18:17:42 +00:00
|
|
|
router.postAsync('/campaigns-others-by-list-table/:campaignId/:listIds', passport.loggedIn, async (req, res) => {
|
|
|
|
return res.json(await campaigns.listOthersWhoseListsAreIncludedDTAjax(req.context, req.params.campaignId, req.params.listIds.split(';'), req.body));
|
2018-08-04 09:30:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-08-03 11:35:55 +00:00
|
|
|
router.getAsync('/campaigns-settings/:campaignId', passport.loggedIn, async (req, res) => {
|
|
|
|
const campaign = await campaigns.getById(req.context, req.params.campaignId, true, campaigns.Content.WITHOUT_SOURCE_CUSTOM);
|
|
|
|
campaign.hash = campaigns.hash(campaign, campaigns.Content.WITHOUT_SOURCE_CUSTOM);
|
|
|
|
return res.json(campaign);
|
|
|
|
});
|
|
|
|
|
|
|
|
router.getAsync('/campaigns-content/:campaignId', passport.loggedIn, async (req, res) => {
|
|
|
|
const campaign = await campaigns.getById(req.context, req.params.campaignId, true, campaigns.Content.ONLY_SOURCE_CUSTOM);
|
|
|
|
campaign.hash = campaigns.hash(campaign, campaigns.Content.ONLY_SOURCE_CUSTOM);
|
2018-07-31 04:34:28 +00:00
|
|
|
return res.json(campaign);
|
|
|
|
});
|
|
|
|
|
|
|
|
router.postAsync('/campaigns', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
|
|
|
return res.json(await campaigns.create(req.context, req.body));
|
|
|
|
});
|
|
|
|
|
2018-08-03 11:35:55 +00:00
|
|
|
router.putAsync('/campaigns-settings/:campaignId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
|
|
|
const entity = req.body;
|
|
|
|
entity.id = parseInt(req.params.campaignId);
|
|
|
|
|
|
|
|
await campaigns.updateWithConsistencyCheck(req.context, entity, campaigns.Content.WITHOUT_SOURCE_CUSTOM);
|
|
|
|
return res.json();
|
|
|
|
});
|
|
|
|
|
|
|
|
router.putAsync('/campaigns-content/:campaignId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
2018-07-31 04:34:28 +00:00
|
|
|
const entity = req.body;
|
|
|
|
entity.id = parseInt(req.params.campaignId);
|
|
|
|
|
2018-08-03 11:35:55 +00:00
|
|
|
await campaigns.updateWithConsistencyCheck(req.context, entity, campaigns.Content.ONLY_SOURCE_CUSTOM);
|
2018-07-31 04:34:28 +00:00
|
|
|
return res.json();
|
|
|
|
});
|
|
|
|
|
|
|
|
router.deleteAsync('/campaigns/:campaignId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
|
|
|
await campaigns.remove(req.context, req.params.campaignId);
|
|
|
|
return res.json();
|
|
|
|
});
|
|
|
|
|
2017-07-11 09:28:44 +00:00
|
|
|
|
|
|
|
module.exports = router;
|