Skip to content

Commit

Permalink
feat(crossselling): parametrize "groupByProduct
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobernardina committed Aug 9, 2023
1 parent 52c51aa commit 1b34690
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added
- `groupByProduct` param to `crossSelling` query.
- `groupByProduct` param to `productRecommendations` query.
- `quantity` param to `Recommendation.similars` resolver.

## [1.65.1] - 2023-04-24

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions node/clients/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ export class Search extends AppClient {
metric: 'search-category',
})

public crossSelling = (id: string, type: SearchCrossSellingTypes) =>
public crossSelling = (id: string, type: SearchCrossSellingTypes, groupByProduct = true) =>
this.get<SearchProduct[]>(
`/pub/products/crossselling/${type}/${id}?groupByProduct=true`,
`/pub/products/crossselling/${type}/${id}?groupByProduct=${groupByProduct}`,
{
metric: 'search-crossSelling',
}
Expand Down
6 changes: 4 additions & 2 deletions node/resolvers/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ enum CrossSellingInput {
interface ProductRecommendationArg {
identifier?: ProductIndentifier
type?: CrossSellingInput
groupByProduct?: boolean
}

interface ProductsByIdentifierArgs {
Expand Down Expand Up @@ -541,7 +542,7 @@ export const queries = {

productRecommendations: async (
_: any,
{ identifier, type }: ProductRecommendationArg,
{ identifier, type, groupByProduct = true }: ProductRecommendationArg,
ctx: Context
) => {
if (identifier == null || type == null) {
Expand All @@ -556,7 +557,8 @@ export const queries = {

const products = await ctx.clients.search.crossSelling(
productId,
searchType
searchType,
groupByProduct
)

searchFirstElements(products, 0, ctx.clients.search)
Expand Down
11 changes: 9 additions & 2 deletions node/resolvers/search/recommendation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { SearchCrossSellingTypes } from './utils'

type SimilarProductsQuantityEnum = 'ALL_AVAILABLE' | 'DEFAULT'

export const resolvers = {
Recommendation: {
buy: (
Expand All @@ -14,9 +16,14 @@ export const resolvers = {

similars: (
{ productId }: SearchProduct,
_: any,
{ quantity = 'DEFAULT' }: { quantity: SimilarProductsQuantityEnum },
{ clients: { search } }: Context
) => search.crossSelling(productId, SearchCrossSellingTypes.similars),
) => {
// Let's keep this variable name explicit
const groupByProduct = quantity !== 'ALL_AVAILABLE';

return search.crossSelling(productId, SearchCrossSellingTypes.similars, groupByProduct)
},

view: (
{ productId }: SearchProduct,
Expand Down

0 comments on commit 1b34690

Please sign in to comment.