remove rest id from creating

This commit is contained in:
2025-11-22 12:46:26 +03:30
parent 9845b5e017
commit 8e63213f1d
5 changed files with 25 additions and 17 deletions
@@ -16,23 +16,28 @@ export class RestaurantPaymentMethodService {
) {}
async create(
restId: string,
createRestaurantPaymentMethodDto: CreateRestaurantPaymentMethodDto,
): Promise<RestaurantPaymentMethod> {
// Check if restaurant exists
const restaurant = await this.em.findOne(Restaurant, { id: createRestaurantPaymentMethodDto.restaurantId });
const restaurant = await this.em.findOne(Restaurant, { id: restId });
if (!restaurant) {
throw new NotFoundException(`Restaurant with ID ${createRestaurantPaymentMethodDto.restaurantId} not found`);
throw new NotFoundException(`Restaurant with ID ${restId} not found`);
}
// Check if payment method exists
const paymentMethod = await this.em.findOne(PaymentMethod, { id: createRestaurantPaymentMethodDto.paymentMethodId });
const paymentMethod = await this.em.findOne(PaymentMethod, {
id: createRestaurantPaymentMethodDto.paymentMethodId,
});
if (!paymentMethod) {
throw new NotFoundException(`PaymentMethod with ID ${createRestaurantPaymentMethodDto.paymentMethodId} not found`);
throw new NotFoundException(
`PaymentMethod with ID ${createRestaurantPaymentMethodDto.paymentMethodId} not found`,
);
}
// Check if the relationship already exists
const existing = await this.restaurantPaymentMethodRepository.findOne({
restaurant: { id: createRestaurantPaymentMethodDto.restaurantId },
restaurant: { id: restId },
paymentMethod: { id: createRestaurantPaymentMethodDto.paymentMethodId },
});
@@ -95,9 +100,13 @@ export class RestaurantPaymentMethodService {
}
if (updateRestaurantPaymentMethodDto.paymentMethodId) {
const paymentMethod = await this.em.findOne(PaymentMethod, { id: updateRestaurantPaymentMethodDto.paymentMethodId });
const paymentMethod = await this.em.findOne(PaymentMethod, {
id: updateRestaurantPaymentMethodDto.paymentMethodId,
});
if (!paymentMethod) {
throw new NotFoundException(`PaymentMethod with ID ${updateRestaurantPaymentMethodDto.paymentMethodId} not found`);
throw new NotFoundException(
`PaymentMethod with ID ${updateRestaurantPaymentMethodDto.paymentMethodId} not found`,
);
}
// Check if the new relationship already exists