20 lines
881 B
TypeScript
20 lines
881 B
TypeScript
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<RestaurantPaymentMethod> {
|
|
constructor(readonly em: EntityManager) {
|
|
super(em, RestaurantPaymentMethod);
|
|
}
|
|
async findOneWithPopulate(id: string): Promise<RestaurantPaymentMethod> {
|
|
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;
|
|
}
|
|
}
|