Refactor Payments module structure and update controller to use new service paths
This commit is contained in:
parent
8d6a8f75ea
commit
f6b560bf86
@ -1,5 +1,5 @@
|
|||||||
import { Body, Controller, Post } from '@nestjs/common';
|
import { Body, Controller, Post } from '@nestjs/common';
|
||||||
import { PaymentsService } from './payments.service';
|
import { PaymentsService } from './services/payments.service';
|
||||||
import { CreatePaymentDto } from './dto/create-payment.dto';
|
import { CreatePaymentDto } from './dto/create-payment.dto';
|
||||||
|
|
||||||
@Controller('payments')
|
@Controller('payments')
|
||||||
@ -7,7 +7,7 @@ export class PaymentsController {
|
|||||||
constructor(private readonly paymentsService: PaymentsService) {}
|
constructor(private readonly paymentsService: PaymentsService) {}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
async payment(@Body() createPaymentDto: CreatePaymentDto) {
|
async payment(@Body() createPaymentDto: CreatePaymentDto): Promise<any> {
|
||||||
return this.paymentsService.store(createPaymentDto);
|
return this.paymentsService.store(createPaymentDto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,20 +1,34 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { PaymentsService } from './payments.service';
|
import { PaymentsService } from './services/payments.service';
|
||||||
import { PaymentsController } from './payments.controller';
|
import { PaymentsController } from './payments.controller';
|
||||||
import { HttpModule } from '@nestjs/axios';
|
import { HttpModule } from '@nestjs/axios';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { Payment } from './entities/payment.entity';
|
import { Payment } from './entities/payment.entity';
|
||||||
import { BullModule } from '@nestjs/bullmq';
|
import { HealthModule } from '../health/health.module';
|
||||||
|
import { PaymentDefaultProcessor } from './processor/payment-default.processor';
|
||||||
|
import { RetryPaymentService } from './services/retry-payment.service';
|
||||||
|
import { PaymentProcessor } from './processor/payment.processor';
|
||||||
|
import { ProcessPaymentService } from './services/process-payment.service';
|
||||||
|
import { QueueModule } from '../queue/queue.module';
|
||||||
|
import { DatabaseModule } from '../database/database.module';
|
||||||
|
import { PaymentFallbackProcessor } from './processor/payment-fallback.processor';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forFeature([Payment]),
|
TypeOrmModule.forFeature([Payment]),
|
||||||
BullModule.registerQueue({
|
|
||||||
name: 'payments',
|
|
||||||
}),
|
|
||||||
HttpModule,
|
HttpModule,
|
||||||
|
HealthModule,
|
||||||
|
QueueModule,
|
||||||
|
DatabaseModule,
|
||||||
],
|
],
|
||||||
controllers: [PaymentsController],
|
controllers: [PaymentsController],
|
||||||
providers: [PaymentsService],
|
providers: [
|
||||||
|
PaymentsService,
|
||||||
|
PaymentDefaultProcessor,
|
||||||
|
RetryPaymentService,
|
||||||
|
PaymentProcessor,
|
||||||
|
ProcessPaymentService,
|
||||||
|
PaymentFallbackProcessor,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class PaymentsModule {}
|
export class PaymentsModule {}
|
||||||
|
|||||||
@ -1,39 +0,0 @@
|
|||||||
import { Injectable, Logger } from '@nestjs/common';
|
|
||||||
import { CreatePaymentDto } from './dto/create-payment.dto';
|
|
||||||
import { HttpService } from '@nestjs/axios';
|
|
||||||
import { catchError, firstValueFrom } from 'rxjs';
|
|
||||||
import { AxiosError } from 'axios';
|
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
|
||||||
import { Payment } from './entities/payment.entity';
|
|
||||||
import { Repository } from 'typeorm';
|
|
||||||
import { Queue } from 'bullmq';
|
|
||||||
import { InjectQueue } from '@nestjs/bullmq';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class PaymentsService {
|
|
||||||
private readonly logger = new Logger(PaymentsService.name);
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
@InjectQueue('payments') private readonly paymentsQueue: Queue,
|
|
||||||
private readonly httpService: HttpService,
|
|
||||||
@InjectRepository(Payment) private readonly repository: Repository<Payment>,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
async store(createPaymentDto: CreatePaymentDto) {
|
|
||||||
const urlPaymentDefault = 'http://192.168.1.126:8002/payments';
|
|
||||||
const { data } = await firstValueFrom(
|
|
||||||
this.httpService.post(urlPaymentDefault, createPaymentDto).pipe(
|
|
||||||
catchError((error: AxiosError) => {
|
|
||||||
this.logger.error(error?.response);
|
|
||||||
throw 'An error happened!';
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
await this.repository.save({
|
|
||||||
...createPaymentDto,
|
|
||||||
paymentProcessor: 'default',
|
|
||||||
});
|
|
||||||
this.logger.log(data);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user