Removed obsolete dir

Numeric conversions for all ids coming in as route req params.
Infrastructure for proper error message when dependencies prevent entity deletion.
This commit is contained in:
Tomas Bures 2018-09-29 13:30:29 +02:00
parent 2b57396a5d
commit 0a08088893
636 changed files with 291 additions and 73346 deletions

View file

@ -4,6 +4,7 @@ const passport = require('../../lib/passport');
const campaigns = require('../../models/campaigns');
const router = require('../../lib/router-async').create();
const {castToInteger} = require('../../lib/helpers');
router.postAsync('/campaigns-table', passport.loggedIn, async (req, res) => {
@ -15,26 +16,26 @@ router.postAsync('/campaigns-with-content-table', passport.loggedIn, async (req,
});
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));
return res.json(await campaigns.listOthersWhoseListsAreIncludedDTAjax(req.context, castToInteger(req.params.campaignId), req.params.listIds.split(';').map(x => castToInteger(x)), req.body));
});
router.postAsync('/campaigns-test-users-table/:campaignId', passport.loggedIn, async (req, res) => {
return res.json(await campaigns.listTestUsersDTAjax(req.context, req.params.campaignId, req.body));
return res.json(await campaigns.listTestUsersDTAjax(req.context, castToInteger(req.params.campaignId), req.body));
});
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);
const campaign = await campaigns.getById(req.context, castToInteger(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-stats/:campaignId', passport.loggedIn, async (req, res) => {
const campaign = await campaigns.getById(req.context, req.params.campaignId, true, campaigns.Content.SETTINGS_WITH_STATS);
const campaign = await campaigns.getById(req.context, castToInteger(req.params.campaignId), true, campaigns.Content.SETTINGS_WITH_STATS);
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);
const campaign = await campaigns.getById(req.context, castToInteger(req.params.campaignId), true, campaigns.Content.ONLY_SOURCE_CUSTOM);
campaign.hash = campaigns.hash(campaign, campaigns.Content.ONLY_SOURCE_CUSTOM);
return res.json(campaign);
});
@ -45,7 +46,7 @@ router.postAsync('/campaigns', passport.loggedIn, passport.csrfProtection, async
router.putAsync('/campaigns-settings/:campaignId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
const entity = req.body;
entity.id = parseInt(req.params.campaignId);
entity.id = castToInteger(req.params.campaignId);
await campaigns.updateWithConsistencyCheck(req.context, entity, campaigns.Content.WITHOUT_SOURCE_CUSTOM);
return res.json();
@ -53,32 +54,32 @@ router.putAsync('/campaigns-settings/:campaignId', passport.loggedIn, passport.c
router.putAsync('/campaigns-content/:campaignId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
const entity = req.body;
entity.id = parseInt(req.params.campaignId);
entity.id = castToInteger(req.params.campaignId);
await campaigns.updateWithConsistencyCheck(req.context, entity, campaigns.Content.ONLY_SOURCE_CUSTOM);
return res.json();
});
router.deleteAsync('/campaigns/:campaignId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
await campaigns.remove(req.context, req.params.campaignId);
await campaigns.remove(req.context, castToInteger(req.params.campaignId));
return res.json();
});
router.postAsync('/campaign-start/:campaignId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
return res.json(await campaigns.start(req.context, req.params.campaignId, null));
return res.json(await campaigns.start(req.context, castToInteger(req.params.campaignId), null));
});
router.postAsync('/campaign-start-at/:campaignId/:dateTime', passport.loggedIn, passport.csrfProtection, async (req, res) => {
return res.json(await campaigns.start(req.context, req.params.campaignId, new Date(Number.parseInt(req.params.dateTime))));
return res.json(await campaigns.start(req.context, castToInteger(req.params.campaignId), new Date(Number.parseInt(req.params.dateTime))));
});
router.postAsync('/campaign-stop/:campaignId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
return res.json(await campaigns.stop(req.context, req.params.campaignId));
return res.json(await campaigns.stop(req.context, castToInteger(req.params.campaignId)));
});
router.postAsync('/campaign-reset/:campaignId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
return res.json(await campaigns.reset(req.context, req.params.campaignId));
return res.json(await campaigns.reset(req.context, castToInteger(req.params.campaignId)));
});
module.exports = router;

View file

