Skip to content

Commit 0acbe78

Browse files
MiguelMiguel
authored andcommitted
challenge resolved
1 parent 270dee2 commit 0acbe78

19 files changed

Lines changed: 408 additions & 12 deletions

.eslintrc.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
project: 'tsconfig.json',
5+
tsconfigRootDir: __dirname,
6+
sourceType: 'module',
7+
},
8+
plugins: ['@typescript-eslint/eslint-plugin'],
9+
extends: [
10+
'plugin:@typescript-eslint/recommended',
11+
'plugin:prettier/recommended',
12+
],
13+
root: true,
14+
env: {
15+
node: true,
16+
jest: true,
17+
},
18+
ignorePatterns: ['.eslintrc.js'],
19+
rules: {
20+
'@typescript-eslint/interface-name-prefix': 'off',
21+
'@typescript-eslint/explicit-function-return-type': 'off',
22+
'@typescript-eslint/explicit-module-boundary-types': 'off',
23+
'@typescript-eslint/no-explicit-any': 'off',
24+
},
25+
};

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,6 @@ dist
102102

103103
# TernJS port file
104104
.tern-port
105+
106+
#package-lock.json
107+
package-lock.json

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all"
4+
}

docker-compose.yml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,22 @@ services:
88
- POSTGRES_USER=postgres
99
- POSTGRES_PASSWORD=postgres
1010
zookeeper:
11-
image: confluentinc/cp-zookeeper:5.5.3
11+
image: bitnami/zookeeper:3.9
12+
container_name: zookeeper
13+
ports:
14+
- '2181:2181'
1215
environment:
13-
ZOOKEEPER_CLIENT_PORT: 2181
16+
- ALLOW_ANONYMOUS_LOGIN=yes
1417
kafka:
15-
image: confluentinc/cp-enterprise-kafka:5.5.3
16-
depends_on: [zookeeper]
17-
environment:
18-
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
19-
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
20-
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
21-
KAFKA_BROKER_ID: 1
22-
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
23-
KAFKA_JMX_PORT: 9991
18+
image: bitnami/kafka:3.6
19+
container_name: kafka
2420
ports:
25-
- 9092:9092
21+
- '9092:9092'
22+
environment:
23+
- KAFKA_BROKER_ID=1
24+
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
25+
- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092
26+
- KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
27+
- ALLOW_PLAINTEXT_LISTENER=yes
28+
depends_on:
29+
- zookeeper

nest-cli.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://json.schemastore.org/nest-cli",
3+
"collection": "@nestjs/schematics",
4+
"sourceRoot": "src",
5+
"compilerOptions": {
6+
"deleteOutDir": true
7+
}
8+
}

