Skip to content

Commit

Permalink
Refactor product update to replace locations instead of concatenating
Browse files Browse the repository at this point in the history
  • Loading branch information
jamalsoueidan committed May 30, 2024
1 parent 4f99e73 commit 26af379
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions src/functions/customer/services/product/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,7 @@ export const CustomerProductServiceUpdate = async (
productId,
});

const locations = oldProduct.locations.concat(
(body.locations || [])?.filter(
(item2) =>
!oldProduct.locations.some(
(item1) => item1.location.toString() === item2.location.toString() // must use toString since location could be type of objectId
)
)
);
const locations = !body.locations ? oldProduct.locations : body.locations;

const newProduct = {
...oldProduct,
Expand Down

0 comments on commit 26af379

Please sign in to comment.