Skip to content

Commit

Permalink
chore: added absolute aliases and renamed variable env
Browse files Browse the repository at this point in the history
  • Loading branch information
pratham-outside committed Dec 29, 2024
1 parent 5233053 commit 81a71f0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { AppService } from '@/app.service';

@Controller()
export class AppController {
Expand Down
10 changes: 5 additions & 5 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { validate } from './config/env.config';
import { ConfigModule } from '@nestjs/config';
import { DatabaseModule } from './database/db.module';
import { Module } from '@nestjs/common';
import { AppController } from '@/app.controller';
import { AppService } from '@/app.service';
import { validate } from '@/config/env.config';
import { DatabaseModule } from '@/database/db.module';

@Module({
imports: [ConfigModule.forRoot({ isGlobal: true, validate }), DatabaseModule],
Expand Down
6 changes: 3 additions & 3 deletions src/database/db.module.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
import { dataBaseConfigurations } from 'src/scripts/orm.config';
import { dataBaseConfigurations } from '@/scripts/orm.config';
import { DataSource, DataSourceOptions, TypeORMError } from 'typeorm';
import { envVariables } from '@/config/env.config';
import { env } from '@/config/env.config';

@Module({
imports: [
TypeOrmModule.forRootAsync({
useFactory: () => {
return {
host: envVariables.DB_HOST,
host: env.DB_HOST,
...dataBaseConfigurations,
} as TypeOrmModuleOptions;
},
Expand Down
8 changes: 4 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { envVariables } from './config/env.config';
import { AppModule } from '@/app.module';
import { env } from '@/config/env.config';

async function bootstrap(): Promise<void> {
const app = await NestFactory.create(AppModule);
const port = envVariables.APP_PORT;
const port = env.APP_PORT;
await app.listen(port, () => {
console.info(`Server listening at port ${port}`);
console.info(`${env.NODE_ENV?.toLocaleUpperCase()} Server listening at port ${port}`);
});
}

Expand Down
12 changes: 6 additions & 6 deletions src/scripts/orm.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { writeFile } from 'fs/promises';
import { join } from 'path';
import { DataSource, DataSourceOptions } from 'typeorm';
import { envVariables } from '@/config/env.config';
import { env, APP_ENVIRONVENT } from '@/config/env.config';

const dataBaseConfigurations = {
type: 'postgres',
port: +(envVariables.POSTGRES_PORT ?? '5432'),
username: envVariables.POSTGRES_USER,
password: envVariables.POSTGRES_PASSWORD,
database: envVariables.POSTGRES_DB,
synchronize: false, // Should be false in production to use migrations
port: +env.POSTGRES_PORT,
username: env.POSTGRES_USER,
password: env.POSTGRES_PASSWORD,
database: env.POSTGRES_DB,
synchronize: env.NODE_ENV === APP_ENVIRONVENT.PRODUCTION ? false : true, // Should be false in production to use migrations
logging: true,
entities: [join(__dirname, '/../entities', '*.entity.{ts,js}')],
migrations: [join(__dirname, '/../migrations', '*.{ts,js}')],
Expand Down

0 comments on commit 81a71f0

Please sign in to comment.