CUD operations on reports and report templates seem to work
Execution of reports is TBD
This commit is contained in:
parent
38cf3e49c0
commit
6d95fa515e
18 changed files with 273 additions and 46 deletions
13
models/campaigns.js
Normal file
13
models/campaigns.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
const knex = require('../lib/knex');
|
||||
const dtHelpers = require('../lib/dt-helpers');
|
||||
|
||||
async function listDTAjax(params) {
|
||||
return await dtHelpers.ajaxList(params, tx => tx('campaigns'), ['campaigns.id', 'campaigns.name', 'campaigns.description', 'campaigns.status', 'campaigns.created']);
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
listDTAjax
|
||||
};
|
13
models/lists.js
Normal file
13
models/lists.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
const knex = require('../lib/knex');
|
||||
const dtHelpers = require('../lib/dt-helpers');
|
||||
|
||||
async function listDTAjax(params) {
|
||||
return await dtHelpers.ajaxList(params, tx => tx('lists'), ['lists.id', 'lists.name', 'lists.cid', 'lists.subscribers', 'lists.description']);
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
listDTAjax
|
||||
};
|
|
@ -50,11 +50,21 @@ async function remove(id) {
|
|||
await knex('report_templates').where('id', id).del();
|
||||
}
|
||||
|
||||
async function getUserFieldsById(id) {
|
||||
const entity = await knex('report_templates').select(['user_fields']).where('id', id).first();
|
||||
if (!entity) {
|
||||
throw new interoperableErrors.NotFoundError();
|
||||
}
|
||||
|
||||
return JSON.parse(entity.user_fields);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
hash,
|
||||
getById,
|
||||
listDTAjax,
|
||||
create,
|
||||
updateWithConsistencyCheck,
|
||||
remove
|
||||
remove,
|
||||
getUserFieldsById
|
||||
};
|
|
@ -21,12 +21,15 @@ function hash(entity) {
|
|||
return hasher.hash(filterObject(entity, allowedKeys));
|
||||
}
|
||||
|
||||
async function getById(id) {
|
||||
const entity = await knex('reports').where('id', id).first();
|
||||
async function getByIdWithUserFields(id) {
|
||||
const entity = await knex('reports').where('reports.id', id).innerJoin('report_templates', 'reports.report_template', 'report_templates.id').select(['reports.id', 'reports.name', 'reports.description', 'reports.report_template', 'reports.params', 'report_templates.user_fields']).first();
|
||||
if (!entity) {
|
||||
throw new interoperableErrors.NotFoundError();
|
||||
}
|
||||
|
||||
entity.user_fields = JSON.parse(entity.user_fields);
|
||||
entity.params = JSON.parse(entity.params);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
@ -36,12 +39,14 @@ async function listDTAjax(params) {
|
|||
|
||||
async function create(entity) {
|
||||
await knex.transaction(async tx => {
|
||||
const id = await tx('reports').insert(filterObject(entity, allowedKeys));
|
||||
|
||||
if (!await tx('report_templates').select(['id']).where('id', entity.report_template).first()) {
|
||||
throw new interoperableErrors.DependencyNotFoundError();
|
||||
}
|
||||
|
||||
entity.params = JSON.stringify(entity.params);
|
||||
|
||||
const id = await tx('reports').insert(filterObject(entity, allowedKeys));
|
||||
|
||||
return id;
|
||||
});
|
||||
}
|
||||
|
@ -53,6 +58,8 @@ async function updateWithConsistencyCheck(entity) {
|
|||
throw new interoperableErrors.NotFoundError();
|
||||
}
|
||||
|
||||
existing.params = JSON.parse(existing.params);
|
||||
|
||||
const existingHash = hash(existing);
|
||||
if (existingHash != entity.originalHash) {
|
||||
throw new interoperableErrors.ChangedError();
|
||||
|
@ -62,6 +69,8 @@ async function updateWithConsistencyCheck(entity) {
|
|||
throw new interoperableErrors.DependencyNotFoundError();
|
||||
}
|
||||
|
||||
entity.params = JSON.stringify(entity.params);
|
||||
|
||||
await tx('reports').where('id', entity.id).update(filterObject(entity, allowedKeys));
|
||||
});
|
||||
}
|
||||
|
@ -87,7 +96,7 @@ async function bulkChangeState(oldState, newState) {
|
|||
module.exports = {
|
||||
ReportState,
|
||||
hash,
|
||||
getById,
|
||||
getByIdWithUserFields,
|
||||
listDTAjax,
|
||||
create,
|
||||
updateWithConsistencyCheck,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue