Files
dmenu-api/src/modules/payments/repositories/restaurant-payment-method.repository.ts
T
2025-12-01 10:34:40 +03:30

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;
}
}