Skip to content

Commit

Permalink
Remove duplicate data on load
Browse files Browse the repository at this point in the history
  • Loading branch information
ivank committed Jul 12, 2017
1 parent 47f7753 commit a0fd40b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongoose-subscriptions-braintree",
"version": "1.4.3",
"version": "1.4.4",
"description": "Braintree processor for mongoose-subscriptions",
"main": "src/index.js",
"repository": "[email protected]:enhancv/mongoose-subscriptions-braintree.git",
Expand Down
12 changes: 10 additions & 2 deletions src/customerProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const addressProcessor = require("./addressProcessor");
const paymentMethodProcessor = require("./paymentMethodProcessor");
const subscriptionProcessor = require("./subscriptionProcessor");
const transactionProcessor = require("./transactionProcessor");
const { getOr, uniqBy, get, flatten, map, orderBy, curry, set, uniqWith } = require("lodash/fp");
const { getOr, uniqBy, get, flatten, map, orderBy, curry, set } = require("lodash/fp");

const ProcessorItem = main.Schema.ProcessorItem;

Expand Down Expand Up @@ -121,7 +121,15 @@ function load(processor, customer) {
transactionProcessor.fields(customer)
);

customer.transactions = uniqWith((a, b) => a._id === b._id, customer.transactions);
customer.subscriptions = uniqBy(
subscription => subscription.processor.id || subscription._id,
customer.subscriptions
);
customer.paymentMethods = uniqBy(
paymentMethod => paymentMethod.processor.id || paymentMethod._id,
customer.paymentMethods
);
customer.transactions = uniqBy(transaction => transaction._id, customer.transactions);

return customer;
});
Expand Down

0 comments on commit a0fd40b

Please sign in to comment.