Skip to content

Commit

Permalink
Add simulationBehavior only1P
Browse files Browse the repository at this point in the history
  • Loading branch information
thalytafabrine authored and hiagolcm committed Sep 30, 2021
1 parent 54d9a86 commit ce6e50e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion node/commons/compatibility-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface OrderFormItemBySeller {
export const convertBiggyProduct = async (
product: BiggySearchProduct,
checkout: Checkout,
simulationBehavior: 'skip' | 'default' | null,
simulationBehavior: 'skip' | 'only1P' | 'default' | null,
segment?: SegmentData,
tradePolicy?: string,
regionId?: string | null,
Expand Down
2 changes: 1 addition & 1 deletion node/commons/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { queries } from '../resolvers/search'
interface ConvertProductInput {
searchResult: any
ctx: any
simulationBehavior?: 'skip' | 'default' | null
simulationBehavior?: 'skip' | 'only1P' | 'default' | null
tradePolicy?: string | null
regionId?: string | null
}
Expand Down
2 changes: 1 addition & 1 deletion node/typings/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ interface SuggestionProductsArgs {
segment?: SegmentData
indexingType?: IndexingType
productOriginVtex: boolean
simulationBehavior: 'skip' | 'default' | null
simulationBehavior: 'skip' | 'default' | 'only1P' | null
sellers?: RegionSeller[]
hideUnavailableItems?: boolean | null
regionId?: string
Expand Down
12 changes: 7 additions & 5 deletions node/utils/compatibility-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { Store } from '../clients/store'
const fillProductWithSimulation = async (
product: SearchProduct,
store: Store,
simulationBehavior: 'default' | 'only1P',
regionId?: string,
) => {
const payload = {
items: product.items.map(item => ({
itemId: item.itemId,
sellers: item.sellers.map(seller => ({
sellers: simulationBehavior === 'only1P' ? [{sellerId: "1"}] : item.sellers.map(seller => ({
sellerId: seller.sellerId,
})),
})),
Expand All @@ -28,7 +29,8 @@ const fillProductWithSimulation = async (

return mergeProductWithItems(
product,
itemsWithSimulation.data.itemsWithSimulation
itemsWithSimulation.data.itemsWithSimulation,
simulationBehavior
)
} catch(error) {
// TODO: PER-2503 - Improve error observability
Expand All @@ -40,7 +42,7 @@ const fillProductWithSimulation = async (
}
}

export const convertProducts = async (products: BiggySearchProduct[], ctx: Context, simulationBehavior: 'skip' | 'default' | null, channel?: string, regionId?: string) => {
export const convertProducts = async (products: BiggySearchProduct[], ctx: Context, simulationBehavior: 'skip' | 'default' | 'only1P' | null, channel?: string, regionId?: string) => {
const {
vtex: { segment },
clients: { store },
Expand All @@ -50,8 +52,8 @@ export const convertProducts = async (products: BiggySearchProduct[], ctx: Conte
let convertedProducts = products
.map(product => convertISProduct(product, salesChannel))

if (simulationBehavior === 'default') {
const simulationPromises = convertedProducts.map(product => fillProductWithSimulation(product as SearchProduct, store, regionId))
if (simulationBehavior === 'default' || simulationBehavior === 'only1P') {
const simulationPromises = convertedProducts.map(product => fillProductWithSimulation(product as SearchProduct, store, simulationBehavior, regionId))
convertedProducts = (await Promise.all(simulationPromises)) as SearchProduct[]
}

Expand Down

0 comments on commit ce6e50e

Please sign in to comment.