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
133 changes: 118 additions & 15 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"passport-custom": "^1.1.1",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"pg": "^8.15.5",
"pg": "^8.15.6",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",
"starknet": "^6.24.1",
Expand Down Expand Up @@ -78,6 +78,7 @@
"ts-loader": "^9.5.2",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typeorm-ts-node-commonjs": "^0.3.20",
"typescript": "^5.7.3",
"typescript-eslint": "^8.20.0"
},
Expand Down
33 changes: 23 additions & 10 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
import { registerAs } from '@nestjs/config';
import dotenv from 'dotenv';
dotenv.config();

export default registerAs('app', () => ({
// Helper to parse integers robustly
const toInt = (value: string | undefined, fallback: number): number => {
if (value === undefined) return fallback;
const num = parseInt(value, 10);
return Number.isNaN(num) ? fallback : num;
};

// Export a factory function
export default () => ({
env: process.env.NODE_ENV || 'development',
name: process.env.APP_NAME || 'MyApp',
port: parseInt(process.env.APP_PORT || '3000', 10),
name: process.env.APP_NAME || 'budget-chain-backend',
port: toInt(process.env.PORT, 3000),
database: {
host: process.env.DATABASE_HOST || 'localhost',
port: parseInt(process.env.DATABASE_PORT || '5432', 10),
port: toInt(process.env.DATABASE_PORT, 5432),
user: process.env.DATABASE_USER || 'postgres',
password: process.env.DATABASE_PASSWORD || 'secret',
name: process.env.DATABASE_NAME || 'mydatabase',
password: process.env.DATABASE_PASSWORD || 'password',
name: process.env.DATABASE_NAME || 'budgetchain',
},
jwt: {
secret: process.env.JWT_SECRET || 'default_jwt_secret',
expiresIn: process.env.JWT_EXPIRES_IN || '3600s',
secret:
process.env.JWT_SECRET ||
(() => {
throw new Error('JWT_SECRET is not defined');
})(),
expiresIn: process.env.JWT_EXPIRES_IN || '1h',
},
}));
});
45 changes: 45 additions & 0 deletions src/config/data-source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// import { DataSource } from 'typeorm';
// import { ConfigService } from '@nestjs/config';

// const configService = new ConfigService();

// export default new DataSource({
// type: 'postgres',
// host: configService.get('database').host as string,
// port: configService.get('database').port as number,
// username: configService.get('database').user as string,
// password: configService.get('database').password as string,
// database: configService.get('database').name as string,
// entities: ['src/modules/**/*.entity.ts'],
// migrations: ['src/migrations/*.ts'],
// synchronize: false, // Use migrations instead of auto-sync
// });

import { DataSource } from 'typeorm';
import { ConfigService } from '@nestjs/config';

// Define the structure of the database configuration
interface DatabaseConfig {
host: string;
port: number;
user: string;
password: string;
name: string;
}

const configService = new ConfigService();

// Retrieve the database configuration with a type assertion
const database = configService.get('database') as DatabaseConfig;

export default new DataSource({
type: 'postgres',
host: database.host,
port: database.port,
username: database.user,
password: database.password,
database: database.name,
entities: ['src/modules/**/*.entity.ts'],
migrations: ['src/migrations/*.ts'],
synchronize: false, // Use migrations instead of auto-sync
});
Loading
Loading