2017-07-11 09:28:44 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const passport = require('../../lib/passport');
|
|
|
|
const lists = require('../../models/lists');
|
|
|
|
|
|
|
|
const router = require('../../lib/router-async').create();
|
2018-09-29 11:30:29 +00:00
|
|
|
const {castToInteger} = require('../../lib/helpers');
|
2017-07-11 09:28:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
router.postAsync('/lists-table', passport.loggedIn, async (req, res) => {
|
2017-07-29 19:42:07 +00:00
|
|
|
return res.json(await lists.listDTAjax(req.context, req.body));
|
|
|
|
});
|
|
|
|
|
2019-03-26 23:41:18 +00:00
|
|
|
router.postAsync('/lists-by-namespace-table/:namespaceId', passport.loggedIn, async (req, res) => {
|
2019-03-14 15:15:37 +00:00
|
|
|
return res.json(await lists.listByNamespaceDTAjax(req.context, castToInteger(req.params.namespaceId), req.body));
|
2019-03-13 08:52:02 +00:00
|
|
|
});
|
|
|
|
|
2018-09-09 22:55:44 +00:00
|
|
|
router.postAsync('/lists-with-segment-by-campaign-table/:campaignId', passport.loggedIn, async (req, res) => {
|
2018-09-29 11:30:29 +00:00
|
|
|
return res.json(await lists.listWithSegmentByCampaignDTAjax(req.context, castToInteger(req.params.campaignId), req.body));
|
2018-09-09 22:55:44 +00:00
|
|
|
});
|
|
|
|
|
2017-07-29 19:42:07 +00:00
|
|
|
router.getAsync('/lists/:listId', passport.loggedIn, async (req, res) => {
|
2018-09-29 11:30:29 +00:00
|
|
|
const list = await lists.getByIdWithListFields(req.context, castToInteger(req.params.listId));
|
2017-07-29 19:42:07 +00:00
|
|
|
list.hash = lists.hash(list);
|
|
|
|
return res.json(list);
|
|
|
|
});
|
|
|
|
|
|
|
|
router.postAsync('/lists', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
2018-02-13 22:50:13 +00:00
|
|
|
return res.json(await lists.create(req.context, req.body));
|
2017-07-29 19:42:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
router.putAsync('/lists/:listId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
2017-08-14 20:53:29 +00:00
|
|
|
const entity = req.body;
|
2018-09-29 11:30:29 +00:00
|
|
|
entity.id = castToInteger(req.params.listId);
|
2017-07-29 19:42:07 +00:00
|
|
|
|
2017-08-14 20:53:29 +00:00
|
|
|
await lists.updateWithConsistencyCheck(req.context, entity);
|
2017-07-29 19:42:07 +00:00
|
|
|
return res.json();
|
|
|
|
});
|
|
|
|
|
|
|
|
router.deleteAsync('/lists/:listId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
2018-09-29 11:30:29 +00:00
|
|
|
await lists.remove(req.context, castToInteger(req.params.listId));
|
2017-07-29 19:42:07 +00:00
|
|
|
return res.json();
|
2017-07-11 09:28:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = router;
|