From 09e948630c60de3af01ad9538166cdd52b41195a Mon Sep 17 00:00:00 2001 From: YulikK Date: Sun, 26 May 2024 20:06:21 +0200 Subject: [PATCH] feat: add total count for products --- src/shared/API/product/model/ProductModel.ts | 10 ++++++++++ src/shared/API/types/type.ts | 1 + 2 files changed, 11 insertions(+) diff --git a/src/shared/API/product/model/ProductModel.ts b/src/shared/API/product/model/ProductModel.ts index e5474f93..91b7b14f 100644 --- a/src/shared/API/product/model/ProductModel.ts +++ b/src/shared/API/product/model/ProductModel.ts @@ -296,6 +296,14 @@ export class ProductModel { return category; } + private getTotalFromData(data: ClientResponse): number { + let total = 0; + if (isClientResponse(data) && isProductProjectionPagedQueryResponse(data.body)) { + total = data.body.total || 0; + } + return total; + } + public adaptLocalizationValue(data: LocalizedString | undefined): localization[] { const result: localization[] = []; Object.entries(data || {}).forEach(([language, value]) => { @@ -341,11 +349,13 @@ export class ProductModel { const sizeCount = this.getSizeProductCountFromData(data); const categoryCount = this.getCategoriesProductCountFromData(data); const priceRange = this.getPriceRangeFromData(data); + const total = this.getTotalFromData(data); const result: ProductWithCount = { categoryCount, priceRange, products, sizeCount, + total, }; return result; } diff --git a/src/shared/API/types/type.ts b/src/shared/API/types/type.ts index 573fe0c6..b6653d00 100644 --- a/src/shared/API/types/type.ts +++ b/src/shared/API/types/type.ts @@ -77,4 +77,5 @@ export type ProductWithCount = { priceRange: PriceRange; products: Product[]; sizeCount: SizeProductCount[]; + total: number; };