Skip to content

Commit

Permalink
chore: fixes typing error pointing by linter
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoferreiradev committed Oct 14, 2024
1 parent d9c45c6 commit 4d783d1
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 66 deletions.
132 changes: 66 additions & 66 deletions vtex/actions/address/createAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,89 +3,89 @@ 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 {
receiverName?: string;
complement?: string | null;
neighborhood?: string | null;
country?: string;
state?: string;
number?: string | null;
street?: string;
geoCoordinates?: number[];
postalCode?: string;
city?: string;
reference?: string | null;
addressName: string;
addressType?: string;
receiverName?: string;
complement?: string | null;
neighborhood?: string | null;
country?: string;
state?: string;
number?: string | null;
street?: string;
geoCoordinates?: number[];
postalCode?: string;
city?: string;
reference?: string | null;
addressName: string;
addressType?: string;
}

async function loader(
props: Address,
req: Request,
ctx: AppContext,
props: Address,
req: Request,
ctx: AppContext,
): Promise<
| PostalAddress & {
receiverName?: string | null;
complement?: string | null;
}
| null
| PostalAddress & {
receiverName?: string | null;
complement?: string | null;
}
| null
> {
const { io } = ctx;
const { cookie } = parseCookie(req.headers, ctx.account);
const { io } = ctx;
const { cookie } = parseCookie(req.headers, ctx.account);

const mutation = `
const mutation = `
mutation SaveAddress($address: AddressInput!) {
saveAddress(address: $address) @context(provider: "vtex.store-graphql") {
id
cacheId
}
}`;

try {
const { saveAddress: updatedAddress } = await io.query<
{ saveAddress: Address },
{ address: AddressInput }
>(
{
query: mutation,
operationName: "SaveAddress",
variables: {
address: props,
},
},
{ headers: { cookie } },
);
try {
const { saveAddress: updatedAddress } = await io.query<
{ saveAddress: Address },
{ address: AddressInput }
>(
{
query: mutation,
operationName: "SaveAddress",
variables: {
address: props,
},
},
{ headers: { cookie } },
);

return {
"@type": "PostalAddress",
addressCountry: updatedAddress?.country,
addressLocality: updatedAddress?.city,
addressRegion: updatedAddress?.state,
postalCode: updatedAddress?.postalCode,
streetAddress: updatedAddress?.street,
receiverName: updatedAddress?.receiverName,
complement: updatedAddress?.complement,
};
} catch (error) {
console.error("Error saving address:", error);
return null;
}
return {
"@type": "PostalAddress",
addressCountry: updatedAddress?.country,
addressLocality: updatedAddress?.city,
addressRegion: updatedAddress?.state,
postalCode: updatedAddress?.postalCode,
streetAddress: updatedAddress?.street,
receiverName: updatedAddress?.receiverName,
complement: updatedAddress?.complement,
};
} catch (error) {
console.error("Error saving address:", error);
return null;
}
}

export default loader;
1 change: 1 addition & 0 deletions vtex/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ export interface ShippingData {

export interface Address {
addressType: string;
addressName: string;
receiverName: null;
addressId: string;
isDisposable: boolean;
Expand Down

0 comments on commit 4d783d1

Please sign in to comment.