From 4b7c100b3d417e3251ee8fd11c9444fe33870159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Sun, 14 Dec 2025 20:09:32 +0300 Subject: [PATCH] add best offer flag --- src/catalog/catalog.service.ts | 17 +++++++++++++---- src/catalog/dto/catalog-item.dto.ts | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/catalog/catalog.service.ts b/src/catalog/catalog.service.ts index 775e3d3..8ebd880 100644 --- a/src/catalog/catalog.service.ts +++ b/src/catalog/catalog.service.ts @@ -270,14 +270,23 @@ export class CatalogService { ({ isFeatured }) => !isFeatured, ); - const featuredYacthIndex = clonedCatalog.findIndex( + const featuredYachtIndex = clonedCatalog.findIndex( (item) => item.isFeatured === true, ); - if (featuredYacthIndex !== -1) { + if (featuredYachtIndex !== -1) { + const minCost = Math.min( + ...filteredCatalog.map((item) => item.minCost || Infinity), + ); + + const mappedRestYachts = filteredCatalog.slice(0, 6).map((item) => ({ + ...item, + isBestOffer: item.minCost === minCost, + })); + return { - featuredYacht: clonedCatalog[featuredYacthIndex], - restYachts: filteredCatalog.slice(0, 6), + featuredYacht: clonedCatalog[featuredYachtIndex], + restYachts: mappedRestYachts, }; } diff --git a/src/catalog/dto/catalog-item.dto.ts b/src/catalog/dto/catalog-item.dto.ts index 8c07837..859b642 100644 --- a/src/catalog/dto/catalog-item.dto.ts +++ b/src/catalog/dto/catalog-item.dto.ts @@ -9,4 +9,5 @@ export class CatalogItemDto { hasQuickRent: boolean; isFeatured: boolean; topText?: string; + isBestOffer?: boolean; }