From ca90991de1555769b162c3f6b9430e58561dc2f2 Mon Sep 17 00:00:00 2001 From: Robert Field Date: Mon, 26 Aug 2024 18:45:40 +0100 Subject: [PATCH] feat: add util for extracting image --- .../sdks/shopper/src/utils/extract-product-image.ts | 12 ++++++++++++ packages/sdks/shopper/src/utils/index.ts | 1 + 2 files changed, 13 insertions(+) create mode 100644 packages/sdks/shopper/src/utils/extract-product-image.ts create mode 100644 packages/sdks/shopper/src/utils/index.ts diff --git a/packages/sdks/shopper/src/utils/extract-product-image.ts b/packages/sdks/shopper/src/utils/extract-product-image.ts new file mode 100644 index 00000000..4290be26 --- /dev/null +++ b/packages/sdks/shopper/src/utils/extract-product-image.ts @@ -0,0 +1,12 @@ +import { Included, Product } from "../client" + +export const extractProductImage = ( + product: Product, + images: Included["main_images"], +) => { + return images?.find((file) => { + if (file.id === product.relationships?.main_image?.data?.id) { + return file + } + }) +} diff --git a/packages/sdks/shopper/src/utils/index.ts b/packages/sdks/shopper/src/utils/index.ts new file mode 100644 index 00000000..a3175f1d --- /dev/null +++ b/packages/sdks/shopper/src/utils/index.ts @@ -0,0 +1 @@ +export { extractProductImage } from "./extract-product-image"