@ -4,51 +4,52 @@ const passport = require('../../lib/passport');
const fields = require('../../models/fields');
const router = require('../../lib/router-async').create();
const {castToInteger} = require('../../lib/helpers');
router.postAsync('/fields-table/:listId', passport.loggedIn, async (req, res) => {
return res.json(await fields.listDTAjax(req.context, req.params.listId, req.body));
return res.json(await fields.listDTAjax(req.context, castToInteger(req.params.listId), req.body));
});
router.postAsync('/fields-grouped-table/:listId', passport.loggedIn, async (req, res) => {
return res.json(await fields.listGroupedDTAjax(req.context, req.params.listId, req.body));
return res.json(await fields.listGroupedDTAjax(req.context, castToInteger(req.params.listId), req.body));
});
router.getAsync('/fields/:listId/:fieldId', passport.loggedIn, async (req, res) => {
const entity = await fields.getById(req.context, req.params.listId, req.params.fieldId);
const entity = await fields.getById(req.context, castToInteger(req.params.listId), castToInteger(req.params.fieldId));
entity.hash = fields.hash(entity);
return res.json(entity);
});
router.getAsync('/fields/:listId', passport.loggedIn, async (req, res) => {
const rows = await fields.list(req.context, req.params.listId);
const rows = await fields.list(req.context, castToInteger(req.params.listId));
return res.json(rows);
});
router.getAsync('/fields-grouped/:listId', passport.loggedIn, async (req, res) => {
const rows = await fields.listGrouped(req.context, req.params.listId);
const rows = await fields.listGrouped(req.context, castToInteger(req.params.listId));
return res.json(rows);
});
router.postAsync('/fields/:listId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
return res.json(await fields.create(req.context, req.params.listId, req.body));
return res.json(await fields.create(req.context, castToInteger(req.params.listId), req.body));
});
router.putAsync('/fields/:listId/:fieldId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
const entity = req.body;
entity.id = parseInt(req.params.fieldId);
entity.id = castToInteger(req.params.fieldId);
await fields.updateWithConsistencyCheck(req.context, req.params.listId, entity);
await fields.updateWithConsistencyCheck(req.context, castToInteger(req.params.listId), entity);
return res.json();
});
router.deleteAsync('/fields/:listId/:fieldId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
await fields.remove(req.context, req.params.listId, req.params.fieldId);
await fields.remove(req.context, castToInteger(req.params.listId), castToInteger(req.params.fieldId));
return res.json();
});
router.postAsync('/fields-validate/:listId', passport.loggedIn, async (req, res) => {
return res.json(await fields.serverValidate(req.context, req.params.listId, req.body));
return res.json(await fields.serverValidate(req.context, castToInteger(req.params.listId), req.body));
});

View file

@ -4,19 +4,20 @@ const passport = require('../../lib/passport');
const files = require('../../models/files');
const router = require('../../lib/router-async').create();
const fileHelpers = require('../../lib/file-helpers');
const {castToInteger} = require('../../lib/helpers');
router.postAsync('/files-table/:type/:subType/:entityId', passport.loggedIn, async (req, res) => {
return res.json(await files.listDTAjax(req.context, req.params.type, req.params.subType, req.params.entityId, req.body));
return res.json(await files.listDTAjax(req.context, req.params.type, req.params.subType, castToInteger(req.params.entityId), req.body));
});
router.getAsync('/files/:type/:subType/:fileId', passport.loggedIn, async (req, res) => {
const file = await files.getFileById(req.context, req.params.type, req.params.subType, req.params.fileId);
const file = await files.getFileById(req.context, req.params.type, req.params.subType, castToInteger(req.params.fileId));
res.type(file.mimetype);
return res.download(file.path, file.name);
});
router.deleteAsync('/files/:type/:subType/:fileId', passport.loggedIn, async (req, res) => {
await files.removeFile(req.context, req.params.type, req.params.subType, req.params.fileId);
await files.removeFile(req.context, req.params.type, req.params.subType, castToInteger(req.params.fileId));
return res.json();
});

View file

@ -4,6 +4,7 @@ const passport = require('../../lib/passport');
const forms = require('../../models/forms');
const router = require('../../lib/router-async').create();
const {castToInteger} = require('../../lib/helpers');
router.postAsync('/forms-table', passport.loggedIn, async (req, res) => {
@ -11,7 +12,7 @@ router.postAsync('/forms-table', passport.loggedIn, async (req, res) => {
});
router.getAsync('/forms/:formId', passport.loggedIn, async (req, res) => {
const entity = await forms.getById(req.context, req.params.formId);
const entity = await forms.getById(req.context, castToInteger(req.params.formId));
entity.hash = forms.hash(entity);
return res.json(entity);
});
@ -22,14 +23,14 @@ router.postAsync('/forms', passport.loggedIn, passport.csrfProtection, async (re
router.putAsync('/forms/:formId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
const entity = req.body;
entity.id = parseInt(req.params.formId);
entity.id = castToInteger(req.params.formId);
await forms.updateWithConsistencyCheck(req.context, entity);
return res.json();
});
router.deleteAsync('/forms/:formId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
await forms.remove(req.context, req.params.formId);
await forms.remove(req.context, castToInteger(req.params.formId));
return res.json();
});

View file

@ -4,17 +4,18 @@ const passport = require('../../lib/passport');
const importRuns = require('../../models/import-runs');
const router = require('../../lib/router-async').create();
const {castToInteger} = require('../../lib/helpers');
router.postAsync('/import-runs-table/:listId/:importId', passport.loggedIn, async (req, res) => {
return res.json(await importRuns.listDTAjax(req.context, req.params.listId, req.params.importId, req.body));
return res.json(await importRuns.listDTAjax(req.context, castToInteger(req.params.listId), castToInteger(req.params.importId), req.body));
});
router.postAsync('/import-run-failed-table/:listId/:importId/:importRunId', passport.loggedIn, async (req, res) => {
return res.json(await importRuns.listFailedDTAjax(req.context, req.params.listId, req.params.importId, req.params.importRunId, req.body));
return res.json(await importRuns.listFailedDTAjax(req.context, castToInteger(req.params.listId), castToInteger(req.params.importId), castToInteger(req.params.importRunId), req.body));
});
router.getAsync('/import-runs/:listId/:importId/:runId', passport.loggedIn, async (req, res) => {
const entity = await importRuns.getById(req.context, req.params.listId, req.params.importId, req.params.runId);
const entity = await importRuns.getById(req.context, castToInteger(req.params.listId), castToInteger(req.params.importId), castToInteger(req.params.runId));
return res.json(entity);
});

View file

@ -4,6 +4,7 @@ const passport = require('../../lib/passport');
const imports = require('../../models/imports');
const router = require('../../lib/router-async').create();
const {castToInteger} = require('../../lib/helpers');
const path = require('path');
@ -15,11 +16,11 @@ const multer = require('multer')({
});
router.postAsync('/imports-table/:listId', passport.loggedIn, async (req, res) => {
return res.json(await imports.listDTAjax(req.context, req.params.listId, req.body));
return res.json(await imports.listDTAjax(req.context, castToInteger(req.params.listId), req.body));
});
router.getAsync('/imports/:listId/:importId', passport.loggedIn, async (req, res) => {
const entity = await imports.getById(req.context, req.params.listId, req.params.importId, true);
const entity = await imports.getById(req.context, castToInteger(req.params.listId), castToInteger(req.params.importId), true);
entity.hash = imports.hash(entity);
return res.json(entity);
});
@ -31,28 +32,28 @@ const fileFields = [
router.postAsync('/imports/:listId', passport.loggedIn, passport.csrfProtection, multer.fields(fileFields), async (req, res) => {
const entity = JSON.parse(req.body.entity);
return res.json(await imports.create(req.context, req.params.listId, entity, req.files));
return res.json(await imports.create(req.context, castToInteger(req.params.listId), entity, req.files));
});
router.putAsync('/imports/:listId/:importId', passport.loggedIn, passport.csrfProtection, multer.fields(fileFields), async (req, res) => {
const entity = JSON.parse(req.body.entity);
entity.id = parseInt(req.params.importId);
entity.id = castToInteger(req.params.importId);
await imports.updateWithConsistencyCheck(req.context, req.params.listId, entity, req.files);
await imports.updateWithConsistencyCheck(req.context, castToInteger(req.params.listId), entity, req.files);
return res.json();
});
router.deleteAsync('/imports/:listId/:importId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
await imports.remove(req.context, req.params.listId, req.params.importId);
await imports.remove(req.context, castToInteger(req.params.listId), castToInteger(req.params.importId));
return res.json();
});
router.postAsync('/import-start/:listId/:importId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
return res.json(await imports.start(req.context, req.params.listId, req.params.importId));
return res.json(await imports.start(req.context, castToInteger(req.params.listId), castToInteger(req.params.importId)));
});
router.postAsync('/import-stop/:listId/:importId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
return res.json(await imports.stop(req.context, req.params.listId, req.params.importId));
return res.json(await imports.stop(req.context, castToInteger(req.params.listId), castToInteger(req.params.importId)));
});
module.exports = router;

