Skip to content

Commit

Permalink
fix: Cart item with additionalProperty (#1325)
Browse files Browse the repository at this point in the history
* id non required

* fix validateCart logic
  • Loading branch information
tlgimenes authored May 30, 2022
1 parent 5bce52b commit 8fa6aa1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions packages/api/src/__generated__/schema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions packages/api/src/platforms/vtex/resolvers/validateCart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
IStoreCart,
IStoreOffer,
IStoreOrder,
IStorePropertyValue,
} from '../../../__generated__/schema'
import type {
OrderForm,
Expand All @@ -20,17 +21,18 @@ import {

type Indexed<T> = T & { index?: number }

const getAttachments = (item: IStoreOffer) =>
item.itemOffered.additionalProperty?.filter(
(i) => i.valueReference === VALUE_REFERENCES.attachment
)
const isAttachment = (value: IStorePropertyValue) =>
value.valueReference === VALUE_REFERENCES.attachment

const getId = (item: IStoreOffer) =>
[
item.itemOffered.sku,
item.seller.identifier,
item.price,
item.itemOffered.additionalProperty?.map(getPropertyId).join('-'),
item.itemOffered.additionalProperty
?.filter(isAttachment)
.map(getPropertyId)
.join('-'),
]
.filter(Boolean)
.join('::')
Expand Down Expand Up @@ -59,7 +61,9 @@ const offerToOrderItemInput = (
seller: offer.seller.identifier,
id: offer.itemOffered.sku,
index: offer.index,
attachments: (getAttachments(offer) ?? []).map((attachment) => ({
attachments: (
offer.itemOffered.additionalProperty?.filter(isAttachment) ?? []
).map((attachment) => ({
name: attachment.name,
content: attachment.value,
})),
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/typeDefs/propertyValue.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ type StorePropertyValue {
}

input IStorePropertyValue {
"""
Property id. This propert changes according to the content of the object.
"""
propertyID: String
"""
Property value. May hold a string or the string representation of an object.
"""
Expand Down

1 comment on commit 8fa6aa1

@vercel
Copy link

@vercel vercel bot commented on 8fa6aa1 May 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.