Skip to content

Commit

Permalink
[VTEX] Feat: add new types and cancel order action (#945)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriassuncx authored Oct 28, 2024
1 parent 4473723 commit c779bcc
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 16 deletions.
43 changes: 43 additions & 0 deletions vtex/actions/orders/cancel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { parseCookie } from "../../utils/vtexId.ts";
import { AppContext } from "../../mod.ts";
import { CanceledOrder } from "../../utils/types.ts";

interface Props {
orderId: string;
reason: string;
}

async function action(
props: Props,
req: Request,
ctx: AppContext,
): Promise<CanceledOrder | null> {
const { vcsDeprecated } = ctx;
const { cookie, payload } = parseCookie(req.headers, ctx.account);

if (!payload?.sub || !payload?.userId) {
return null;
}

const { orderId, reason } = props;

const response = await vcsDeprecated
["POST /api/oms/user/orders/:orderId/cancel"](
{ orderId },
{
body: { reason },
headers: {
cookie,
},
},
);

if (response.ok) {
const canceledOrder = await response.json();
return canceledOrder;
}

return null;
}

export default action;
34 changes: 18 additions & 16 deletions vtex/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ import * as $$$$$$$$$19 from "./actions/cart/updateUser.ts";
import * as $$$$$$$$$20 from "./actions/masterdata/createDocument.ts";
import * as $$$$$$$$$21 from "./actions/newsletter/subscribe.ts";
import * as $$$$$$$$$22 from "./actions/notifyme.ts";
import * as $$$$$$$$$23 from "./actions/payments/delete.ts";
import * as $$$$$$$$$24 from "./actions/profile/newsletterProfile.ts";
import * as $$$$$$$$$25 from "./actions/profile/updateProfile.ts";
import * as $$$$$$$$$26 from "./actions/review/submit.ts";
import * as $$$$$$$$$27 from "./actions/sessions/delete.ts";
import * as $$$$$$$$$28 from "./actions/trigger.ts";
import * as $$$$$$$$$29 from "./actions/wishlist/addItem.ts";
import * as $$$$$$$$$30 from "./actions/wishlist/removeItem.ts";
import * as $$$$$$$$$23 from "./actions/orders/cancel.ts";
import * as $$$$$$$$$24 from "./actions/payments/delete.ts";
import * as $$$$$$$$$25 from "./actions/profile/newsletterProfile.ts";
import * as $$$$$$$$$26 from "./actions/profile/updateProfile.ts";
import * as $$$$$$$$$27 from "./actions/review/submit.ts";
import * as $$$$$$$$$28 from "./actions/sessions/delete.ts";
import * as $$$$$$$$$29 from "./actions/trigger.ts";
import * as $$$$$$$$$30 from "./actions/wishlist/addItem.ts";
import * as $$$$$$$$$31 from "./actions/wishlist/removeItem.ts";
import * as $$$$0 from "./handlers/sitemap.ts";
import * as $$$0 from "./loaders/address/getAddressByZIP.ts";
import * as $$$1 from "./loaders/address/list.ts";
Expand Down Expand Up @@ -159,14 +160,15 @@ const manifest = {
"vtex/actions/masterdata/createDocument.ts": $$$$$$$$$20,
"vtex/actions/newsletter/subscribe.ts": $$$$$$$$$21,
"vtex/actions/notifyme.ts": $$$$$$$$$22,
"vtex/actions/payments/delete.ts": $$$$$$$$$23,
"vtex/actions/profile/newsletterProfile.ts": $$$$$$$$$24,
"vtex/actions/profile/updateProfile.ts": $$$$$$$$$25,
"vtex/actions/review/submit.ts": $$$$$$$$$26,
"vtex/actions/sessions/delete.ts": $$$$$$$$$27,
"vtex/actions/trigger.ts": $$$$$$$$$28,
"vtex/actions/wishlist/addItem.ts": $$$$$$$$$29,
"vtex/actions/wishlist/removeItem.ts": $$$$$$$$$30,
"vtex/actions/orders/cancel.ts": $$$$$$$$$23,
"vtex/actions/payments/delete.ts": $$$$$$$$$24,
"vtex/actions/profile/newsletterProfile.ts": $$$$$$$$$25,
"vtex/actions/profile/updateProfile.ts": $$$$$$$$$26,
"vtex/actions/review/submit.ts": $$$$$$$$$27,
"vtex/actions/sessions/delete.ts": $$$$$$$$$28,
"vtex/actions/trigger.ts": $$$$$$$$$29,
"vtex/actions/wishlist/addItem.ts": $$$$$$$$$30,
"vtex/actions/wishlist/removeItem.ts": $$$$$$$$$31,
},
"workflows": {
"vtex/workflows/events.ts": $$$$$$$$$$0,
Expand Down
7 changes: 7 additions & 0 deletions vtex/utils/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Userorderslist } from "./openapi/vcs.openapi.gen.ts";
import {
Brand,
CanceledOrder,
Category,
CreateNewDocument,
FacetSearchResult,
Expand Down Expand Up @@ -252,6 +253,12 @@ export interface VTEXCommerceStable {
"GET /api/oms/user/orders/:orderId": {
response: OrderItem;
};
"POST /api/oms/user/orders/:orderId/cancel": {
response: CanceledOrder;
body: {
reason: string;
};
};
}

export interface SP {
Expand Down
27 changes: 27 additions & 0 deletions vtex/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,24 @@ export interface Order {
workflowInRetry: boolean;
}

export interface Package {
cfop: string | null;
invoiceNumber: string;
invoiceValue: number;
invoiceUrl: string | null;
issuanceDate: string;
trackingNumber: string | null;
invoiceKey: string;
trackingUrl: string | null;
embeddedInvoice: string;
courierStatus: {
status: string | null;
finished: boolean;
deliveredDate: string;
};
type: "Input" | "Output";
}

export interface OrderItem {
orderId: string;
sequence: string;
Expand All @@ -1377,6 +1395,9 @@ export interface OrderItem {
authorizedDate: string;
callCenterOperatorData: string;
cancelReason: string;
packageAttachment: {
packages: Package[];
} | null;
cancellationData: {
RequestedByUser: boolean;
RequestedBySystem: boolean;
Expand Down Expand Up @@ -1431,6 +1452,12 @@ export interface OrderItem {
openTextField: string | null;
}

export interface CanceledOrder {
date: string;
orderId: string;
receipt: string | null;
}

interface Marketplace {
baseURL: string;
// deno-lint-ignore no-explicit-any
Expand Down

0 comments on commit c779bcc

Please sign in to comment.