Skip to content

feat: se agrego ms-transaccion y ms-antifraud-rules #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=transaction_db
zookeeper:
image: confluentinc/cp-zookeeper:5.5.3
environment:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore → ms-antifraud-rules/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ build/Release

# Dependency directories
node_modules/
ms-antifraud-rules/node_modules/
ms-transacciones/node_modules/
jspm_packages/

# TypeScript v1 declaration files
Expand Down Expand Up @@ -81,6 +83,8 @@ typings/
# Nuxt.js build / generate output
.nuxt
dist
ms-transacciones/dist
ms-antifraud-rules/dist

# Gatsby files
.cache/
Expand Down
4 changes: 4 additions & 0 deletions ms-antifraud-rules/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
72 changes: 72 additions & 0 deletions ms-antifraud-rules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# ms-antifraud-rules

The `ms-antifraud-rules` microservice is responsible for validating financial transactions and determining their status (approved or rejected) based on predefined rules.

## Features

- Listens to `transaction-created` events from Kafka.
- Validates transactions based on their value:
- Transactions with a value greater than 1000 are rejected.
- Transactions with a value less than or equal to 1000 are approved.
- Emits `transaction-validated` events with the updated transaction status.

## Tech Stack

- **NestJS**: Framework for building scalable server-side applications.
- **Kafka**: Message broker for event-driven communication.
- **TypeScript**: Strongly typed programming language.

## Folder Structure

- `src/validator`: Contains the core logic for validating transactions.
- `validator.service.ts`: Handles transaction validation logic.
- `validator.controller.ts`: Listens to Kafka events and triggers validation.
- `dto/validator.dto.ts`: Defines the data structure for transaction validation.

## How It Works

1. The service listens to the `transaction-created` Kafka topic.
2. When a transaction is created, the service validates it:
- If the transaction value is greater than 1000, it is marked as `REJECTED`.
- Otherwise, it is marked as `APPROVED`.
3. The service emits a `transaction-validated` event with the transaction's updated status.

## Environment Variables

Ensure the following environment variables are set:

- `KAFKA_BROKERS`: Kafka broker addresses (e.g., `localhost:9092`).

## Running the Service

1. Install dependencies:

```bash
npm install

2. Start the service in development mode:

```bash
npm run start:dev

3. Build the service:

```bash
npm run build

## Kafka Topics
* Input: transaction-created
```json
{
"transactionExternalId": "123e4567-e89b-12d3-a456-426614174000",
"value": 1500
}

* Output: transaction-validated
```json
{
"transactionExternalId": "123e4567-e89b-12d3-a456-426614174000",
"status": "REJECTED"
}


37 changes: 37 additions & 0 deletions ms-antifraud-rules/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// @ts-check
import eslint from '@eslint/js';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{
ignores: ['eslint.config.mjs'],
},
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
eslintPluginPrettierRecommended,
{
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
ecmaVersion: 5,
sourceType: 'module',
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'prettier/prettier': 'off'
},
},
);
8 changes: 8 additions & 0 deletions ms-antifraud-rules/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}
Loading