This commit is contained in:
@@ -26,8 +26,8 @@ import { Payment } from 'src/modules/payments/entities/payment.entity';
|
||||
@Index({ properties: ['restaurant', 'status'] })
|
||||
@Index({ properties: ['restaurant', 'orderNumber'] })
|
||||
export class Order extends BaseEntity {
|
||||
@ManyToOne(() => User)
|
||||
user!: User;
|
||||
@ManyToOne(() => User, { nullable: true })
|
||||
user?: User | null;
|
||||
|
||||
@ManyToOne(() => Restaurant)
|
||||
restaurant!: Restaurant;
|
||||
|
||||
@@ -133,6 +133,12 @@ export class PaymentListeners {
|
||||
);
|
||||
return;
|
||||
}
|
||||
if(!order.user){
|
||||
this.logger.error(
|
||||
`User not found: ${event.orderId} for restaurant: ${event.restaurantId}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
const userRecipients = [
|
||||
{
|
||||
userId: order.user.id,
|
||||
|
||||
@@ -111,7 +111,7 @@ export class PaymentsService {
|
||||
await this.em.transactional(async em => {
|
||||
const order = await em.findOne(Order, { id: ctx.order.id }, { populate: ['user', 'restaurant'] });
|
||||
if (!order) throw new NotFoundException(OrderMessage.NOT_FOUND);
|
||||
|
||||
if (!order.user) throw new NotFoundException(OrderMessage.USER_NOT_FOUND);
|
||||
if (order.status === OrderStatus.PAID) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user