Skip to content

Commit

Permalink
Merge pull request #50 from gabrielMatosBoubee/productList-Transform-…
Browse files Browse the repository at this point in the history
…VNDA

Product list transform vnda
  • Loading branch information
matheusgr authored Sep 14, 2023
2 parents ec1c614 + 45df590 commit def14b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions vnda/loaders/productList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export interface Props {

/** @description search for products that have certain tag */
tags?: string[];

/** @description search for products by id */
ids: number[];
}

/**
Expand All @@ -38,6 +41,7 @@ const productListLoader = async (
sort: props?.sort,
per_page: props?.count,
"tags[]": props?.tags,
"ids[]": props?.ids,
}, STALE).then((res) => res.json());

return search.results?.map((product) =>
Expand Down
17 changes: 16 additions & 1 deletion vnda/utils/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ const toPropertyValue = (variant: VNDAProduct): PropertyValue[] =>
} as PropertyValue)
).filter((x): x is PropertyValue => Boolean(x));

const toPropertyValueTags = (tags: ProductSearch["tags"]): PropertyValue[] =>
tags?.map((tag) =>
tag && ({
"@type": "PropertyValue",
name: tag.name,
value: JSON.stringify(tag),
valueReference: "TAGS",
} as PropertyValue)
);

// deno-lint-ignore no-explicit-any
const isProductVariant = (p: any): p is VariantProductSearch =>
typeof p.id === "number";
Expand Down Expand Up @@ -191,14 +201,19 @@ export const toProduct = (
const offer = toOffer(variant);
const offers = offer ? [offer] : [];

const myTags = "tags" in product ? product.tags : [];

return {
"@type": "Product",
productID,
sku: productID,
url: variantUrl,
name: product.name,
description: product.description,
additionalProperty: toPropertyValue(variant),
additionalProperty: [
...toPropertyValue(variant),
...toPropertyValueTags(myTags),
],
inProductGroupWithID: productGroupID,
gtin: product.reference,
isVariantOf: {
Expand Down

0 comments on commit def14b3

Please sign in to comment.