fix(medusa): Use get for creating fulfillments (#3498)

* use get

* changeset

* use set

* add tests

---------

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Philip Korsholm
2023-03-16 19:03:36 +01:00
committed by GitHub
co-authored by Oliver Windall Juhl
parent fe4b8feb7e
commit 0d1b63d773
3 changed files with 176 additions and 22 deletions
@@ -114,8 +114,8 @@ export default async (req, res) => {
await orderServiceTx.retrieve(id, {
relations: ["fulfillments"],
})
const existingFulfillmentMap = new Map(
existingFulfillments.map((fulfillment) => [fulfillment.id, fulfillment])
const existingFulfillmentSet = new Set(
existingFulfillments.map((fulfillment) => fulfillment.id)
)
await orderServiceTx.createFulfillment(id, validatedBody.items, {
@@ -137,7 +137,7 @@ export default async (req, res) => {
pvInventoryService.withTransaction(transactionManager)
await updateInventoryAndReservations(
fulfillments.filter((f) => !existingFulfillmentMap[f.id]),
fulfillments.filter((f) => !existingFulfillmentSet.has(f.id)),
{
inventoryService: pvInventoryServiceTx,
locationId: validatedBody.location_id,