This commit is contained in:
2025-11-21 18:37:09 +03:30
parent e2a04e6a50
commit 2c0ab601f3
22 changed files with 669 additions and 2 deletions
@@ -0,0 +1,48 @@
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 { RequiredEntityData } from '@mikro-orm/core';
@Injectable()
export class PaymentMethodService {
constructor(
private readonly paymentMethodRepository: PaymentMethodRepository,
private readonly em: EntityManager,
) {}
async create(createPaymentMethodInput: CreatePaymentMethodInput): Promise<PaymentMethod> {
const paymentMethod = this.paymentMethodRepository.create(
createPaymentMethodInput as unknown as RequiredEntityData<PaymentMethod>,
);
await this.em.persistAndFlush(paymentMethod);
return paymentMethod;
}
async findAll(): Promise<PaymentMethod[]> {
return this.paymentMethodRepository.findAll();
}
async findOne(id: string): Promise<PaymentMethod> {
const paymentMethod = await this.paymentMethodRepository.findOne({ id });
if (!paymentMethod) {
throw new NotFoundException(`PaymentMethod with ID ${id} not found`);
}
return paymentMethod;
}
async update(id: string, updatePaymentMethodInput: UpdatePaymentMethodInput): Promise<PaymentMethod> {
const paymentMethod = await this.findOne(id);
this.em.assign(paymentMethod, updatePaymentMethodInput);
await this.em.flush();
return paymentMethod;
}
async remove(id: string): Promise<PaymentMethod> {
const paymentMethod = await this.findOne(id);
await this.em.removeAndFlush(paymentMethod);
return paymentMethod;
}
}