import { Injectable, NotFoundException } from '@nestjs/common'; import { EntityManager, EntityRepository } from '@mikro-orm/postgresql'; import { RestaurantPaymentMethod } from '../entities/restaurant-payment-method.entity'; @Injectable() export class RestaurantPaymentMethodRepository extends EntityRepository { constructor(readonly em: EntityManager) { super(em, RestaurantPaymentMethod); } async findOneWithPopulate(id: string): Promise { const restaurantPaymentMethod = await this.findOne({ id }, { populate: ['restaurant', 'paymentMethod'] }); if (!restaurantPaymentMethod) { throw new NotFoundException('Restaurant payment method not found'); } await restaurantPaymentMethod.restaurant.load(); await restaurantPaymentMethod.paymentMethod.load(); return restaurantPaymentMethod; } }