Implementation of archive route. Simplified from v1. Not tested.
This commit is contained in:
parent
a9e1700dbe
commit
dda95ecdb3
9 changed files with 320 additions and 272 deletions
|
@ -172,8 +172,8 @@ async function listTestUsersDTAjax(context, campaignId, params) {
|
|||
});
|
||||
}
|
||||
|
||||
async function rawGetByIdTx(tx, id) {
|
||||
const entity = await tx('campaigns').where('campaigns.id', id)
|
||||
async function rawGetByTx(tx, key, id) {
|
||||
const entity = await tx('campaigns').where('campaigns.' + key, id)
|
||||
.leftJoin('campaign_lists', 'campaigns.id', 'campaign_lists.campaign')
|
||||
.groupBy('campaigns.id')
|
||||
.select([
|
||||
|
@ -207,7 +207,7 @@ async function rawGetByIdTx(tx, id) {
|
|||
async function getByIdTx(tx, context, id, withPermissions = true, content = Content.ALL) {
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'campaign', id, 'view');
|
||||
|
||||
let entity = await rawGetByIdTx(tx, id);
|
||||
let entity = await rawGetByTx(tx, 'id', id);
|
||||
|
||||
if (content === Content.ALL || content === Content.RSS_ENTRY) {
|
||||
// Return everything
|
||||
|
@ -255,22 +255,6 @@ async function getById(context, id, withPermissions = true, content = Content.AL
|
|||
});
|
||||
}
|
||||
|
||||
async function getByCidTx(tx, context, cid) {
|
||||
const entity = await tx('campaigns').where('cid', cid).first();
|
||||
if (!entity) {
|
||||
shares.throwPermissionDenied();
|
||||
}
|
||||
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'campaign', entity.id, 'view');
|
||||
return entity;
|
||||
}
|
||||
|
||||
async function getByCid(context, cid) {
|
||||
return await knex.transaction(async tx => {
|
||||
return getByCidTx(tx, context, cid);
|
||||
});
|
||||
}
|
||||
|
||||
async function _validateAndPreprocess(tx, context, entity, isCreate, content) {
|
||||
if (content === Content.ALL || content === Content.WITHOUT_SOURCE_CUSTOM || content === Content.RSS_ENTRY) {
|
||||
await namespaceHelpers.validateEntity(tx, entity);
|
||||
|
@ -405,7 +389,7 @@ async function updateWithConsistencyCheck(context, entity, content) {
|
|||
await knex.transaction(async tx => {
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'campaign', entity.id, 'edit');
|
||||
|
||||
const existing = await rawGetByIdTx(tx, entity.id);
|
||||
const existing = await rawGetByTx(tx, 'id', entity.id);
|
||||
|
||||
const existingHash = hash(existing, content);
|
||||
if (existingHash !== entity.originalHash) {
|
||||
|
@ -745,4 +729,6 @@ module.exports.getSubscribersQueryGeneratorTx = getSubscribersQueryGeneratorTx;
|
|||
|
||||
module.exports.start = start;
|
||||
module.exports.stop = stop;
|
||||
module.exports.reset = reset;
|
||||
module.exports.reset = reset;
|
||||
|
||||
module.exports.rawGetBy = rawGetBy;
|
Loading…
Add table
Add a link
Reference in a new issue