diff --git a/src/config/mikro-orm.config.dev.ts b/src/config/mikro-orm.config.dev.ts index 9e7439e..fec939c 100644 --- a/src/config/mikro-orm.config.dev.ts +++ b/src/config/mikro-orm.config.dev.ts @@ -25,7 +25,7 @@ export default defineConfig({ entitiesTs: ['src/**/*.entity.ts'], driver: PostgreSqlDriver, dbName: DB_NAME, - debug: !isProduction, + debug: false, clientUrl: `postgres://${DB_USER}:${encodedPassword}@${DB_HOST}:${DB_PORT}`, ensureDatabase: isProduction ? false diff --git a/src/config/mikro-orm.config.ts b/src/config/mikro-orm.config.ts index d337d0c..3b32bca 100644 --- a/src/config/mikro-orm.config.ts +++ b/src/config/mikro-orm.config.ts @@ -35,7 +35,7 @@ const dataBaseConfig: MikroOrmModuleAsyncOptions = { driver: PostgreSqlDriver, autoLoadEntities: true, dbName: DB_NAME, - debug: !isProduction, + debug: false, clientUrl: `postgres://${DB_USER}:${encodedPassword}@${DB_HOST}:${DB_PORT}`, ensureDatabase: isProduction ? false diff --git a/src/modules/notifications/listeners/notification.listeners.ts b/src/modules/notifications/listeners/notification.listeners.ts index eb3b63f..41e505b 100644 --- a/src/modules/notifications/listeners/notification.listeners.ts +++ b/src/modules/notifications/listeners/notification.listeners.ts @@ -15,11 +15,11 @@ export class NotificationListeners { constructor(private readonly notificationService: NotificationService) {} - @OnEvent('order.created') + @OnEvent(OrderCreatedEvent.name) async handleOrderCreated(event: OrderCreatedEvent) { try { this.logger.log(`Order created event received: ${event.orderNumber}`); - + console.log('Order created event received: ', event); await this.notificationService.sendNotification({ restaurantId: event.restaurantId, userId: event.userId, @@ -33,7 +33,7 @@ export class NotificationListeners { ); } } - @OnEvent('order.payment.success') + @OnEvent(OrderPaymentSuccessEvent.name) async handleOrderPaymentSuccess(event: OrderPaymentSuccessEvent) { try { this.logger.log(`Order payment success event received: ${event.orderNumber}`); @@ -52,7 +52,7 @@ export class NotificationListeners { } } - @OnEvent('review.created') + @OnEvent(ReviewCreatedEvent.name) async handleReviewCreated(event: ReviewCreatedEvent) { try { this.logger.log(`Review created event received: ${event.reviewId}`); @@ -71,7 +71,7 @@ export class NotificationListeners { } } - @OnEvent('order.status.changed') + @OnEvent(OrderStatusChangedEvent.name) async handleOrderStatusChanged(event: OrderStatusChangedEvent) { try { this.logger.log(`Order status changed: ${event.orderId} from ${event.oldStatus} to ${event.newStatus}`); diff --git a/src/modules/orders/orders.service.ts b/src/modules/orders/orders.service.ts index 7118cc5..90cff71 100644 --- a/src/modules/orders/orders.service.ts +++ b/src/modules/orders/orders.service.ts @@ -19,6 +19,8 @@ import { Cron, CronExpression } from '@nestjs/schedule'; import { OrderRepository } from './repositories/order.repository'; import { FindOrdersDto } from './dto/find-orders.dto'; import { PaginatedResult } from 'src/common/interfaces/pagination.interface'; +import { EventEmitter2 } from '@nestjs/event-emitter'; +import { OrderCreatedEvent, OrderPaymentSuccessEvent } from '../notifications/events/notification.events'; @Injectable() export class OrdersService { @@ -29,10 +31,12 @@ export class OrdersService { private readonly cartService: CartService, private readonly paymentsService: PaymentsService, private readonly orderRepository: OrderRepository, + private readonly eventEmitter2: EventEmitter2, // private readonly paymentGatewayService: PaymentGatewayService, ) {} async checkout(userId: string, restaurantId: string) { + console.log('Order created event emitted 000'); const cart = await this.cartService.findOneOrFail(userId, restaurantId); const { order } = await this.createOrder(userId, restaurantId, cart); @@ -45,6 +49,15 @@ export class OrdersService { await this.cartService.clearCart(userId, restaurantId); + this.eventEmitter2.emit( + OrderCreatedEvent.name, + new OrderCreatedEvent(order.id, restaurantId, order.user.id, order.total), + ); + this.eventEmitter2.emit( + OrderPaymentSuccessEvent.name, + new OrderPaymentSuccessEvent(order.id, restaurantId, order.user.id, order.total), + ); + console.log('Order created event emitted 111'); return { order, paymentUrl }; }