2017-07-11 09:28:44 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const knex = require('../lib/knex');
|
|
|
|
const dtHelpers = require('../lib/dt-helpers');
|
2017-07-13 11:27:03 +00:00
|
|
|
const interoperableErrors = require('../shared/interoperable-errors');
|
2017-08-13 18:11:58 +00:00
|
|
|
const shares = require('./shares');
|
2017-07-11 09:28:44 +00:00
|
|
|
|
|
|
|
async function listDTAjax(params) {
|
2017-08-13 18:11:58 +00:00
|
|
|
return await dtHelpers.ajaxListWithPermissions(
|
|
|
|
context,
|
|
|
|
[{ entityTypeId: 'campaign', requiredOperations: ['view'] }],
|
|
|
|
params,
|
|
|
|
builder => builder.from('campaigns')
|
|
|
|
.innerJoin('namespaces', 'namespaces.id', 'campaigns.namespace'),
|
|
|
|
['campaigns.id', 'campaigns.name', 'campaigns.description', 'campaigns.status', 'campaigns.created']
|
|
|
|
);
|
2017-07-11 09:28:44 +00:00
|
|
|
|
2017-08-13 18:11:58 +00:00
|
|
|
}
|
2017-07-13 11:27:03 +00:00
|
|
|
|
2017-08-13 18:11:58 +00:00
|
|
|
async function getById(context, id) {
|
|
|
|
return await knex.transaction(async tx => {
|
|
|
|
await shares.enforceEntityPermissionTx(tx, context, 'campaign', 'view');
|
|
|
|
const entity = await tx('campaigns').where('id', id).first();
|
|
|
|
entity.permissions = await shares.getPermissionsTx(tx, context, 'campaign', id);
|
|
|
|
return entity;
|
|
|
|
});
|
2017-07-13 11:27:03 +00:00
|
|
|
}
|
2017-07-11 09:28:44 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2017-07-13 11:27:03 +00:00
|
|
|
listDTAjax,
|
|
|
|
getById
|
2017-07-11 09:28:44 +00:00
|
|
|
};
|