From 45df5903de839788197bd3f78eab8d9a902a7609 Mon Sep 17 00:00:00 2001 From: gabrielMatosBoubee Date: Thu, 14 Sep 2023 15:06:29 -0300 Subject: [PATCH] feat: add productList search by id (Prop) and tags return in transform --- vnda/loaders/productList.ts | 4 ++-- vnda/utils/transform.ts | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/vnda/loaders/productList.ts b/vnda/loaders/productList.ts index f737cd040..e79ce5e51 100644 --- a/vnda/loaders/productList.ts +++ b/vnda/loaders/productList.ts @@ -20,7 +20,7 @@ export interface Props { tags?: string[]; /** @description search for products by id */ - ids: number[] + ids: number[]; } /** @@ -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) => diff --git a/vnda/utils/transform.ts b/vnda/utils/transform.ts index 4e10713e3..559d09e08 100644 --- a/vnda/utils/transform.ts +++ b/vnda/utils/transform.ts @@ -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 => @@ -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", @@ -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: {