View file

@ -4,6 +4,7 @@ const passport = require('../../lib/passport');
const lists = require('../../models/lists');
const router = require('../../lib/router-async').create();
const {castToInteger} = require('../../lib/helpers');
router.postAsync('/lists-table', passport.loggedIn, async (req, res) => {
@ -11,11 +12,11 @@ router.postAsync('/lists-table', passport.loggedIn, async (req, res) => {
});
router.postAsync('/lists-with-segment-by-campaign-table/:campaignId', passport.loggedIn, async (req, res) => {
return res.json(await lists.listWithSegmentByCampaignDTAjax(req.context, req.params.campaignId, req.body));
return res.json(await lists.listWithSegmentByCampaignDTAjax(req.context, castToInteger(req.params.campaignId), req.body));
});
router.getAsync('/lists/:listId', passport.loggedIn, async (req, res) => {
const list = await lists.getByIdWithListFields(req.context, req.params.listId);
const list = await lists.getByIdWithListFields(req.context, castToInteger(req.params.listId));
list.hash = lists.hash(list);
return res.json(list);
});
@ -26,14 +27,14 @@ router.postAsync('/lists', passport.loggedIn, passport.csrfProtection, async (re
router.putAsync('/lists/:listId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
const entity = req.body;
entity.id = parseInt(req.params.listId);
entity.id = castToInteger(req.params.listId);
await lists.updateWithConsistencyCheck(req.context, entity);
return res.json();
});
router.deleteAsync('/lists/:listId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
await lists.remove(req.context, req.params.listId);
await lists.remove(req.context, castToInteger(req.params.listId));
return res.json();
});

View file

@ -2,12 +2,12 @@
const passport = require('../../lib/passport');
const mosaicoTemplates = require('../../models/mosaico-templates');
const router = require('../../lib/router-async').create();
const {castToInteger} = require('../../lib/helpers');
router.getAsync('/mosaico-templates/:mosaicoTemplateId', passport.loggedIn, async (req, res) => {
const mosaicoTemplate = await mosaicoTemplates.getById(req.context, req.params.mosaicoTemplateId);
const mosaicoTemplate = await mosaicoTemplates.getById(req.context, castToInteger(req.params.mosaicoTemplateId));
mosaicoTemplate.hash = mosaicoTemplates.hash(mosaicoTemplate);
return res.json(mosaicoTemplate);
});
@ -18,14 +18,14 @@ router.postAsync('/mosaico-templates', passport.loggedIn, passport.csrfProtectio
router.putAsync('/mosaico-templates/:mosaicoTemplateId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
const mosaicoTemplate = req.body;
mosaicoTemplate.id = parseInt(req.params.mosaicoTemplateId);
mosaicoTemplate.id = castToInteger(req.params.mosaicoTemplateId);
await mosaicoTemplates.updateWithConsistencyCheck(req.context, mosaicoTemplate);
return res.json();
});
router.deleteAsync('/mosaico-templates/:mosaicoTemplateId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
await mosaicoTemplates.remove(req.context, req.params.mosaicoTemplateId);
await mosaicoTemplates.remove(req.context, castToInteger(req.params.mosaicoTemplateId));
return res.json();
});

View file

@ -5,10 +5,11 @@ const _ = require('../../lib/translate')._;
const namespaces = require('../../models/namespaces');
const router = require('../../lib/router-async').create();
const {castToInteger} = require('../../lib/helpers');
router.getAsync('/namespaces/:nsId', passport.loggedIn, async (req, res) => {
const ns = await namespaces.getById(req.context, req.params.nsId);
const ns = await namespaces.getById(req.context, castToInteger(req.params.nsId));
ns.hash = namespaces.hash(ns);
@ -21,14 +22,14 @@ router.postAsync('/namespaces', passport.loggedIn, passport.csrfProtection, asyn
router.putAsync('/namespaces/:nsId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
const ns = req.body;
ns.id = parseInt(req.params.nsId);
ns.id = castToInteger(req.params.nsId);
await namespaces.updateWithConsistencyCheck(req.context, ns);
return res.json();
});
router.deleteAsync('/namespaces/:nsId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
await namespaces.remove(req.context, req.params.nsId);
await namespaces.remove(req.context, castToInteger(req.params.nsId));
return res.json();
});

View file

@ -5,10 +5,11 @@ 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, req.params.reportTemplateId);
const reportTemplate = await reportTemplates.getById(req.context, castToInteger(req.params.reportTemplateId));
reportTemplate.hash = reportTemplates.hash(reportTemplate);
return res.json(reportTemplate);
});
@ -19,14 +20,14 @@ router.postAsync('/report-templates', passport.loggedIn, passport.csrfProtection
router.putAsync('/report-templates/:reportTemplateId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
const reportTemplate = req.body;
reportTemplate.id = parseInt(req.params.reportTemplateId);
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, req.params.reportTemplateId);
await reportTemplates.remove(req.context, castToInteger(req.params.reportTemplateId));
return res.json();
});
@ -35,7 +36,7 @@ router.postAsync('/report-templates-table', passport.loggedIn, async (req, res)
});
router.getAsync('/report-template-user-fields/:reportTemplateId', passport.loggedIn, async (req, res) => {
const userFields = await reportTemplates.getUserFieldsById(req.context, req.params.reportTemplateId);
const userFields = await reportTemplates.getUserFieldsById(req.context, castToInteger(req.params.reportTemplateId));
return res.json(userFields);
});

