-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
103 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
api/src/modules/auth/authentication/authentication.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Controller } from '@nestjs/common'; | ||
|
||
@Controller('authentication') | ||
export class AuthenticationController {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AuthenticationService } from './authentication.service'; | ||
import { AuthenticationController } from './authentication.controller'; | ||
|
||
@Module({ | ||
providers: [AuthenticationService], | ||
controllers: [AuthenticationController], | ||
}) | ||
export class AuthenticationModule {} |
4 changes: 4 additions & 0 deletions
4
api/src/modules/auth/authentication/authentication.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class AuthenticationService {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
@Module({}) | ||
export class AuthorisationModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Global, Module } from '@nestjs/common'; | ||
import { ConfigModule, ConfigService } from '@nestjs/config'; | ||
import { join } from 'path'; | ||
import { ApiConfigService } from '@api/modules/config/app-config.service'; | ||
import { DatabaseModule } from '@api/modules/config/database/database.module'; | ||
|
||
@Global() | ||
@Module({ | ||
imports: [ | ||
DatabaseModule, | ||
/** | ||
* @note: Check if we can abstract the conf to ApiConfigService | ||
*/ | ||
ConfigModule.forRoot({ | ||
isGlobal: true, | ||
cache: true, | ||
envFilePath: [ | ||
join( | ||
__dirname, | ||
`../../../../shared/config/.env.${process.env.NODE_ENV}`, | ||
), | ||
join(__dirname, '../../../../shared/config/.env'), | ||
], | ||
}), | ||
], | ||
providers: [ConfigService, ApiConfigService], | ||
exports: [ApiConfigService, DatabaseModule], | ||
}) | ||
export class ApiConfigModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { join } from 'path'; | ||
|
||
@Injectable() | ||
export class ApiConfigService { | ||
constructor(private configService: ConfigService) {} | ||
|
||
/** | ||
* @note We could abstract this to a data layer access config specific class within database module, as well for other configs when the thing gets more complex. | ||
* we could also abstract the underlying engine type, which is now set in the main app module | ||
*/ | ||
getDatabaseConfig() { | ||
return { | ||
host: this.configService.get('DB_HOST'), | ||
port: this.configService.get('DB_PORT'), | ||
username: this.configService.get('DB_USERNAME'), | ||
password: this.configService.get('DB_PASSWORD'), | ||
database: this.configService.get('DB_NAME'), | ||
entities: [join(__dirname, '**', '*.entity.{ts,js}')], | ||
synchronize: true, | ||
ssl: this.isProduction() | ||
? { require: true, rejectUnauthorized: false } | ||
: false, | ||
}; | ||
} | ||
|
||
private isProduction(): boolean { | ||
return this.configService.get('NODE_ENV') === 'production'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { forwardRef, Module } from '@nestjs/common'; | ||
import { ApiConfigService } from '@api/modules/config/app-config.service'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { ApiConfigModule } from '@api/modules/config/app-config.module'; | ||
|
||
@Module({ | ||
imports: [ | ||
TypeOrmModule.forRootAsync({ | ||
imports: [forwardRef(() => ApiConfigModule)], | ||
|
||
useFactory: (config: ApiConfigService) => ({ | ||
...config.getDatabaseConfig(), | ||
type: 'postgres', | ||
}), | ||
inject: [ApiConfigService], | ||
}), | ||
], | ||
exports: [TypeOrmModule], | ||
}) | ||
export class DatabaseModule {} |