payment
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user