View file

@ -9,10 +9,11 @@ const shares = require('../../models/shares');
const contextHelpers = require('../../lib/context-helpers');
const router = require('../../lib/router-async').create();
const {castToInteger} = require('../../lib/helpers');
router.getAsync('/reports/:reportId', passport.loggedIn, async (req, res) => {
const report = await reports.getByIdWithTemplate(req.context, req.params.reportId);
const report = await reports.getByIdWithTemplate(req.context, castToInteger(req.params.reportId));
report.hash = reports.hash(report);
return res.json(report);
});
@ -23,14 +24,14 @@ router.postAsync('/reports', passport.loggedIn, passport.csrfProtection, async (
router.putAsync('/reports/:reportId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
const report = req.body;
report.id = parseInt(req.params.reportId);
report.id = castToInteger(req.params.reportId);
await reports.updateWithConsistencyCheck(req.context, report);
return res.json();
});
router.deleteAsync('/reports/:reportId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
await reports.remove(req.context, req.params.reportId);
await reports.remove(req.context, castToInteger(req.params.reportId));
return res.json();
});
@ -39,36 +40,44 @@ router.postAsync('/reports-table', passport.loggedIn, async (req, res) => {
});
router.postAsync('/report-start/:id', passport.loggedIn, passport.csrfProtection, async (req, res) => {
await shares.enforceEntityPermission(req.context, 'report', req.params.id, 'execute');
const id = castToInteger(req.params.id);
const report = await reports.getByIdWithTemplate(contextHelpers.getAdminContext(), req.params.id);
await shares.enforceEntityPermission(req.context, 'report', id, 'execute');
const report = await reports.getByIdWithTemplate(contextHelpers.getAdminContext(), id);
await shares.enforceEntityPermission(req.context, 'reportTemplate', report.report_template, 'execute');
await reportProcessor.start(req.params.id);
await reportProcessor.start(id);
res.json();
});
router.postAsync('/report-stop/:id', async (req, res) => {
await shares.enforceEntityPermission(req.context, 'report', req.params.id, 'execute');
const id = castToInteger(req.params.id);
const report = await reports.getByIdWithTemplate(contextHelpers.getAdminContext(), req.params.id);
await shares.enforceEntityPermission(req.context, 'report', id, 'execute');
const report = await reports.getByIdWithTemplate(contextHelpers.getAdminContext(), id);
await shares.enforceEntityPermission(req.context, 'reportTemplate', report.report_template, 'execute');
await reportProcessor.stop(req.params.id);
await reportProcessor.stop(id);
res.json();
});
router.getAsync('/report-content/:id', async (req, res) => {
await shares.enforceEntityPermission(req.context, 'report', req.params.id, 'viewContent');
const id = castToInteger(req.params.id);
const report = await reports.getByIdWithTemplate(contextHelpers.getAdminContext(), req.params.id);
await shares.enforceEntityPermission(req.context, 'report', id, 'viewContent');
const report = await reports.getByIdWithTemplate(contextHelpers.getAdminContext(), id);
res.sendFile(reportHelpers.getReportContentFile(report));
});
router.getAsync('/report-output/:id', async (req, res) => {
await shares.enforceEntityPermission(req.context, 'report', req.params.id, 'viewOutput');
const id = castToInteger(req.params.id);
const report = await reports.getByIdWithTemplate(contextHelpers.getAdminContext(), req.params.id);
await shares.enforceEntityPermission(req.context, 'report', id, 'viewOutput');
const report = await reports.getByIdWithTemplate(contextHelpers.getAdminContext(), id);
res.sendFile(reportHelpers.getReportOutputFile(report));
});