package.json

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"name": "app-nodejs-codechallenge",
3+
"version": "0.0.1",
4+
"description": "",
5+
"author": "",
6+
"private": true,
7+
"license": "UNLICENSED",
8+
"scripts": {
9+
"build": "nest build",
10+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
11+
"start": "nest start",
12+
"local": "nest start --watch",
13+
"start:debug": "nest start --debug --watch",
14+
"start:prod": "node dist/main",
15+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
16+
"test": "jest",
17+
"test:watch": "jest --watch",
18+
"test:cov": "jest --coverage",
19+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
20+
"test:e2e": "jest --config ./test/jest-e2e.json"
21+
},
22+
"dependencies": {
23+
"@nestjs/common": "^10.0.0",
24+
"@nestjs/config": "^4.0.2",
25+
"@nestjs/core": "^10.0.0",
26+
"@nestjs/microservices": "^10.4.18",
27+
"@nestjs/platform-express": "^10.0.0",
28+
"@nestjs/typeorm": "^11.0.0",
29+
"class-transformer": "^0.5.1",
30+
"class-validator": "^0.14.2",
31+
"kafkajs": "^2.2.4",
32+
"pg": "^8.16.0",
33+
"reflect-metadata": "^0.2.0",
34+
"rxjs": "^7.8.1",
35+
"typeorm": "^0.3.24"
36+
},
37+
"devDependencies": {
38+
"@nestjs/cli": "^10.0.0",
39+
"@nestjs/schematics": "^10.0.0",
40+
"@nestjs/testing": "^10.0.0",
41+
"@types/express": "^5.0.0",
42+
"@types/jest": "^29.5.2",
43+
"@types/node": "^20.3.1",
44+
"@types/supertest": "^6.0.0",
45+
"@typescript-eslint/eslint-plugin": "^8.0.0",
46+
"@typescript-eslint/parser": "^8.0.0",
47+
"eslint": "^8.0.0",
48+
"eslint-config-prettier": "^9.0.0",
49+
"eslint-plugin-prettier": "^5.0.0",
50+
"jest": "^29.5.0",
51+
"prettier": "^3.0.0",
52+
"source-map-support": "^0.5.21",
53+
"supertest": "^7.0.0",
54+
"ts-jest": "^29.1.0",
55+
"ts-loader": "^9.4.3",
56+
"ts-node": "^10.9.1",
57+
"tsconfig-paths": "^4.2.0",
58+
"typescript": "^5.1.3"
59+
},
60+
"jest": {
61+
"moduleFileExtensions": [
62+
"js",
63+
"json",
64+
"ts"
65+
],
66+
"rootDir": "src",
67+
"testRegex": ".*\\.spec\\.ts$",
68+
"transform": {
69+
"^.+\\.(t|j)s$": "ts-jest"
70+
},
71+
"collectCoverageFrom": [
72+
"**/*.(t|j)s"
73+
],
74+
"coverageDirectory": "../coverage",
75+
"testEnvironment": "node"
76+
}
77+
}

src/app.module.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Module } from '@nestjs/common';
2+
import { TransactionModule } from './transaction/transaction.module';
3+
import { ConfigModule } from '@nestjs/config';
4+
import { TypeOrmModule } from '@nestjs/typeorm';
5+
6+
@Module({
7+
imports: [
8+
ConfigModule.forRoot({
9+
isGlobal: true,
10+
}),
11+
TypeOrmModule.forRoot({
12+
type: 'postgres',
13+
host: process.env.POSTGRES_HOST,
14+
port: parseInt(process.env.POSTGRES_PORT, 10),
15+
username: process.env.POSTGRES_USER,
16+
password: process.env.POSTGRES_PASSWORD,
17+
database: process.env.POSTGRES_DB,
18+
autoLoadEntities: true,
19+
synchronize: true,
20+
}),
21+
TransactionModule,
22+
],
23+
controllers: [],
24+
providers: [],
25+
})
26+
export class AppModule { }

src/main.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { NestFactory } from '@nestjs/core';
2+
import { AppModule } from './app.module';
3+
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
4+
import { ValidationPipe } from '@nestjs/common';
5+
6+
async function bootstrap() {
7+
const app = await NestFactory.create(AppModule);
8+
app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
9+
app.connectMicroservice<MicroserviceOptions>({
10+
transport: Transport.KAFKA,
11+
options: {
12+
client: {
13+
brokers: ['localhost:9092'],
14+
},
15+
consumer: {
16+
groupId: 'transaction-consumer-group',
17+
},
18+
},
19+
});
20+
21+
await app.startAllMicroservices();
22+
await app.listen(process.env.PORT ?? 3000);
23+
}
24+
bootstrap();

src/shared/enum/enum.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export enum TransferType {
2+
TRANSFER = 1,
3+
PAYMENT = 2,
4+
REFUND = 3,
5+
WITHDRAWAL = 4
6+
}
7+
8+
export const TransferTypeLabel = {
9+
[TransferType.TRANSFER]: 'transfer',
10+
[TransferType.PAYMENT]: 'payment',
11+
[TransferType.REFUND]: 'refund',
12+
[TransferType.WITHDRAWAL]: 'withdrawal',
13+
} as const;

src/shared/kafka/kafka.module.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Module } from '@nestjs/common';
2+
import { KafkaProducerService } from './kafka.producer';
3+
4+
@Module({
5+
providers: [KafkaProducerService],
6+
exports: [KafkaProducerService],
7+
})
8+
export class KafkaModule {}

0 commit comments

Comments
 (0)