-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: health check * feat: init main.ts * feat: update readme * feat: add swagger * feat: add configuration * feat: add versioning * feat: connect orm * feat: add common entity * feat: add typeorm migration * feat: add user query * feat: add authenticate * feat: add typeorm custom repository * feat: login-by email * feat: create token * feat: return token when login * feat: add jwt auth guard * fix: unit test
- Loading branch information
Showing
59 changed files
with
2,275 additions
and
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
root = true | ||
[*] | ||
end_of_line = lf |
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,15 @@ | ||
SERVICE_HOST=0.0.0.0 | ||
SERVICE_PORT=3333 | ||
|
||
DB_PORT=localhost | ||
DB_PORT=5432 | ||
DB_USERNAME=admin | ||
DB_PASSWORD=admin | ||
DB_NAME=admin | ||
DB_LOGGING=true | ||
DB_SSL=false | ||
DB_AUTO_RUN_MIGRATIONS=true | ||
DB_AUTO_SYNC=false | ||
|
||
JWT_SECRET_KEY=top_secret | ||
JWT_EXPIRATION_TIME=7d |
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
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 |
---|---|---|
|
@@ -22,4 +22,6 @@ jobs: | |
|
||
- name: Check lint | ||
run: yarn lint | ||
|
||
|
||
- name: Run test | ||
run: yarn test |
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx --no -- commitlint --edit ${1} | ||
npx --no -- commitlint --edit |
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true, | ||
"printWidth": 120, | ||
"trailingComma": "all", | ||
"useTabs": false | ||
"semi": false, | ||
"singleQuote": true, | ||
"printWidth": 120, | ||
"trailingComma": "all", | ||
"useTabs": false, | ||
"endOfLine": "lf" | ||
} |
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
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,21 @@ | ||
version: '3.4' | ||
|
||
services: | ||
db: | ||
image: postgres:latest | ||
environment: | ||
- 'POSTGRES_USER=admin' | ||
- 'POSTGRES_PASSWORD=admin' | ||
volumes: | ||
- data:/var/lib/postgresql/data | ||
ports: | ||
- 5432:5432 | ||
restart: always | ||
networks: | ||
- db-network | ||
volumes: | ||
data: null | ||
|
||
networks: | ||
db-network: | ||
driver: bridge |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module.exports = { | ||
'./src/**/*.{js,jsx,ts,tsx,json,css,scss,md}': ['yarn format:write'], | ||
'./src/**/*.+(js|json|ts|tsx)': ['yarn lint:fix'], | ||
'./src/**/*.{json,css,scss,md}': ['yarn format:write'], | ||
'./src/**/*.+(ts|tsx)': ['yarn lint:fix'], | ||
} |
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
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 |
---|---|---|
@@ -1,22 +1,27 @@ | ||
import { ConfigModule } from '@nestjs/config' | ||
import { Test, TestingModule } from '@nestjs/testing' | ||
|
||
import { AppController } from './app.controller' | ||
import { AppService } from './app.service' | ||
import { appConfiguration } from './configurations/app.config' | ||
import { jwtConfiguration } from './configurations/jwt.config' | ||
import { typeormConfiguration } from './configurations/typeorm.config' | ||
|
||
describe('AppController', () => { | ||
let appController: AppController | ||
|
||
beforeEach(async () => { | ||
const app: TestingModule = await Test.createTestingModule({ | ||
controllers: [AppController], | ||
providers: [AppService], | ||
imports: [ConfigModule.forRoot({ load: [appConfiguration, typeormConfiguration, jwtConfiguration] })], | ||
providers: [], | ||
}).compile() | ||
|
||
appController = app.get<AppController>(AppController) | ||
}) | ||
|
||
describe('root', () => { | ||
it('should return "Hello World!"', () => { | ||
expect(appController.getHello()).toBe('Hello World!') | ||
it('should return version when health check', () => { | ||
expect(appController.healthCheck().version).toMatch(/^v(\d+).(\d+).(\d+)$/g) | ||
}) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import { Controller, Get } from '@nestjs/common' | ||
import { AppService } from './app.service' | ||
import { ConfigService } from '@nestjs/config' | ||
import { ApiTags } from '@nestjs/swagger' | ||
|
||
import { AppConfiguration } from './configurations/app.config' | ||
|
||
@Controller() | ||
@ApiTags('app') | ||
export class AppController { | ||
constructor(private readonly appService: AppService) {} | ||
constructor(private readonly configService: ConfigService) {} | ||
|
||
@Get() | ||
getHello(): string { | ||
return this.appService.getHello() | ||
@Get('/healthz') | ||
healthCheck() { | ||
const { version } = this.configService.get<AppConfiguration>('app') | ||
return { | ||
version: `v${version}`, | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,30 @@ | ||
import { UserModule } from '@modules/users/user.module' | ||
import { Module } from '@nestjs/common' | ||
import { ConfigModule, ConfigService } from '@nestjs/config' | ||
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm' | ||
|
||
import { AppController } from './app.controller' | ||
import { AppService } from './app.service' | ||
import { appConfiguration } from './configurations/app.config' | ||
import { jwtConfiguration } from './configurations/jwt.config' | ||
import { typeormConfiguration } from './configurations/typeorm.config' | ||
import { AuthModule } from './modules/auth/auth.module' | ||
|
||
const appModules = [AuthModule, UserModule] | ||
|
||
@Module({ | ||
imports: [], | ||
imports: [ | ||
ConfigModule.forRoot({ | ||
ignoreEnvFile: process.env.NODE_ENV === 'production', | ||
load: [appConfiguration, typeormConfiguration, jwtConfiguration], | ||
isGlobal: true, | ||
}), | ||
TypeOrmModule.forRootAsync({ | ||
inject: [ConfigService], | ||
useFactory: (configService: ConfigService) => configService.get<TypeOrmModuleOptions>('orm'), | ||
}), | ||
...appModules, | ||
], | ||
controllers: [AppController], | ||
providers: [AppService], | ||
providers: [], | ||
}) | ||
export class AppModule {} |
This file was deleted.
Oops, something went wrong.
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,8 @@ | ||
import { PrimaryGeneratedColumn } from 'typeorm' | ||
|
||
import { BaseEntity } from './base.entity' | ||
|
||
export class AbstractEntity extends BaseEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number | ||
} |
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,12 @@ | ||
import { AggregateRoot } from '@nestjs/cqrs' | ||
import { CreateDateColumn, DeleteDateColumn, UpdateDateColumn } from 'typeorm' | ||
export class BaseEntity extends AggregateRoot { | ||
@CreateDateColumn({ type: 'timestamp with time zone' }) | ||
createdAt: Date | ||
|
||
@UpdateDateColumn({ type: 'timestamp with time zone' }) | ||
updatedAt: Date | ||
|
||
@DeleteDateColumn({ type: 'timestamp with time zone', nullable: true }) | ||
deletedAt?: Date | ||
} |
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,15 @@ | ||
import { registerAs } from '@nestjs/config' | ||
|
||
export interface AppConfiguration { | ||
readonly host: string | ||
readonly port: number | ||
readonly version: string | ||
} | ||
|
||
export const appConfiguration = registerAs<AppConfiguration>('app', () => { | ||
return { | ||
host: process.env.SERVICE_HOST || '0.0.0.0', | ||
port: +process.env.SERVICE_PORT || 3000, | ||
version: process.env.SERVICE_VERSION || process.env.npm_package_version || '0.0.0', | ||
} | ||
}) |
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 { registerAs } from '@nestjs/config' | ||
import { JwtModuleOptions } from '@nestjs/jwt' | ||
|
||
export const jwtConfiguration = registerAs<JwtModuleOptions>('jwt', () => ({ | ||
secret: process.env.JWT_SECRET_KEY || 'secret', | ||
signOptions: { | ||
expiresIn: process.env.JWT_EXPIRATION_TIME || '7d', | ||
}, | ||
})) |
Oops, something went wrong.