View file

@ -4,36 +4,37 @@ const passport = require('../../lib/passport');
const segments = require('../../models/segments');
const router = require('../../lib/router-async').create();
const {castToInteger} = require('../../lib/helpers');
router.postAsync('/segments-table/:listId', passport.loggedIn, async (req, res) => {
return res.json(await segments.listDTAjax(req.context, req.params.listId, req.body));
return res.json(await segments.listDTAjax(req.context, castToInteger(req.params.listId), req.body));
});
router.getAsync('/segments/:listId', passport.loggedIn, async (req, res) => {
return res.json(await segments.listIdName(req.context, req.params.listId));
return res.json(await segments.listIdName(req.context, castToInteger(req.params.listId)));
});
router.getAsync('/segments/:listId/:segmentId', passport.loggedIn, async (req, res) => {
const segment = await segments.getById(req.context, req.params.listId, req.params.segmentId);
const segment = await segments.getById(req.context, castToInteger(req.params.listId), castToInteger(req.params.segmentId));
segment.hash = segments.hash(segment);
return res.json(segment);
});
router.postAsync('/segments/:listId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
return res.json(await segments.create(req.context, req.params.listId, req.body));
return res.json(await segments.create(req.context, castToInteger(req.params.listId), req.body));
});
router.putAsync('/segments/:listId/:segmentId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
const entity = req.body;
entity.id = parseInt(req.params.segmentId);
entity.id = castToInteger(req.params.segmentId);
await segments.updateWithConsistencyCheck(req.context, req.params.listId, entity);
await segments.updateWithConsistencyCheck(req.context, castToInteger(req.params.listId), entity);
return res.json();
});
router.deleteAsync('/segments/:listId/:segmentId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
await segments.remove(req.context, req.params.listId, req.params.segmentId);
await segments.remove(req.context, castToInteger(req.params.listId), castToInteger(req.params.segmentId));
return res.json();
});

View file

@ -4,16 +4,17 @@ const passport = require('../../lib/passport');
const sendConfigurations = require('../../models/send-configurations');
const router = require('../../lib/router-async').create();
const {castToInteger} = require('../../lib/helpers');
router.getAsync('/send-configurations-private/:sendConfigurationId', passport.loggedIn, async (req, res) => {
const sendConfiguration = await sendConfigurations.getById(req.context, req.params.sendConfigurationId, true, true);
const sendConfiguration = await sendConfigurations.getById(req.context, castToInteger(req.params.sendConfigurationId), true, true);
sendConfiguration.hash = sendConfigurations.hash(sendConfiguration);
return res.json(sendConfiguration);
});
router.getAsync('/send-configurations-public/:sendConfigurationId', passport.loggedIn, async (req, res) => {
const sendConfiguration = await sendConfigurations.getById(req.context, req.params.sendConfigurationId, true, false);
const sendConfiguration = await sendConfigurations.getById(req.context, castToInteger(req.params.sendConfigurationId), true, false);
sendConfiguration.hash = sendConfigurations.hash(sendConfiguration);
return res.json(sendConfiguration);
});
@ -24,14 +25,14 @@ router.postAsync('/send-configurations', passport.loggedIn, passport.csrfProtect
router.putAsync('/send-configurations/:sendConfigurationId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
const sendConfiguration = req.body;
sendConfiguration.id = parseInt(req.params.sendConfigurationId);
sendConfiguration.id = castToInteger(req.params.sendConfigurationId);
await sendConfigurations.updateWithConsistencyCheck(req.context, sendConfiguration);
return res.json();
});
router.deleteAsync('/send-configurations/:sendConfigurationId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
await sendConfigurations.remove(req.context, req.params.sendConfigurationId);
await sendConfigurations.remove(req.context, castToInteger(req.params.sendConfigurationId));
return res.json();
});

