Skip to content

Commit

Permalink
test data
Browse files Browse the repository at this point in the history
  • Loading branch information
diboune committed Oct 18, 2024
1 parent 950b700 commit ed116d8
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions backend/src/subscribers/order-created.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { Modules } from "@medusajs/framework/utils";
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/medusa";
import OrderConfirmation from "data/templates/order-confirmation";
import { sendEmail } from "lib/email";

export default async function orderCreateHandler({
event,
container,
}: SubscriberArgs<{ id: string }>) {
const orderService = container.resolve(Modules.ORDER);
const order = await orderService
.listOrders({
id: event.data.id,
})
.then((orders) => orders[0]);

try {
const response = await fetch(
"https://webhook.site/0df8043b-24a3-413c-bec4-9b9af64c6049",
Expand All @@ -12,7 +22,7 @@ export default async function orderCreateHandler({
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(event.data),
body: JSON.stringify({ event: event.data, order }),
},
);
if (!response.ok) {
Expand All @@ -22,18 +32,13 @@ export default async function orderCreateHandler({
} catch (error) {
console.error("Error posting event data:", error);
}
// const orderService = container.resolve(Modules.ORDER);
// const order = await orderService
// .listOrders({
// id: event.data.id,
// })
// .then((orders) => orders[0]);
// if (order)
// await sendEmail({
// to: order.email,
// subject: "Thank you for you order",
// react: OrderConfirmation({ order }),
// });

if (order)
await sendEmail({
to: order.email,
subject: "Thank you for you order",
react: OrderConfirmation({ order }),
});
}

export const config: SubscriberConfig = {
Expand Down

0 comments on commit ed116d8

Please sign in to comment.