diff --git a/.vscode/settings.json b/.vscode/settings.json index 5767b748..51db7632 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,7 @@ { "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "explicit" }, "eslint.validate": [ "javascript", diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ef84ccf..6bdc87e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed + +- Fixed the return from skuFromRefIds and improve the return from getSkuSellerInfo ## [3.15.7] - 2024-09-26 diff --git a/node/package.json b/node/package.json index 5a1fc760..daf6d981 100644 --- a/node/package.json +++ b/node/package.json @@ -16,7 +16,7 @@ }, "dependencies": { "@gocommerce/utils": "^0.7.3", - "@vtex/api": "6.46.1", + "@vtex/api": "6.47.0", "atob": "^2.1.2", "axios": "^0.19.0", "camelcase": "^5.0.0", diff --git a/node/resolvers/search/index.ts b/node/resolvers/search/index.ts index 3ac23bd6..a4501393 100644 --- a/node/resolvers/search/index.ts +++ b/node/resolvers/search/index.ts @@ -181,9 +181,9 @@ const getSkuSellerInfo = (simulationResults: any, result: any) => { if (Object.keys(simulationResults).length !== 0) { items = result.map((item: any) => { - const skuInfoBySeller = item.sellers?.map((seller: any) => { + const skuInfoBySeller = item.sellers?.flatMap((seller: any) => { if (!simulationResults[item.sku]) { - return null + return []; } const currSeller = simulationResults[item.sku].sellers.find( @@ -210,7 +210,7 @@ const getSkuSellerInfo = (simulationResults: any, result: any) => { return { ...item, - sellers: item.sellers ? skuInfoBySeller : null, + sellers: skuInfoBySeller, } }) } @@ -297,8 +297,20 @@ export const queries = { }, ctx ).then(simulationResults => { - // include SKU's availability and unit multiplier info in given seller - items = getSkuSellerInfo(simulationResults, result) + if (Object.keys(simulationResults).length !== 0) { + // include SKU's availability and unit multiplier info in given seller + items = getSkuSellerInfo(simulationResults, result) + } else { + // ensures that each item in the result array has a sellers array that only includes sellers with a defined and non-null availability property. + // If no such sellers exist, the sellers array will be empty. + items = result.map((item: { sellers: any[] }) => ({ + ...item, + sellers: item.sellers?.filter((seller: any) => + 'availability' in seller && + seller.availability !== null + ) || [] + })) + } }) } catch (error) { logger.error({ diff --git a/node/yarn.lock b/node/yarn.lock index 1ad2e985..6ee9c44f 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -1863,10 +1863,10 @@ resolved "https://registry.yarnpkg.com/@types/zen-observable/-/zen-observable-0.8.0.tgz#8b63ab7f1aa5321248aad5ac890a485656dcea4d" integrity sha512-te5lMAWii1uEJ4FwLjzdlbw3+n0FZNOvFXHxQDKeT0dilh7HOzdMzV2TrJVUzq8ep7J4Na8OUYPRLSQkJHAlrg== -"@vtex/api@6.46.1": - version "6.46.1" - resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.46.1.tgz#55a8755ae48f5400e7f1ed1921cd547950bb7a2a" - integrity sha512-geoxVvyWoQpOQ70Zmx3M8SBkRoGOS/bp9Gy26M+iCue63jofVSwmFz1zf66EaHA1PKOJNRgQPFwY+oeDE1U2lQ== +"@vtex/api@6.47.0": + version "6.47.0" + resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.47.0.tgz#6910455d593d8bb76f1f4f2b7660023853fda35e" + integrity sha512-t9gt7Q89EMbSj3rLhho+49Fv+/lQgiy8EPVRgtmmXFp1J4v8hIAZF7GPjCPie111KVs4eG0gfZFpmhA5dafKNA== dependencies: "@types/koa" "^2.11.0" "@types/koa-compose" "^3.2.3" @@ -6071,7 +6071,7 @@ static-extend@^0.1.1: define-property "^0.2.5" object-copy "^0.1.0" -stats-lite@vtex/node-stats-lite#dist: +"stats-lite@github:vtex/node-stats-lite#dist": version "2.2.0" resolved "https://codeload.github.com/vtex/node-stats-lite/tar.gz/1b0d39cc41ef7aaecfd541191f877887a2044797" dependencies: