remove rest id from creating
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user