Skip to content

Commit

Permalink
feat: add productList search by id (Prop) and tags return in transform
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielMatosBoubee committed Sep 14, 2023
1 parent b2d05a4 commit 45df590
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions vnda/loaders/productList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface Props {
tags?: string[];

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

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

return search.results?.map((product) =>
Expand Down
25 changes: 14 additions & 11 deletions vnda/utils/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ 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)
)
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 =>
Expand Down Expand Up @@ -201,7 +201,7 @@ export const toProduct = (
const offer = toOffer(variant);
const offers = offer ? [offer] : [];

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

return {
"@type": "Product",
Expand All @@ -210,7 +210,10 @@ export const toProduct = (
url: variantUrl,
name: product.name,
description: product.description,
additionalProperty: [...toPropertyValue(variant), ...toPropertyValueTags(myTags) ],
additionalProperty: [
...toPropertyValue(variant),
...toPropertyValueTags(myTags),
],
inProductGroupWithID: productGroupID,
gtin: product.reference,
isVariantOf: {
Expand Down

0 comments on commit 45df590

Please sign in to comment.