View file

@ -5,17 +5,18 @@ const _ = require('../../lib/translate')._;
const shares = require('../../models/shares');
const router = require('../../lib/router-async').create();
const {castToInteger} = require('../../lib/helpers');
router.postAsync('/shares-table-by-entity/:entityTypeId/:entityId', passport.loggedIn, async (req, res) => {
return res.json(await shares.listByEntityDTAjax(req.context, req.params.entityTypeId, req.params.entityId, req.body));
return res.json(await shares.listByEntityDTAjax(req.context, req.params.entityTypeId, castToInteger(req.params.entityId), req.body));
});
router.postAsync('/shares-table-by-user/:entityTypeId/:userId', passport.loggedIn, async (req, res) => {
return res.json(await shares.listByUserDTAjax(req.context, req.params.entityTypeId, req.params.userId, req.body));
return res.json(await shares.listByUserDTAjax(req.context, req.params.entityTypeId, castToInteger(req.params.userId), req.body));
});
router.postAsync('/shares-unassigned-users-table/:entityTypeId/:entityId', passport.loggedIn, async (req, res) => {
return res.json(await shares.listUnassignedUsersDTAjax(req.context, req.params.entityTypeId, req.params.entityId, req.body));
return res.json(await shares.listUnassignedUsersDTAjax(req.context, req.params.entityTypeId, castToInteger(req.params.entityId), req.body));
});
router.postAsync('/shares-roles-table/:entityTypeId', passport.loggedIn, async (req, res) => {

View file

@ -5,41 +5,42 @@ const subscriptions = require('../../models/subscriptions');
const { SubscriptionSource } = require('../../shared/lists');
const router = require('../../lib/router-async').create();
const {castToInteger} = require('../../lib/helpers');
router.postAsync('/subscriptions-table/:listId/:segmentId?', passport.loggedIn, async (req, res) => {
return res.json(await subscriptions.listDTAjax(req.context, req.params.listId, req.params.segmentId, req.body));
return res.json(await subscriptions.listDTAjax(req.context, castToInteger(req.params.listId), req.params.segmentId ? castToInteger(req.params.segmentId) : null, req.body));
});
router.getAsync('/subscriptions/:listId/:subscriptionId', passport.loggedIn, async (req, res) => {
const entity = await subscriptions.getById(req.context, req.params.listId, req.params.subscriptionId);
entity.hash = await subscriptions.hashByList(req.params.listId, entity);
const entity = await subscriptions.getById(req.context, castToInteger(req.params.listId), castToInteger(req.params.subscriptionId));
entity.hash = await subscriptions.hashByList(castToInteger(req.params.listId), entity);
return res.json(entity);
});
router.postAsync('/subscriptions/:listId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
return res.json(await subscriptions.create(req.context, req.params.listId, req.body, SubscriptionSource.ADMIN_FORM));
return res.json(await subscriptions.create(req.context, castToInteger(req.params.listId), req.body, SubscriptionSource.ADMIN_FORM));
});
router.putAsync('/subscriptions/:listId/:subscriptionId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
const entity = req.body;
entity.id = parseInt(req.params.subscriptionId);
entity.id = castToInteger(req.params.subscriptionId);
await subscriptions.updateWithConsistencyCheck(req.context, req.params.listId, entity, SubscriptionSource.ADMIN_FORM);
await subscriptions.updateWithConsistencyCheck(req.context, castToInteger(req.params.listId), entity, SubscriptionSource.ADMIN_FORM);
return res.json();
});
router.deleteAsync('/subscriptions/:listId/:subscriptionId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
await subscriptions.remove(req.context, req.params.listId, req.params.subscriptionId);
await subscriptions.remove(req.context, castToInteger(req.params.listId), castToInteger(req.params.subscriptionId));
return res.json();
});
router.postAsync('/subscriptions-validate/:listId', passport.loggedIn, async (req, res) => {
return res.json(await subscriptions.serverValidate(req.context, req.params.listId, req.body));
return res.json(await subscriptions.serverValidate(req.context, castToInteger(req.params.listId), req.body));
});
router.postAsync('/subscriptions-unsubscribe/:listId/:subscriptionId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
await subscriptions.unsubscribeByIdAndGet(req.context, req.params.listId, req.params.subscriptionId);
await subscriptions.unsubscribeByIdAndGet(req.context, castToInteger(req.params.listId), castToInteger(req.params.subscriptionId));
return res.json();
});

