order user optional
deploy to danak / build_and_deploy (push) Has been cancelled

This commit is contained in:
2026-07-01 08:53:53 +03:30
parent f6d1716ad0
commit 5d0e862259
3 changed files with 9 additions and 3 deletions
+2 -2
View File
@@ -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;
}