Skip to content

Commit

Permalink
Merge pull request #1118 from flexion/task/962_sent_box
Browse files Browse the repository at this point in the history
962 - Prevent Outbox Entries
  • Loading branch information
codyseibert authored Mar 15, 2019
2 parents 534b815 + 5cdadcf commit d987290
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ exports.completeWorkItem = async ({

await applicationContext.getPersistenceGateway().saveWorkItem({
applicationContext,
createOutboxEntries: true,
workItemToSave: completedWorkItem,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ exports.forwardWorkItem = async ({

return applicationContext.getPersistenceGateway().saveWorkItem({
applicationContext,
createOutboxEntries: true,
workItemToSave: workItemToForward.validate().toRawObject(),
});
};
40 changes: 23 additions & 17 deletions shared/src/persistence/dynamo/workitems/saveWorkItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ const { stripInternalKeys } = require('../../dynamo/helpers/stripInternalKeys');
const { getCaseByCaseId } = require('../cases/getCaseByCaseId');
const { saveVersionedCase } = require('../cases/saveCase');

exports.saveWorkItem = async ({ workItemToSave, applicationContext }) => {
exports.saveWorkItem = async ({
workItemToSave,
createOutboxEntries,
applicationContext,
}) => {
const user = applicationContext.getCurrentUser();

const existingWorkItem = await getWorkItemById({
Expand Down Expand Up @@ -40,23 +44,25 @@ exports.saveWorkItem = async ({ workItemToSave, applicationContext }) => {
existingVersion: (caseToUpdate || {}).currentVersion,
});

await client.put({
applicationContext,
Item: {
pk: `${user.userId}|outbox`,
sk: new Date().toISOString(),
...workItemToSave,
},
});
if (createOutboxEntries) {
await client.put({
applicationContext,
Item: {
pk: `${user.userId}|outbox`,
sk: new Date().toISOString(),
...workItemToSave,
},
});

await client.put({
applicationContext,
Item: {
pk: `${user.section}|outbox`,
sk: new Date().toISOString(),
...workItemToSave,
},
});
await client.put({
applicationContext,
Item: {
pk: `${user.section}|outbox`,
sk: new Date().toISOString(),
...workItemToSave,
},
});
}

const workItem = await client.put({
applicationContext,
Expand Down

0 comments on commit d987290

Please sign in to comment.