Skip to content

Commit

Permalink
Apply request changes to fix channel
Browse files Browse the repository at this point in the history
  • Loading branch information
igorbrasileiro committed Mar 30, 2022
1 parent d7260dc commit 447a842
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions packages/api/src/platforms/vtex/resolvers/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,22 @@ import type {
} from '../../../__generated__/schema'
import type { CategoryTree } from '../clients/commerce/types/CategoryTree'
import type { Context } from '../index'
import ChannelMarshal from '../utils/channel'

export const Query = {
product: async (_: unknown, { locator }: QueryProductArgs, ctx: Context) => {
// Insert channel in context for later usage
ctx.storage = {
...ctx.storage,
channel:
// TODO: Check if make sense move this parse a layer down or pass the whole parsed channel
// TODO: Put the channel from ctx inside the parse
ChannelMarshal.parse(
locator.find((facet) => facet.key === 'channel')?.value ?? '{}'
).salesChannel || ctx.storage.channel,
locator.find((facet) => facet.key === 'channel')?.value ??
ctx.storage.channel,
}

const {
loaders: { skuLoader },
} = ctx

return skuLoader.load(locator.map(transformSelectedFacet).flat())
return skuLoader.load(locator.flatMap(transformSelectedFacet))
},
collection: (_: unknown, { slug }: QueryCollectionArgs, ctx: Context) => {
const {
Expand All @@ -48,12 +44,8 @@ export const Query = {
ctx.storage = {
...ctx.storage,
channel:
// TODO: Check if make sense move this parse a layer down or pass the whole parsed channel
// TODO: Put the channel from ctx inside the parse
ChannelMarshal.parse(
selectedFacets?.find((facet) => facet.key === 'channel')?.value ??
'{}'
).salesChannel || ctx.storage.channel,
selectedFacets?.find((facet) => facet.key === 'channel')?.value ??
ctx.storage.channel,
}

const after = maybeAfter ? Number(maybeAfter) : 0
Expand All @@ -62,7 +54,7 @@ export const Query = {
count: first,
query: term,
sort: SORT_MAP[sort ?? 'score_desc'],
selectedFacets: selectedFacets?.map(transformSelectedFacet).flat() ?? [],
selectedFacets: selectedFacets?.flatMap(transformSelectedFacet) ?? [],
}

return searchArgs
Expand Down

0 comments on commit 447a842

Please sign in to comment.