Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
diboune committed Oct 18, 2024
1 parent f5c3fbf commit 3ca7f67
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 43 deletions.
32 changes: 12 additions & 20 deletions backend/src/subscribers/order-created.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
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,
Expand All @@ -18,30 +15,25 @@ export default async function orderCreateHandler({
body: JSON.stringify(event.data),
},
);

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

console.log("Event data posted successfully");
} 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 }),
});
// 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 }),
// });
}

export const config: SubscriberConfig = {
Expand Down
46 changes: 23 additions & 23 deletions backend/src/subscribers/order-updated.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { Modules } from "@medusajs/framework/utils";
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/medusa";
import ShippingConfirmation from "data/templates/shipping-confirmation";
import { sendEmail } from "./lib/email";
// import { Modules } from "@medusajs/framework/utils";
// import type { SubscriberArgs, SubscriberConfig } from "@medusajs/medusa";
// import ShippingConfirmation from "data/templates/shipping-confirmation";
// import { sendEmail } from "./lib/email";

export default async function orderUpdatedHandler({
event,
container,
}: SubscriberArgs<{ id: string }>) {
const orderService = container.resolve(Modules.ORDER);
// export default async function orderUpdatedHandler({
// event,
// container,
// }: SubscriberArgs<{ id: string }>) {
// const orderService = container.resolve(Modules.ORDER);

const order = await orderService
.listOrders({
id: event.data.id,
})
.then((orders) => orders[0]);
// const order = await orderService
// .listOrders({
// id: event.data.id,
// })
// .then((orders) => orders[0]);

await sendEmail({
to: order.email,
subject: "Your order is shipped",
react: ShippingConfirmation(),
});
}
// await sendEmail({
// to: order.email,
// subject: "Your order is shipped",
// react: ShippingConfirmation(),
// });
// }

export const config: SubscriberConfig = {
event: ["order.updated"],
};
// export const config: SubscriberConfig = {
// event: ["order.updated"],
// };

0 comments on commit 3ca7f67

Please sign in to comment.