2017-07-13 11:27:03 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const knex = require('../lib/knex');
|
|
|
|
const dtHelpers = require('../lib/dt-helpers');
|
|
|
|
const interoperableErrors = require('../shared/interoperable-errors');
|
2017-08-13 18:11:58 +00:00
|
|
|
const shares = require('./shares');
|
|
|
|
const fields = require('./fields');
|
|
|
|
const { SubscriptionStatus } = require('../shared/lists');
|
2017-08-19 13:12:22 +00:00
|
|
|
const segments = require('./segments');
|
|
|
|
|
2017-07-13 11:27:03 +00:00
|
|
|
|
2017-08-13 18:11:58 +00:00
|
|
|
const allowedKeysBase = new Set(['cid', 'email']);
|
2017-07-13 11:27:03 +00:00
|
|
|
|
2017-08-13 18:11:58 +00:00
|
|
|
function hash(entity) {
|
|
|
|
const allowedKeys = allowedKeysBase.slice();
|
|
|
|
|
|
|
|
// TODO add keys from custom fields
|
|
|
|
|
|
|
|
return hasher.hash(filterObject(entity, allowedKeys));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-19 13:12:22 +00:00
|
|
|
async function listDTAjax(context, listId, segmentId, params) {
|
2017-08-13 18:11:58 +00:00
|
|
|
return await knex.transaction(async tx => {
|
|
|
|
await shares.enforceEntityPermissionTx(tx, context, 'list', listId, 'viewSubscriptions');
|
|
|
|
|
|
|
|
const flds = await fields.listByOrderListTx(tx, listId, ['column']);
|
2017-08-19 13:12:22 +00:00
|
|
|
const addSegmentQuery = segmentId ? await segments.getQueryGeneratorTx(tx, listId, segmentId) : () => {};
|
2017-08-13 18:11:58 +00:00
|
|
|
|
|
|
|
return await dtHelpers.ajaxListTx(
|
|
|
|
tx,
|
|
|
|
params,
|
2017-08-19 13:12:22 +00:00
|
|
|
builder => {
|
|
|
|
const query = builder.from(`subscription__${listId}`);
|
|
|
|
query.where(function() {
|
|
|
|
addSegmentQuery(this);
|
|
|
|
});
|
|
|
|
return query;
|
|
|
|
},
|
2017-08-13 18:11:58 +00:00
|
|
|
['id', 'cid', 'email', 'status', 'created', ...flds.map(fld => fld.column)]
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function list(context, listId) {
|
|
|
|
return await knex.transaction(async tx => {
|
|
|
|
await shares.enforceEntityPermissionTx(tx, context, 'list', listId, 'viewSubscriptions');
|
|
|
|
|
|
|
|
return await tx(`subscription__${listId}`);
|
|
|
|
});
|
2017-07-13 11:27:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
2017-08-13 18:11:58 +00:00
|
|
|
list,
|
|
|
|
listDTAjax
|
2017-07-13 11:27:03 +00:00
|
|
|
};
|