remove graph

This commit is contained in:
2025-11-22 10:49:31 +03:30
parent 2c0ab601f3
commit ee1e6049c5
42 changed files with 364 additions and 875 deletions
@@ -2,8 +2,8 @@ import { Injectable, NotFoundException } from '@nestjs/common';
import { EntityManager } from '@mikro-orm/postgresql';
import { PaymentMethod } from '../entities/payment-method.entity';
import { PaymentMethodRepository } from '../repositories/payment-method.repository';
import { CreatePaymentMethodInput } from '../dto/create-payment-method.input';
import { UpdatePaymentMethodInput } from '../dto/update-payment-method.input';
import { CreatePaymentMethodDto } from '../dto/create-payment-method.dto';
import { UpdatePaymentMethodDto } from '../dto/update-payment-method.dto';
import { RequiredEntityData } from '@mikro-orm/core';
@Injectable()
@@ -13,9 +13,9 @@ export class PaymentMethodService {
private readonly em: EntityManager,
) {}
async create(createPaymentMethodInput: CreatePaymentMethodInput): Promise<PaymentMethod> {
async create(createPaymentMethodDto: CreatePaymentMethodDto): Promise<PaymentMethod> {
const paymentMethod = this.paymentMethodRepository.create(
createPaymentMethodInput as unknown as RequiredEntityData<PaymentMethod>,
createPaymentMethodDto as unknown as RequiredEntityData<PaymentMethod>,
);
await this.em.persistAndFlush(paymentMethod);
return paymentMethod;
@@ -33,9 +33,9 @@ export class PaymentMethodService {
return paymentMethod;
}
async update(id: string, updatePaymentMethodInput: UpdatePaymentMethodInput): Promise<PaymentMethod> {
async update(id: string, updatePaymentMethodDto: UpdatePaymentMethodDto): Promise<PaymentMethod> {
const paymentMethod = await this.findOne(id);
this.em.assign(paymentMethod, updatePaymentMethodInput);
this.em.assign(paymentMethod, updatePaymentMethodDto);
await this.em.flush();
return paymentMethod;
}
@@ -1,10 +1,10 @@
import { Injectable } from '@nestjs/common';
import { CreatePaymentInput } from '../dto/create-payment.input';
import { UpdatePaymentInput } from '../dto/update-payment.input';
import { CreatePaymentDto } from '../dto/create-payment.dto';
import { UpdatePaymentDto } from '../dto/update-payment.dto';
@Injectable()
export class PaymentsService {
create(createPaymentInput: CreatePaymentInput) {
create(createPaymentDto: CreatePaymentDto) {
return 'This action adds a new payment';
}
@@ -16,7 +16,7 @@ export class PaymentsService {
return `This action returns a #${id} payment`;
}
update(id: number, updatePaymentInput: UpdatePaymentInput) {
update(id: number, updatePaymentDto: UpdatePaymentDto) {
return `This action updates a #${id} payment`;
}
@@ -4,8 +4,8 @@ import { RestaurantPaymentMethod } from '../entities/restaurant-payment-method.e
import { RestaurantPaymentMethodRepository } from '../repositories/restaurant-payment-method.repository';
import { Restaurant } from '../../restaurants/entities/restaurant.entity';
import { PaymentMethod } from '../entities/payment-method.entity';
import { CreateRestaurantPaymentMethodInput } from '../dto/create-restaurant-payment-method.input';
import { UpdateRestaurantPaymentMethodInput } from '../dto/update-restaurant-payment-method.input';
import { CreateRestaurantPaymentMethodDto } from '../dto/create-restaurant-payment-method.dto';
import { UpdateRestaurantPaymentMethodDto } from '../dto/update-restaurant-payment-method.dto';
import { RequiredEntityData } from '@mikro-orm/core';
@Injectable()
@@ -16,24 +16,24 @@ export class RestaurantPaymentMethodService {
) {}
async create(
createRestaurantPaymentMethodInput: CreateRestaurantPaymentMethodInput,
createRestaurantPaymentMethodDto: CreateRestaurantPaymentMethodDto,
): Promise<RestaurantPaymentMethod> {
// Check if restaurant exists
const restaurant = await this.em.findOne(Restaurant, { id: createRestaurantPaymentMethodInput.restaurantId });
const restaurant = await this.em.findOne(Restaurant, { id: createRestaurantPaymentMethodDto.restaurantId });
if (!restaurant) {
throw new NotFoundException(`Restaurant with ID ${createRestaurantPaymentMethodInput.restaurantId} not found`);
throw new NotFoundException(`Restaurant with ID ${createRestaurantPaymentMethodDto.restaurantId} not found`);
}
// Check if payment method exists
const paymentMethod = await this.em.findOne(PaymentMethod, { id: createRestaurantPaymentMethodInput.paymentMethodId });
const paymentMethod = await this.em.findOne(PaymentMethod, { id: createRestaurantPaymentMethodDto.paymentMethodId });
if (!paymentMethod) {
throw new NotFoundException(`PaymentMethod with ID ${createRestaurantPaymentMethodInput.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: createRestaurantPaymentMethodInput.restaurantId },
paymentMethod: { id: createRestaurantPaymentMethodInput.paymentMethodId },
restaurant: { id: createRestaurantPaymentMethodDto.restaurantId },
paymentMethod: { id: createRestaurantPaymentMethodDto.paymentMethodId },
});
if (existing) {
@@ -43,8 +43,8 @@ export class RestaurantPaymentMethodService {
const restaurantPaymentMethod = this.restaurantPaymentMethodRepository.create({
restaurant,
paymentMethod,
merchantId: createRestaurantPaymentMethodInput.merchantId,
isActive: createRestaurantPaymentMethodInput.isActive ?? true,
merchantId: createRestaurantPaymentMethodDto.merchantId,
isActive: createRestaurantPaymentMethodDto.isActive ?? true,
} as unknown as RequiredEntityData<RestaurantPaymentMethod>);
await this.em.persistAndFlush(restaurantPaymentMethod);
@@ -82,28 +82,28 @@ export class RestaurantPaymentMethodService {
async update(
id: string,
updateRestaurantPaymentMethodInput: UpdateRestaurantPaymentMethodInput,
updateRestaurantPaymentMethodDto: UpdateRestaurantPaymentMethodDto,
): Promise<RestaurantPaymentMethod> {
const restaurantPaymentMethod = await this.findOne(id);
if (updateRestaurantPaymentMethodInput.restaurantId) {
const restaurant = await this.em.findOne(Restaurant, { id: updateRestaurantPaymentMethodInput.restaurantId });
if (updateRestaurantPaymentMethodDto.restaurantId) {
const restaurant = await this.em.findOne(Restaurant, { id: updateRestaurantPaymentMethodDto.restaurantId });
if (!restaurant) {
throw new NotFoundException(`Restaurant with ID ${updateRestaurantPaymentMethodInput.restaurantId} not found`);
throw new NotFoundException(`Restaurant with ID ${updateRestaurantPaymentMethodDto.restaurantId} not found`);
}
restaurantPaymentMethod.restaurant = restaurant;
}
if (updateRestaurantPaymentMethodInput.paymentMethodId) {
const paymentMethod = await this.em.findOne(PaymentMethod, { id: updateRestaurantPaymentMethodInput.paymentMethodId });
if (updateRestaurantPaymentMethodDto.paymentMethodId) {
const paymentMethod = await this.em.findOne(PaymentMethod, { id: updateRestaurantPaymentMethodDto.paymentMethodId });
if (!paymentMethod) {
throw new NotFoundException(`PaymentMethod with ID ${updateRestaurantPaymentMethodInput.paymentMethodId} not found`);
throw new NotFoundException(`PaymentMethod with ID ${updateRestaurantPaymentMethodDto.paymentMethodId} not found`);
}
// Check if the new relationship already exists
const existing = await this.restaurantPaymentMethodRepository.findOne({
restaurant: { id: restaurantPaymentMethod.restaurant.id },
paymentMethod: { id: updateRestaurantPaymentMethodInput.paymentMethodId },
paymentMethod: { id: updateRestaurantPaymentMethodDto.paymentMethodId },
});
if (existing && existing.id !== id) {
@@ -114,12 +114,12 @@ export class RestaurantPaymentMethodService {
}
// Update merchantId and isActive if provided
if (updateRestaurantPaymentMethodInput.merchantId !== undefined) {
restaurantPaymentMethod.merchantId = updateRestaurantPaymentMethodInput.merchantId;
if (updateRestaurantPaymentMethodDto.merchantId !== undefined) {
restaurantPaymentMethod.merchantId = updateRestaurantPaymentMethodDto.merchantId;
}
if (updateRestaurantPaymentMethodInput.isActive !== undefined) {
restaurantPaymentMethod.isActive = updateRestaurantPaymentMethodInput.isActive;
if (updateRestaurantPaymentMethodDto.isActive !== undefined) {
restaurantPaymentMethod.isActive = updateRestaurantPaymentMethodDto.isActive;
}
await this.em.flush();