From 9ce8beac2dce6ee7cb171c67e70fc9d9ee7438d4 Mon Sep 17 00:00:00 2001 From: soutofernando Date: Thu, 3 Oct 2024 17:38:09 -0300 Subject: [PATCH] deno check --- vtex/actions/address/updateAddress.ts | 158 +++++++++++++------------- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/vtex/actions/address/updateAddress.ts b/vtex/actions/address/updateAddress.ts index 15ff73d0f..27135c375 100644 --- a/vtex/actions/address/updateAddress.ts +++ b/vtex/actions/address/updateAddress.ts @@ -3,65 +3,65 @@ import { AppContext } from "../../mod.ts"; import { parseCookie } from "../../utils/vtexId.ts"; interface Address { - name?: string; - addressName?: string; - addressType?: string; - city?: string; - complement?: string; - country?: string; - geoCoordinates?: number[]; - neighborhood?: string; - number?: string; - postalCode?: string; - receiverName?: string; - reference?: string; - state?: string; - street?: string; + name?: string; + addressName?: string; + addressType?: string; + city?: string; + complement?: string; + country?: string; + geoCoordinates?: number[]; + neighborhood?: string; + number?: string; + postalCode?: string; + receiverName?: string; + reference?: string; + state?: string; + street?: string; } interface AddressInput { - addressId?: string; - name?: string; - addressName?: string; - addressType?: string; - city?: string; - complement?: string; - country?: string; - geoCoordinates?: number[]; - neighborhood?: string; - number?: string; - postalCode?: string; - receiverName?: string; - reference?: string; - state?: string; - street?: string; + addressId?: string; + name?: string; + addressName?: string; + addressType?: string; + city?: string; + complement?: string; + country?: string; + geoCoordinates?: number[]; + neighborhood?: string; + number?: string; + postalCode?: string; + receiverName?: string; + reference?: string; + state?: string; + street?: string; } async function loader( - _props: unknown, - req: Request, - ctx: AppContext, + _props: unknown, + req: Request, + ctx: AppContext, ): Promise { - const { io } = ctx; - const { cookie } = parseCookie(req.headers, ctx.account); + const { io } = ctx; + const { cookie } = parseCookie(req.headers, ctx.account); - const moc: AddressInput = { - addressType: "Residential", - addressName: "Home Address", - city: "Los Angeles", - complement: "Apt 4B", - country: "USA", - neighborhood: "Downtown", - number: "1234", - postalCode: "90001", - geoCoordinates: [-111.98, 40.74], - receiverName: "John Maria", - reference: "Near the central park", - state: "UTA", - street: "Main St", - }; + const moc: AddressInput = { + addressType: "Residential", + addressName: "Home Address", + city: "Los Angeles", + complement: "Apt 4B", + country: "USA", + neighborhood: "Downtown", + number: "1234", + postalCode: "90001", + geoCoordinates: [-111.98, 40.74], + receiverName: "John Maria", + reference: "Near the central park", + state: "UTA", + street: "Main St", + }; - const mutation = ` + const mutation = ` mutation UpdateAddress($addressId: String, $addressFields: AddressInput) { updateAddress(id: $addressId, fields: $addressFields) @context(provider: "vtex.store-graphql") { @@ -85,36 +85,36 @@ async function loader( } }`; - try { - const { updateAddress: updatedAddress } = await io.query< - { updateAddress: Address }, - { addressId: string; addressFields: AddressInput } - >( - { - query: mutation, - operationName: "UpdateAddress", - variables: { - addressId: "9y11rmhpsq", - addressFields: { - ...moc, - }, - }, - }, - { headers: { cookie } }, - ); + try { + const { updateAddress: updatedAddress } = await io.query< + { updateAddress: Address }, + { addressId: string; addressFields: AddressInput } + >( + { + query: mutation, + operationName: "UpdateAddress", + variables: { + addressId: "9y11rmhpsq", + addressFields: { + ...moc, + }, + }, + }, + { headers: { cookie } }, + ); - return { - "@type": "PostalAddress", - addressCountry: updatedAddress?.country, - addressLocality: updatedAddress?.city, - addressRegion: updatedAddress?.state, - postalCode: updatedAddress?.postalCode, - streetAddress: updatedAddress?.street, - }; - } catch (error) { - console.error("Error updating address:", error); - return null; - } + return { + "@type": "PostalAddress", + addressCountry: updatedAddress?.country, + addressLocality: updatedAddress?.city, + addressRegion: updatedAddress?.state, + postalCode: updatedAddress?.postalCode, + streetAddress: updatedAddress?.street, + }; + } catch (error) { + console.error("Error updating address:", error); + return null; + } } export default loader;