Skip to content

Commit

Permalink
feat: add stats to search adapter (#1649)
Browse files Browse the repository at this point in the history
  • Loading branch information
victorcg88 authored Oct 31, 2024
1 parent c20f050 commit 14b94ec
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/x-adapter-platform/src/schemas/models/stats.schema.ts
Original file line number Diff line number Diff line change
@@ -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<PlatformStats, Stats>({
price: {
min: ({ price }) => Number(price.min),
max: ({ price }) => Number(price.max)
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -41,6 +42,10 @@ export const searchResponseSchema = createMutableSchema<PlatformSearchResponse,
$path: 'catalog.partials',
$subSchema: partialResultsSchema
},
stats: {
$path: 'catalog.stats',
$subSchema: statsSchema
},
queryTagging: ({ catalog }) => getTaggingInfoFromUrl(catalog?.tagging?.query),
displayTagging: ({ catalog }) => getDisplayTaggingInfoFromUrl(catalog?.tagging?.display)
});
8 changes: 8 additions & 0 deletions packages/x-adapter-platform/src/types/models/stats.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Stats model for the `platform` API.
*
* @public
*/
export interface PlatformStats {
price: { min: number; max: number };
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export interface PlatformSearchResponse {
query: string;
display: string;
};
stats: {
price: {
min: number;
max: number;
};
};
};
direct: {
content: PlatformRedirection[];
Expand Down

0 comments on commit 14b94ec

Please sign in to comment.