notification fix bug
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}`);
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user