From 16f61abf1d6bb33f33a902d3f2dfeaf363944989 Mon Sep 17 00:00:00 2001 From: Ezequias Calvo Date: Thu, 25 Aug 2022 09:45:53 +0200 Subject: [PATCH 1/2] feat: dont rely on sellerName when creating a request --- graphql/types/ReturnRequest.graphql | 2 +- masterdata/returnRequest/schema.json | 2 +- node/package.json | 2 +- node/resolvers/ReturnRequestResponse.ts | 25 ++++++++++++++------- node/services/createReturnRequestService.ts | 2 -- node/utils/createItemsToReturn.ts | 12 +--------- node/yarn.lock | 4 ++-- react/package.json | 2 +- react/yarn.lock | 4 ++-- 9 files changed, 26 insertions(+), 29 deletions(-) diff --git a/graphql/types/ReturnRequest.graphql b/graphql/types/ReturnRequest.graphql index 7ae4911d0..d4a609ebc 100644 --- a/graphql/types/ReturnRequest.graphql +++ b/graphql/types/ReturnRequest.graphql @@ -136,7 +136,7 @@ type ReturnRequestItem { imageUrl: String! unitMultiplier: Float! sellerId: String! - sellerName: String! + sellerName: String productId: String! refId: String! } diff --git a/masterdata/returnRequest/schema.json b/masterdata/returnRequest/schema.json index 1b3a06b2b..498293262 100644 --- a/masterdata/returnRequest/schema.json +++ b/masterdata/returnRequest/schema.json @@ -116,7 +116,7 @@ "imageUrl": { "type": "string" }, "unitMultiplier": { "type": "number" }, "sellerId": { "type": "string" }, - "sellerName": { "type": "string" }, + "sellerName": { "type": ["string", "null"] }, "productId": { "type": "string" }, "refId": { "type": "string" }, "returnReason": { diff --git a/node/package.json b/node/package.json index c82a96262..fa6f51fb7 100644 --- a/node/package.json +++ b/node/package.json @@ -23,7 +23,7 @@ "vtex.my-account": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.my-account@1.25.0/public/@types/vtex.my-account", "vtex.my-account-commons": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.my-account-commons@1.6.0/public/@types/vtex.my-account-commons", "vtex.render-runtime": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.132.4/public/@types/vtex.render-runtime", - "vtex.return-app": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.return-app@3.4.1/public/@types/vtex.return-app", + "vtex.return-app": "https://seller--vtexspain.myvtex.com/_v/private/typings/linked/v1/vtex.return-app@3.4.1+build1661412341/public/@types/vtex.return-app", "vtex.store-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.155.32/public/@types/vtex.store-graphql", "vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.146.1/public/@types/vtex.styleguide", "vtex.tenant-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.tenant-graphql@0.1.2/public/@types/vtex.tenant-graphql" diff --git a/node/resolvers/ReturnRequestResponse.ts b/node/resolvers/ReturnRequestResponse.ts index c3a3de160..dd0266d2f 100644 --- a/node/resolvers/ReturnRequestResponse.ts +++ b/node/resolvers/ReturnRequestResponse.ts @@ -131,19 +131,28 @@ export const ReturnRequestResponse = { return refundData }, items: async (root: ReturnRequest, _args: unknown, ctx: Context) => { - const { id, items } = root - - if (items) return items + const { id } = root const { - clients: { returnRequest: returnRequestClient }, + clients: { returnRequest: returnRequestClient, oms }, } = ctx - const { items: itemsList } = await returnRequestClient.get(id as string, [ - 'items', - ]) + const { orderId, items: itemsList } = await returnRequestClient.get( + id as string, + ['orderId', 'items'] + ) + + const { sellers } = await oms.order(orderId, 'AUTH_TOKEN') + + const itemsWithSellerName = itemsList.map((item) => { + const sellerName = + sellers.find((sellerInfo) => sellerInfo.id === item.sellerId)?.name ?? + '' + + return { ...item, sellerName } + }) - return itemsList + return itemsWithSellerName }, refundData: async (root: ReturnRequest, _args: unknown, ctx: Context) => { const { id, refundData } = root diff --git a/node/services/createReturnRequestService.ts b/node/services/createReturnRequestService.ts index 55c30b8ab..cd64d75d2 100644 --- a/node/services/createReturnRequestService.ts +++ b/node/services/createReturnRequestService.ts @@ -111,7 +111,6 @@ export const createReturnRequestService = async ( totals, creationDate, status, - sellers, // @ts-expect-error itemMetadata is not typed in the OMS client project itemMetadata, shippingData, @@ -168,7 +167,6 @@ export const createReturnRequestService = async ( const itemsToReturn = await createItemsToReturn({ itemsToReturn: items, orderItems, - sellers, itemMetadata, catalogGQL, }) diff --git a/node/utils/createItemsToReturn.ts b/node/utils/createItemsToReturn.ts index 1dc7374a1..6f2350fe2 100644 --- a/node/utils/createItemsToReturn.ts +++ b/node/utils/createItemsToReturn.ts @@ -1,9 +1,5 @@ import { UserInputError } from '@vtex/api' -import type { - OrderItemDetailResponse, - PriceTag, - SellerDetail, -} from '@vtex/clients' +import type { OrderItemDetailResponse, PriceTag } from '@vtex/clients' import type { ReturnRequestItemInput, ReturnRequestItem } from 'vtex.return-app' import type { CatalogGQL } from '../clients/catalogGQL' @@ -50,13 +46,11 @@ const calculateItemTax = ({ export const createItemsToReturn = async ({ itemsToReturn, orderItems, - sellers, itemMetadata, catalogGQL, }: { itemsToReturn: ReturnRequestItemInput[] orderItems: OrderItemDetailResponse[] - sellers: SellerDetail[] itemMetadata: ItemMetadata catalogGQL: CatalogGQL }): Promise => { @@ -84,9 +78,6 @@ export const createItemsToReturn = async ({ productId, } = orderItem - const sellerName = - sellers.find((sellerInfo) => sellerInfo.id === seller)?.name ?? '' - const productImage = imageUrl ?? itemMetadata.Items.find((itemMeta) => itemMeta.Id === id)?.ImageUrl ?? @@ -104,7 +95,6 @@ export const createItemsToReturn = async ({ sellerId: seller, refId, productId, - sellerName, condition: item.condition ? item.condition : 'unspecified', } }) diff --git a/node/yarn.lock b/node/yarn.lock index 31ca05f60..bdda7bf51 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -6155,9 +6155,9 @@ verror@1.10.0: version "8.132.4" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.132.4/public/@types/vtex.render-runtime#66bb41bd4d342e37c9d85172aad5f7eefebfb6dc" -"vtex.return-app@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.return-app@3.4.1/public/@types/vtex.return-app": +"vtex.return-app@https://seller--vtexspain.myvtex.com/_v/private/typings/linked/v1/vtex.return-app@3.4.1+build1661412341/public/@types/vtex.return-app": version "3.4.1" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.return-app@3.4.1/public/@types/vtex.return-app#3ec50e68b1da9e99870e468775be93af77497e3e" + resolved "https://seller--vtexspain.myvtex.com/_v/private/typings/linked/v1/vtex.return-app@3.4.1+build1661412341/public/@types/vtex.return-app#da05ddd171ea3683f1679ff5195236f4d12ca4c2" "vtex.store-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.155.32/public/@types/vtex.store-graphql": version "2.155.32" diff --git a/react/package.json b/react/package.json index 8d061cc0f..75c8bc77b 100644 --- a/react/package.json +++ b/react/package.json @@ -33,7 +33,7 @@ "vtex.my-account": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.my-account@1.25.0/public/@types/vtex.my-account", "vtex.my-account-commons": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.my-account-commons@1.6.0/public/@types/vtex.my-account-commons", "vtex.render-runtime": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.132.4/public/@types/vtex.render-runtime", - "vtex.return-app": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.return-app@3.4.1/public/@types/vtex.return-app", + "vtex.return-app": "https://seller--vtexspain.myvtex.com/_v/private/typings/linked/v1/vtex.return-app@3.4.1+build1661412341/public/@types/vtex.return-app", "vtex.store-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.155.32/public/@types/vtex.store-graphql", "vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.146.1/public/@types/vtex.styleguide", "vtex.tenant-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.tenant-graphql@0.1.2/public/@types/vtex.tenant-graphql" diff --git a/react/yarn.lock b/react/yarn.lock index 8ed5bcb93..55ba4c8bf 100644 --- a/react/yarn.lock +++ b/react/yarn.lock @@ -5206,9 +5206,9 @@ verror@1.10.0: version "8.132.4" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.132.4/public/@types/vtex.render-runtime#66bb41bd4d342e37c9d85172aad5f7eefebfb6dc" -"vtex.return-app@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.return-app@3.4.1/public/@types/vtex.return-app": +"vtex.return-app@https://seller--vtexspain.myvtex.com/_v/private/typings/linked/v1/vtex.return-app@3.4.1+build1661412341/public/@types/vtex.return-app": version "3.4.1" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.return-app@3.4.1/public/@types/vtex.return-app#3ec50e68b1da9e99870e468775be93af77497e3e" + resolved "https://seller--vtexspain.myvtex.com/_v/private/typings/linked/v1/vtex.return-app@3.4.1+build1661412341/public/@types/vtex.return-app#da05ddd171ea3683f1679ff5195236f4d12ca4c2" "vtex.store-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.155.32/public/@types/vtex.store-graphql": version "2.155.32" From a4a2ff7d1525da09bce5fa3c1466ca401f01816d Mon Sep 17 00:00:00 2001 From: Ezequias Calvo Date: Thu, 25 Aug 2022 09:52:42 +0200 Subject: [PATCH 2/2] docs: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57ea72d65..308a94f55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Add IBAN validation in frontend and backend - Remove IBAN and accountHolderNumber if refund method different than bank +- Stop relying on saving the sellerName at the creation of a return request. Instead get the seller name when resolving the objects that serve it to the front end. ## [3.4.1] - 2022-08-18