Skip to content

Commit

Permalink
feat: Add the JSONItem document as from in the CREATED and UPDATED event
Browse files Browse the repository at this point in the history
  • Loading branch information
Plopix committed Feb 20, 2024
1 parent 9e727e3 commit 14b396d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-bees-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@crystallize/import-utilities': minor
---

Add the JSONItem document as from in the CREATED and UPDATED event
34 changes: 18 additions & 16 deletions src/bootstrap-tenant/bootstrapper/items/createOrUpdateItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ export async function createOrUpdateItem(
type: shape.type,
identifier: shape.identifier,
},
from: item,
} as ItemEventPayloadCreatedOrUpdated)

return responses
Expand Down Expand Up @@ -427,13 +428,13 @@ export async function createOrUpdateItem(
id,
...(p.initial && {
initial: subscriptionPlanPrincingJsonToInput(
p.initial,
meteredVariables
p.initial,
meteredVariables
),
}),
recurring: subscriptionPlanPrincingJsonToInput(
p.recurring,
meteredVariables
p.recurring,
meteredVariables
),
}
}),
Expand Down Expand Up @@ -461,18 +462,18 @@ export async function createOrUpdateItem(
inp.variants.push(
...existingProductVariants.map(
({ priceVariants, stockLocations, components, ...rest }) =>
({
...rest,
priceVariants: priceVariants?.map((p) => ({
identifier: p.identifier,
price: p.price,
})),
stockLocations: stockLocations?.map((p) => ({
identifier: p.identifier,
stock: p.stock,
meta: p.meta,
})),
} as CreateProductVariantInput)
({
...rest,
priceVariants: priceVariants?.map((p) => ({
identifier: p.identifier,
price: p.price,
})),
stockLocations: stockLocations?.map((p) => ({
identifier: p.identifier,
stock: p.stock,
meta: p.meta,
})),
} as CreateProductVariantInput)
)
)
}
Expand Down Expand Up @@ -679,6 +680,7 @@ export async function createOrUpdateItem(
type: shape.type,
identifier: shape.identifier,
},
from: item,
} as ItemEventPayloadCreatedOrUpdated)

// Set the component data for the item
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap-tenant/bootstrapper/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export type ItemEventPayloadCreatedOrUpdated = ItemEventPayload & {
type: 'product' | 'document' | 'folder'
identifier: string
}
from: JSONItem
}
// Lets keep this old type in order to not break things.
export type ItemCreatedOrUpdated = ItemEventPayloadCreatedOrUpdated
Expand Down

0 comments on commit 14b396d

Please sign in to comment.