I am getting this error
for this subscriber file
import { OrderService, SubscriberArgs, SubscriberConfig } from "@medusajs/medusa";
import WalletService from "../services/wallet";
import TransactionHistoryService from "../services/transaction_history";
import CartService from "../services/cart";
type OrderPlacedEvent = {
id: string;
no_notification: boolean;
}
export default async function orderPlacedHandler({ data, eventName, container }: SubscriberArgs<OrderPlacedEvent>) {
const orderService: OrderService = container.resolve("orderService");
const cartService: CartService = container.resolve("cartService");
const walletService: WalletService = container.resolve("walletService");
const transactionHistoryService: TransactionHistoryService = container.resolve("transactionHistoryService");
const orderRepository = container.resolve("orderRepository")
const orderId = data.id;
const order = await orderService.retrieve(orderId, {
relations: ["customer", "cart", "payments"]});
const customerId = order.customer_id;
const wallet = await walletService.findWalletByCustomerId(customerId);
const walletId = wallet.id;
const cart = await cartService.retrieve(order.cart_id);
order.wallet_amt_used = cart.wallet_amt_used;
order.is_wallet_amt_used = cart.is_wallet_amt_used;
await orderRepository.save(order);
const walletAmountUsed = order.wallet_amt_used;
if (walletAmountUsed <= 0) {
return;
}
if (wallet.balance > 0) {
try {
await transactionHistoryService.deduct(orderId, walletId, walletAmountUsed);}
catch (error) {
console.error("Error deducting wallet amount", error);
}
} else {
console.error("Insufficient wallet balance");
}
}
export const config: SubscriberConfig = {
event: OrderService.Events.PLACED
}
please help!
#One or more subscribers of order.placed failed.
4 messages · Page 1 of 1 (latest)
Did you solve this?
yes
I am totally new to this please help. I want to make a subscriber that triggers on product created and sends a post request to another url with the same data.