Skip to content

Commit

Permalink
deno check
Browse files Browse the repository at this point in the history
  • Loading branch information
soutofernando committed Oct 3, 2024
1 parent 50c24fc commit 9ce8bea
Showing 1 changed file with 79 additions and 79 deletions.
158 changes: 79 additions & 79 deletions vtex/actions/address/updateAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PostalAddress | null> {
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") {
Expand All @@ -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;

0 comments on commit 9ce8bea

Please sign in to comment.