View file

@ -4,10 +4,11 @@ const passport = require('../../lib/passport');
const templates = require('../../models/templates');
const router = require('../../lib/router-async').create();
const {castToInteger} = require('../../lib/helpers');
router.getAsync('/templates/:templateId', passport.loggedIn, async (req, res) => {
const template = await templates.getById(req.context, req.params.templateId);
const template = await templates.getById(req.context, castToInteger(req.params.templateId));
template.hash = templates.hash(template);
return res.json(template);
});
@ -18,14 +19,14 @@ router.postAsync('/templates', passport.loggedIn, passport.csrfProtection, async
router.putAsync('/templates/:templateId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
const template = req.body;
template.id = parseInt(req.params.templateId);
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, req.params.templateId);
await templates.remove(req.context, castToInteger(req.params.templateId));
return res.json();
});

View file

@ -4,36 +4,37 @@ const passport = require('../../lib/passport');
const triggers = require('../../models/triggers');
const router = require('../../lib/router-async').create();
const {castToInteger} = require('../../lib/helpers');
router.postAsync('/triggers-by-campaign-table/:campaignId', passport.loggedIn, async (req, res) => {
return res.json(await triggers.listByCampaignDTAjax(req.context, req.params.campaignId, req.body));
return res.json(await triggers.listByCampaignDTAjax(req.context, castToInteger(req.params.campaignId), req.body));
});
router.postAsync('/triggers-by-list-table/:listId', passport.loggedIn, async (req, res) => {
return res.json(await triggers.listByListDTAjax(req.context, req.params.listId, req.body));
return res.json(await triggers.listByListDTAjax(req.context, castToInteger(req.params.listId), req.body));
});
router.getAsync('/triggers/:campaignId/:triggerId', passport.loggedIn, async (req, res) => {
const entity = await triggers.getById(req.context, req.params.campaignId, req.params.triggerId);
const entity = await triggers.getById(req.context, castToInteger(req.params.campaignId), req.params.triggerId);
entity.hash = triggers.hash(entity);
return res.json(entity);
});
router.postAsync('/triggers/:campaignId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
return res.json(await triggers.create(req.context, req.params.campaignId, req.body));
return res.json(await triggers.create(req.context, castToInteger(req.params.campaignId), req.body));
});
router.putAsync('/triggers/:campaignId/:triggerId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
const entity = req.body;
entity.id = parseInt(req.params.triggerId);
entity.id = castToInteger(req.params.triggerId);
await triggers.updateWithConsistencyCheck(req.context, req.params.campaignId, entity);
await triggers.updateWithConsistencyCheck(req.context, castToInteger(req.params.campaignId), entity);
return res.json();
});
router.deleteAsync('/triggers/:campaignId/:triggerId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
await triggers.remove(req.context, req.params.campaignId, req.params.triggerId);
await triggers.remove(req.context, castToInteger(req.params.campaignId), castToInteger(req.params.triggerId));
return res.json();
});

View file

@ -7,10 +7,11 @@ const users = require('../../models/users');
const shares = require('../../models/shares');
const router = require('../../lib/router-async').create();
const {castToInteger} = require('../../lib/helpers');
router.getAsync('/users/:userId', passport.loggedIn, async (req, res) => {
const user = await users.getById(req.context, req.params.userId);
const user = await users.getById(req.context, castToInteger(req.params.userId));
user.hash = users.hash(user);
return res.json(user);
});
@ -21,14 +22,14 @@ router.postAsync('/users', passport.loggedIn, passport.csrfProtection, async (re
router.putAsync('/users/:userId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
const user = req.body;
user.id = parseInt(req.params.userId);
user.id = castToInteger(req.params.userId);
await users.updateWithConsistencyCheck(req.context, user);
return res.json();
});
router.deleteAsync('/users/:userId', passport.loggedIn, passport.csrfProtection, async (req, res) => {
await users.remove(req.context, req.params.userId);
await users.remove(req.context, castToInteger(req.params.userId));
return res.json();
});