-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[VTEX] Feat: add new types and cancel order action (#945)
- Loading branch information
1 parent
4473723
commit c779bcc
Showing
4 changed files
with
95 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters