Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add stats to adapter #1649

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions packages/x-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from './previewable.model';
export * from './promoted.model';
export * from './redirection.model';
export * from './sort.model';
export * from './stats.model';
export * from './suggestion.model';
export * from './tagging.model';
export * from './user-info.model';
Expand Down
2 changes: 2 additions & 0 deletions packages/x-types/src/response/search-response.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Promoted } from '../promoted.model';
import { TaggingRequest } from '../request/tagging-request.model';
import { Redirection } from '../redirection.model';
import { Result } from '../result/result.model';
import { Stats } from '../stats.model';

/**
* Response for the search endpoint.
Expand All @@ -21,5 +22,6 @@ export interface SearchResponse {
redirections?: Redirection[];
results: Result[];
spellcheck?: string;
stats?: Stats;
totalResults: number;
}
8 changes: 8 additions & 0 deletions packages/x-types/src/stats.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* The stats model.
*
* @public
*/
export interface Stats {
price: { min: number; max: number };
}
Loading