Refactor payment processing services to use CreatePaymentDto and simplify job handling
This commit is contained in:
parent
434f03f6c6
commit
96b1e8cd80
@ -4,7 +4,7 @@ import { HttpService } from '@nestjs/axios';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Payment } from '../entities/payment.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { PaymentJobData } from '../../queue/queue.service';
|
||||
import { CreatePaymentDto } from '../dto/create-payment.dto';
|
||||
|
||||
@Injectable()
|
||||
export class MakePaymentToProcessorService {
|
||||
@ -15,10 +15,10 @@ export class MakePaymentToProcessorService {
|
||||
@InjectRepository(Payment) private readonly repository: Repository<Payment>,
|
||||
) {}
|
||||
|
||||
async execute(payment: PaymentJobData, url: string): Promise<boolean> {
|
||||
async execute(payment: CreatePaymentDto, url: string): Promise<boolean> {
|
||||
const paymentData = {
|
||||
amount: payment.paymentData.amount,
|
||||
correlationId: payment.paymentData.correlationId,
|
||||
amount: payment.amount,
|
||||
correlationId: payment.correlationId,
|
||||
};
|
||||
|
||||
const response = await firstValueFrom(
|
||||
|
||||
@ -2,8 +2,6 @@ import { Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Payment } from '../entities/payment.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { QueueService } from '../../queue/queue.service';
|
||||
import { PaymentStatusEnum } from '../enumns/payment-status.enum';
|
||||
import { ProcessorTypeEnum } from '../enumns/processor-type.enum';
|
||||
|
||||
@Injectable()
|
||||
@ -12,7 +10,6 @@ export class PaymentsSummaryService {
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Payment) private readonly repository: Repository<Payment>,
|
||||
private queueService: QueueService,
|
||||
) {}
|
||||
|
||||
async execute(from: string, to: string) {
|
||||
@ -22,9 +19,6 @@ export class PaymentsSummaryService {
|
||||
.addSelect('COUNT(*)', 'totalRequests')
|
||||
.addSelect('SUM(payment.amount)', 'totalAmount')
|
||||
.where('payment.createdAt BETWEEN :from AND :to', { from, to })
|
||||
.andWhere('payment.status = :status', {
|
||||
status: PaymentStatusEnum.SUCCESS,
|
||||
})
|
||||
.groupBy('payment.paymentProcessor');
|
||||
|
||||
const results = await qb.getRawMany();
|
||||
|
||||
@ -16,8 +16,7 @@ export class PaymentsService {
|
||||
|
||||
async store(createPaymentDto: CreatePaymentDto) {
|
||||
await this.queueService.addPaymentJob({
|
||||
paymentData: createPaymentDto,
|
||||
createdAt: new Date(),
|
||||
...createPaymentDto,
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { PaymentDefaultProcessor } from '../processor/payment-default.processor';
|
||||
import { PaymentFallbackProcessor } from '../processor/payment-fallback.processor';
|
||||
import { PaymentJobData } from '../../queue/queue.service';
|
||||
import { CreatePaymentDto } from '../dto/create-payment.dto';
|
||||
|
||||
@Injectable()
|
||||
export class ProcessPaymentService {
|
||||
@ -12,7 +12,7 @@ export class ProcessPaymentService {
|
||||
private paymentFallbackProcessor: PaymentFallbackProcessor,
|
||||
) {}
|
||||
|
||||
async execute(job: PaymentJobData): Promise<void> {
|
||||
async execute(job: CreatePaymentDto): Promise<void> {
|
||||
const result = await this.paymentDefaultProcessor.execute(job);
|
||||
if (!result) await this.paymentFallbackProcessor.execute(job);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user