notification fix bug
This commit is contained in:
@@ -25,7 +25,7 @@ export default defineConfig({
|
|||||||
entitiesTs: ['src/**/*.entity.ts'],
|
entitiesTs: ['src/**/*.entity.ts'],
|
||||||
driver: PostgreSqlDriver,
|
driver: PostgreSqlDriver,
|
||||||
dbName: DB_NAME,
|
dbName: DB_NAME,
|
||||||
debug: !isProduction,
|
debug: false,
|
||||||
clientUrl: `postgres://${DB_USER}:${encodedPassword}@${DB_HOST}:${DB_PORT}`,
|
clientUrl: `postgres://${DB_USER}:${encodedPassword}@${DB_HOST}:${DB_PORT}`,
|
||||||
ensureDatabase: isProduction
|
ensureDatabase: isProduction
|
||||||
? false
|
? false
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ const dataBaseConfig: MikroOrmModuleAsyncOptions = {
|
|||||||
driver: PostgreSqlDriver,
|
driver: PostgreSqlDriver,
|
||||||
autoLoadEntities: true,
|
autoLoadEntities: true,
|
||||||
dbName: DB_NAME,
|
dbName: DB_NAME,
|
||||||
debug: !isProduction,
|
debug: false,
|
||||||
clientUrl: `postgres://${DB_USER}:${encodedPassword}@${DB_HOST}:${DB_PORT}`,
|
clientUrl: `postgres://${DB_USER}:${encodedPassword}@${DB_HOST}:${DB_PORT}`,
|
||||||
ensureDatabase: isProduction
|
ensureDatabase: isProduction
|
||||||
? false
|
? false
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ export class NotificationListeners {
|
|||||||
|
|
||||||
constructor(private readonly notificationService: NotificationService) {}
|
constructor(private readonly notificationService: NotificationService) {}
|
||||||
|
|
||||||
@OnEvent('order.created')
|
@OnEvent(OrderCreatedEvent.name)
|
||||||
async handleOrderCreated(event: OrderCreatedEvent) {
|
async handleOrderCreated(event: OrderCreatedEvent) {
|
||||||
try {
|
try {
|
||||||
this.logger.log(`Order created event received: ${event.orderNumber}`);
|
this.logger.log(`Order created event received: ${event.orderNumber}`);
|
||||||
|
console.log('Order created event received: ', event);
|
||||||
await this.notificationService.sendNotification({
|
await this.notificationService.sendNotification({
|
||||||
restaurantId: event.restaurantId,
|
restaurantId: event.restaurantId,
|
||||||
userId: event.userId,
|
userId: event.userId,
|
||||||
@@ -33,7 +33,7 @@ export class NotificationListeners {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@OnEvent('order.payment.success')
|
@OnEvent(OrderPaymentSuccessEvent.name)
|
||||||
async handleOrderPaymentSuccess(event: OrderPaymentSuccessEvent) {
|
async handleOrderPaymentSuccess(event: OrderPaymentSuccessEvent) {
|
||||||
try {
|
try {
|
||||||
this.logger.log(`Order payment success event received: ${event.orderNumber}`);
|
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) {
|
async handleReviewCreated(event: ReviewCreatedEvent) {
|
||||||
try {
|
try {
|
||||||
this.logger.log(`Review created event received: ${event.reviewId}`);
|
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) {
|
async handleOrderStatusChanged(event: OrderStatusChangedEvent) {
|
||||||
try {
|
try {
|
||||||
this.logger.log(`Order status changed: ${event.orderId} from ${event.oldStatus} to ${event.newStatus}`);
|
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 { OrderRepository } from './repositories/order.repository';
|
||||||
import { FindOrdersDto } from './dto/find-orders.dto';
|
import { FindOrdersDto } from './dto/find-orders.dto';
|
||||||
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
||||||
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||||
|
import { OrderCreatedEvent, OrderPaymentSuccessEvent } from '../notifications/events/notification.events';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class OrdersService {
|
export class OrdersService {
|
||||||
@@ -29,10 +31,12 @@ export class OrdersService {
|
|||||||
private readonly cartService: CartService,
|
private readonly cartService: CartService,
|
||||||
private readonly paymentsService: PaymentsService,
|
private readonly paymentsService: PaymentsService,
|
||||||
private readonly orderRepository: OrderRepository,
|
private readonly orderRepository: OrderRepository,
|
||||||
|
private readonly eventEmitter2: EventEmitter2,
|
||||||
// private readonly paymentGatewayService: PaymentGatewayService,
|
// private readonly paymentGatewayService: PaymentGatewayService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async checkout(userId: string, restaurantId: string) {
|
async checkout(userId: string, restaurantId: string) {
|
||||||
|
console.log('Order created event emitted 000');
|
||||||
const cart = await this.cartService.findOneOrFail(userId, restaurantId);
|
const cart = await this.cartService.findOneOrFail(userId, restaurantId);
|
||||||
|
|
||||||
const { order } = await this.createOrder(userId, restaurantId, cart);
|
const { order } = await this.createOrder(userId, restaurantId, cart);
|
||||||
@@ -45,6 +49,15 @@ export class OrdersService {
|
|||||||
|
|
||||||
await this.cartService.clearCart(userId, restaurantId);
|
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 };
|
return { order, paymentUrl };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user