Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: userController [ISSUE-1,9,65] #66

Merged
merged 4 commits into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions server/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NODE_ENV=dev
PORT=3000
24 changes: 24 additions & 0 deletions server/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3.3'

services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: de-labtory
MYSQL_USER: de-labtory
MYSQL_PASSWORD: de-labtory
MYSQL_DATABASE: hatchout
volumes:
- data:/var/lib/mysql
container_name: typeorm-mysql
ports:
- 3306:3306
adminer:
image: adminer
restart: always
ports:
- 8080:8080
volumes:
data:
2 changes: 2 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"class-validator": "^0.9.1",
"nestjs-config": "^1.4.0",
"nestjs-typeorm-paginate": "^0.1.7",
"pg": "^7.11.0",
"reflect-metadata": "^0.1.12",
"rimraf": "^2.6.2",
"rxjs": "^6.3.3",
Expand All @@ -39,6 +40,7 @@
"@types/jest": "^23.3.13",
"@types/node": "^10.12.18",
"@types/supertest": "^2.0.7",
"assert": "^2.0.0",
"husky": "^2.3.0",
"jest": "^23.6.0",
"jest-plugin-context": "^2.9.0",
Expand Down
5 changes: 3 additions & 2 deletions server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigModule } from 'nestjs-config';
import { GhostService } from './app/ghost/ghost.service';
import { GhostModule } from './port/module/ghost.module';
import * as path from 'path';
import {UserModule} from './port/module/user.module';
import {DatabaseModule} from './port/module/database.module';

@Module({
imports: [
ConfigModule.load(path.resolve(__dirname, 'config', '**/!(*.d).{ts,js}')),
GhostModule,
UserModule,
DatabaseModule,
],
controllers: [AppController],
providers: [AppService, GhostService],
providers: [AppService],
})
export class AppModule {}
12 changes: 12 additions & 0 deletions server/src/config/database/dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
type: 'mysql',
host: 'localhost',
port: 3306,
username: 'de-labtory',
password: 'de-labtory',
database: 'hatchout',
logging: false,
synchronize: true,
entities: ['src/domain/**/*.entity{.ts,.js}'],
dropSchema: false,
};
12 changes: 12 additions & 0 deletions server/src/config/database/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'test',
password: 'test',
database: 'hatchout',
logging: false,
synchronize: true,
entities: ['src/domain/**/*.entity{.ts,.js}'],
dropSchema: true,
};
20 changes: 20 additions & 0 deletions server/src/port/module/database.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {Module} from '@nestjs/common';
import {TypeOrmModule} from '@nestjs/typeorm';
import {RepositoryConfigService} from '../persistence/repository/repository.config.service';
import {UserRepository} from '../persistence/repository/user.repository.impl';
import {GhostRepository} from '../persistence/repository/ghost.repository.impl';
import {TransactionRepository} from '../persistence/repository/transaction.repository.impl';

@Module({
imports: [
TypeOrmModule.forRootAsync({
useClass: RepositoryConfigService,
}),
TypeOrmModule.forFeature([
UserRepository,
GhostRepository,
TransactionRepository,
]),
],
})
export class DatabaseModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {Test, TestingModule} from '@nestjs/testing';
import {ConfigModule, ConfigService} from 'nestjs-config';
import * as path from 'path';
import {RepositoryConfigService} from './repository.config.service';

describe('RepositoryConfig', () => {
let configService: RepositoryConfigService;
let config: ConfigService;

beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.load(path.resolve(__dirname + '/test', 'config', '**/!(*.d).{ts,js}')),
],
providers: [
RepositoryConfigService,
],
}).compile();

configService = module.get<RepositoryConfigService>(RepositoryConfigService);
config = module.get<ConfigService>(ConfigService);
});

describe('#createTypeOrmOptions()', () => {
it('should return option', () => {

const options = configService.createTypeOrmOptions();

expect(options).toEqual(config.get(process.env.NODE_ENV));
});

});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {InjectConfig} from 'nestjs-config';
import {Injectable} from '@nestjs/common';
import {TypeOrmModuleOptions, TypeOrmOptionsFactory} from '@nestjs/typeorm';

@Injectable()
export class RepositoryConfigService implements TypeOrmOptionsFactory {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you implement TypeOrmOptionsFactory, should you name RepositoryConfigFactory?

Why does RepositoryConfigService implement TypeOrmOptionsFactory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it make sense ur comment but I think name repositoryconfihservice is better

  1. We are using "service" at all the other place. i used service for consistency.
  2. other references are using name "service" at the same usage like ConfigService.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see!

I understand your mind. Thank you :)

constructor(@InjectConfig() private config) {
this.config = config.get(process.env.NODE_ENV);
}

createTypeOrmOptions(): TypeOrmModuleOptions {
return {
type: this.config.type,
host: this.config.host,
logging: this.config.logging,
port: this.config.port,
username: this.config.username,
password: this.config.password,
database: this.config.database,
synchronize: this.config.synchronize,
dropSchema: this.config.dropSchema,
entities: this.config.entities,
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default {
type: 'postgres',
host: 'localhost',
logging: true,
port: 5432,
username: 'de-labtory',
password: 'de-labtory',
database: 'hatchout-test',
synchronize: true,
entities: ['src/domain/**/*.entity{.ts,.js}'],
};