Add configuration, database, and queue modules for application setup

This commit is contained in:
Jose Eduardo 2025-08-03 20:58:42 -04:00
parent a99d78c4df
commit 48c9a6a016
3 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,23 @@
import { env } from 'node:process';
export default () => ({
port: env.PORT || 9999,
database: {
host: env.DATABASE_HOST || 'localhost',
port: env.DATABASE_PORT || 5432,
username: env.DATABASE_USERNAME || 'postgres',
password: env.DATABASE_PASSWORD || 'password',
database: env.DATABASE_NAME || 'payment_system',
},
redis: {
host: env.REDIS_HOST || 'localhost',
port: env.REDIS_PORT || 6379,
},
paymentProcessors: {
defaultUrl:
env.PAYMENT_PROCESSOR_URL_DEFAULT || 'http://192.168.1.126:8001',
fallbackUrl:
env.PAYMENT_PROCESSOR_URL_FALLBACK || 'http://192.168.1.126:8002',
healthCheckInterval: env.HEALTH_CHECK_INTERVAL || 5000, // 5 segundos
},
});

View File

@ -0,0 +1,27 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { Payment } from '../payments/entities/payment.entity';
@Module({
imports: [
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
type: 'postgres',
host: configService.get('database.host'),
port: configService.get('database.port'),
username: configService.get('database.username'),
password: configService.get('database.password'),
database: configService.get('database.database'),
entities: [Payment],
synchronize: process.env.NODE_ENV !== 'production', // Apenas para desenvolvimento
logging: process.env.NODE_ENV === 'development',
}),
inject: [ConfigService],
}),
TypeOrmModule.forFeature([Payment]),
],
exports: [TypeOrmModule],
})
export class DatabaseModule {}

View File

@ -0,0 +1,19 @@
import { Module } from '@nestjs/common';
import { BullModule } from '@nestjs/bullmq';
@Module({
imports: [
BullModule.forRoot({
connection: {
host: '192.168.1.112',
port: 6379,
username: 'default',
password: '7TfhqvHPe98AQq123',
},
}),
],
controllers: [],
providers: [],
exports: [],
})
export class QueueModule {}