From 14b94ecf4c4a1f642232c74c22a50f4110976519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20CG?= Date: Thu, 31 Oct 2024 15:58:25 +0100 Subject: [PATCH] feat: add stats to search adapter (#1649) --- .../src/schemas/models/stats.schema.ts | 15 +++++++++++++++ .../schemas/responses/search-response.schema.ts | 5 +++++ .../src/types/models/stats.model.ts | 8 ++++++++ .../src/types/responses/search-response.model.ts | 6 ++++++ 4 files changed, 34 insertions(+) create mode 100644 packages/x-adapter-platform/src/schemas/models/stats.schema.ts create mode 100644 packages/x-adapter-platform/src/types/models/stats.model.ts diff --git a/packages/x-adapter-platform/src/schemas/models/stats.schema.ts b/packages/x-adapter-platform/src/schemas/models/stats.schema.ts new file mode 100644 index 0000000000..e276615beb --- /dev/null +++ b/packages/x-adapter-platform/src/schemas/models/stats.schema.ts @@ -0,0 +1,15 @@ +import { createMutableSchema } from '@empathyco/x-adapter'; +import { Stats } from '@empathyco/x-types'; +import { PlatformStats } from '../../types/models/stats.model'; + +/** + * Default implementation for the Stats schema. + * + * @public + */ +export const statsSchema = createMutableSchema({ + price: { + min: ({ price }) => Number(price.min), + max: ({ price }) => Number(price.max) + } +}); diff --git a/packages/x-adapter-platform/src/schemas/responses/search-response.schema.ts b/packages/x-adapter-platform/src/schemas/responses/search-response.schema.ts index eee6ceb8e4..a1d876e3ac 100644 --- a/packages/x-adapter-platform/src/schemas/responses/search-response.schema.ts +++ b/packages/x-adapter-platform/src/schemas/responses/search-response.schema.ts @@ -8,6 +8,7 @@ import { partialResultsSchema } from '../models/partial-results.schema'; import { promotedSchema } from '../models/promoted.schema'; import { redirectionSchema } from '../models/redirection.schema'; import { resultSchema } from '../models/result.schema'; +import { statsSchema } from '../models/stats.schema'; /** * Default implementation for the SearchResponseSchema. @@ -41,6 +42,10 @@ export const searchResponseSchema = createMutableSchema getTaggingInfoFromUrl(catalog?.tagging?.query), displayTagging: ({ catalog }) => getDisplayTaggingInfoFromUrl(catalog?.tagging?.display) }); diff --git a/packages/x-adapter-platform/src/types/models/stats.model.ts b/packages/x-adapter-platform/src/types/models/stats.model.ts new file mode 100644 index 0000000000..74efab8821 --- /dev/null +++ b/packages/x-adapter-platform/src/types/models/stats.model.ts @@ -0,0 +1,8 @@ +/** + * Stats model for the `platform` API. + * + * @public + */ +export interface PlatformStats { + price: { min: number; max: number }; +} diff --git a/packages/x-adapter-platform/src/types/responses/search-response.model.ts b/packages/x-adapter-platform/src/types/responses/search-response.model.ts index a93b9c9bb3..36531ce801 100644 --- a/packages/x-adapter-platform/src/types/responses/search-response.model.ts +++ b/packages/x-adapter-platform/src/types/responses/search-response.model.ts @@ -24,6 +24,12 @@ export interface PlatformSearchResponse { query: string; display: string; }; + stats: { + price: { + min: number; + max: number; + }; + }; }; direct: { content: PlatformRedirection[];