Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-with-jest-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
with:
# Sets the minimum coverage threshold to 5%
# You can adjust this value as your project grows
threshold: 60
threshold: 30
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
"cSpell.words": [
"autoincrement"
],
"postman.settings.dotenv-detection-notification-visibility": false,
}
72 changes: 69 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
},
"homepage": "https://github.com/lukchm94/NodeGateway#readme",
"dependencies": {
"amqplib": "^0.10.9",
"axios": "^1.11.0",
"body-parser": "^2.2.0",
"dotenv": "^17.2.2",
"express": "^5.1.0",
"joi": "^17.13.3",
"reflect-metadata": "^0.2.2"
},
"devDependencies": {
"@types/amqplib": "^0.10.7",
"@types/body-parser": "^1.19.6",
"@types/express": "^5.0.3",
"@types/jest": "^30.0.0",
Expand All @@ -44,7 +47,11 @@
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"roots": ["<rootDir>/tests"],
"setupFiles": ["<rootDir>/tests/jest.setup.ts"]
"roots": [
"<rootDir>/tests"
],
"setupFiles": [
"<rootDir>/tests/jest.setup.ts"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export class ProcessTransactionUseCase extends BaseClass {
private readonly transactionService: TransactionService
) {
super(appLogger);
this.appLogger.info(
`${this.logPrefix} ${RegisteredServicesEnum.PROCESS_TRANSACTION_USE_CASE} initialized`
);
}

public async run(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { inject, injectable } from "tsyringe";
import { RabbitClient } from "../../../../shared/clients/rabbitMQ/rabbit.client";
import { TransactionRequestEvent } from "../../../../shared/clients/rabbitMQ/transaction.request.event";
import { RegisteredServicesEnum } from "../../../../shared/DIcontainer/registeredServicesEnum";
import { BaseClass } from "../../../../shared/utils/log-prefix.class";
import { Logger } from "../../../../shared/utils/logger";
import { TransactionService } from "../../domain/services/transaction.service";
import { Transaction } from "../../domain/transaction.entity";

@injectable()
export class ProcessTrxEventUseCase extends BaseClass {
constructor(
@inject(RegisteredServicesEnum.APP_LOGGER)
protected readonly appLogger: Logger,
@inject(RegisteredServicesEnum.RABBIT_CLIENT)
private readonly rabbitClient: RabbitClient,
@inject(RegisteredServicesEnum.TRANSACTION_SERVICE)
private readonly transactionService: TransactionService
) {
super(appLogger);
this.appLogger.info(
`${this.logPrefix} ${RegisteredServicesEnum.PROCESS_TRX_EVENT_USE_CASE} initialized`
);
}
public async run(event: TransactionRequestEvent): Promise<Transaction> {

Check warning on line 25 in src/modules/transaction/application/process-trx-event.use-case/process-trx-event.use-case.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
const transactionInput = event.data.eventInput;

Check warning on line 26 in src/modules/transaction/application/process-trx-event.use-case/process-trx-event.use-case.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const transaction =
this.transactionService.processTransaction(transactionInput);

Check warning on line 28 in src/modules/transaction/application/process-trx-event.use-case/process-trx-event.use-case.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
await this.rabbitClient.sendToQueue(transaction);

Check warning on line 29 in src/modules/transaction/application/process-trx-event.use-case/process-trx-event.use-case.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
return transaction;
}
}
5 changes: 4 additions & 1 deletion src/modules/transaction/interfaces/transaction.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { BaseClass } from "../../../shared/utils/log-prefix.class";
import { Logger } from "../../../shared/utils/logger";
import { GatewayOutput } from "../application/output";
import { ProcessTransactionUseCase } from "../application/process-transaction-use-case/process-transaction.use-case";
import { ProcessTrxEventUseCase } from "../application/process-trx-event.use-case/process-trx-event.use-case";
import { CURRENCY_TYPE } from "../domain/validation/currency";
import { TRANSACTION_STATUS_TYPE } from "../domain/validation/status";
import { RequestWithSafeFields } from "./request.interface";
Expand All @@ -19,7 +20,9 @@ export class TransactionController extends BaseClass {
@inject(RegisteredServicesEnum.APP_LOGGER)
protected readonly appLogger: Logger,
@inject(RegisteredServicesEnum.PROCESS_TRANSACTION_USE_CASE)
private readonly processTransactionUseCase: ProcessTransactionUseCase
private readonly processTransactionUseCase: ProcessTransactionUseCase,
@inject(RegisteredServicesEnum.PROCESS_TRX_EVENT_USE_CASE)
private readonly processTrxEventUseCase: ProcessTrxEventUseCase
) {
super(appLogger);
}
Expand Down
8 changes: 7 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import "dotenv/config";
import { Router } from "express";
import "reflect-metadata";
import { RabbitService } from "./shared/clients/rabbitMQ/rabbit.service";
import { DIContainer } from "./shared/DIcontainer/container";
import { RegisteredServicesEnum } from "./shared/DIcontainer/registeredServicesEnum";
import { RouterService } from "./shared/routers/router.service";
import { RoutesEnum } from "./shared/routers/routes.enum";
import { App } from "./shared/server/app";
import { Logger } from "./shared/utils/logger";

/**
* The `bootstrap` function initializes a server application with defined routes and logging, starting
* the server on a specified port.
Expand All @@ -19,6 +20,11 @@ async function bootstrap() {
const routerService = DIContainer.resolve<RouterService>(
RegisteredServicesEnum.ROUTER_SERVICE
);
const rabbitService = DIContainer.resolve<RabbitService>(
RegisteredServicesEnum.RABBIT_SERVICE
);
await rabbitService.start();
appLogger.info(`[Server] RabbitMQ service is active ✅`);

const routes: Array<{ prefix: RoutesEnum; router: Router }> =
routerService.setupRouters();
Expand Down
18 changes: 18 additions & 0 deletions src/shared/DIcontainer/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import { container } from "tsyringe";
import { HealthController } from "../../modules/health/interfaces/health.controller";
import { HealthRouter } from "../../modules/health/interfaces/health.router";
import { ProcessTransactionUseCase } from "../../modules/transaction/application/process-transaction-use-case/process-transaction.use-case";
import { ProcessTrxEventUseCase } from "../../modules/transaction/application/process-trx-event.use-case/process-trx-event.use-case";
import { TransactionService } from "../../modules/transaction/domain/services/transaction.service";
import { WebhookService } from "../../modules/transaction/domain/services/webhook.service";
import { TransactionController } from "../../modules/transaction/interfaces/transaction.controller";
import { TransactionRouter } from "../../modules/transaction/interfaces/transaction.router";
import { RabbitClient } from "../clients/rabbitMQ/rabbit.client";
import { RabbitService } from "../clients/rabbitMQ/rabbit.service";
import { WebhookClient } from "../clients/webhook/webhook.client";
import { RouterService } from "../routers/router.service";
import { Logger } from "../utils/logger";
import { RegisteredServicesEnum } from "./registeredServicesEnum";

// Utilities
container.register<Logger>(RegisteredServicesEnum.APP_LOGGER, {
useClass: Logger,
Expand Down Expand Up @@ -45,6 +49,12 @@ container.register<ProcessTransactionUseCase>(
useClass: ProcessTransactionUseCase,
}
);
container.register<ProcessTrxEventUseCase>(
RegisteredServicesEnum.PROCESS_TRX_EVENT_USE_CASE,
{
useClass: ProcessTrxEventUseCase,
}
);
container.register<TransactionController>(
RegisteredServicesEnum.TRANSACTION_CONTROLLER,
{ useClass: TransactionController }
Expand All @@ -53,4 +63,12 @@ container.register<TransactionRouter>(
RegisteredServicesEnum.TRANSACTION_ROUTER,
{ useClass: TransactionRouter }
);

// RabbitMQ
container.register<RabbitClient>(RegisteredServicesEnum.RABBIT_CLIENT, {
useClass: RabbitClient,
});
container.register<RabbitService>(RegisteredServicesEnum.RABBIT_SERVICE, {
useClass: RabbitService,
});
export const DIContainer = container;
5 changes: 5 additions & 0 deletions src/shared/DIcontainer/registeredServicesEnum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ export enum RegisteredServicesEnum {
TRANSACTION_CONTROLLER = "TransactionController",
TRANSACTION_SERVICE = "TransactionService",
PROCESS_TRANSACTION_USE_CASE = "ProcessTransactionUseCase",
PROCESS_TRX_EVENT_USE_CASE = "ProcessTrxEventUseCase",

// RabbitMQ client
RABBIT_CLIENT = "RabbitClient",
RABBIT_SERVICE = "RabbitService",
}
6 changes: 6 additions & 0 deletions src/shared/clients/rabbitMQ/output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Transaction } from "../../../modules/transaction/domain/transaction.entity";

export interface TransactionResponsePayload {
pattern: string;
data: Transaction;
}
Loading