Skip to content

Commit fabde74

Browse files
committed
implement configService throughout the app
1 parent 5b117fa commit fabde74

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/database/database.providers.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
import { Sequelize } from 'sequelize-typescript';
22
import { User } from './../users/user.entity';
3+
import { ConfigService } from './../shared/config/config.service';
34

45
export const databaseProviders = [
56
{
67
provide: 'SEQUELIZE',
7-
useFactory: async () => {
8-
const sequelize = new Sequelize({
9-
dialect: 'postgres',
10-
host: 'localhost',
11-
port: 5432,
12-
username: 'postgres',
13-
password: 'postgres',
14-
database: 'nest',
15-
});
8+
useFactory: async (configService: ConfigService) => {
9+
const sequelize = new Sequelize(configService.sequelizeOrmConfig);
1610
sequelize.addModels([User]);
1711
await sequelize.sync();
1812
return sequelize;
1913
},
14+
inject: [ConfigService],
2015
},
2116
];

src/users/users.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { UserLoginResponseDto } from './dto/user-login-response.dto';
88
import { JwtPayload } from './auth/jwt-payload.model';
99
import { sign } from 'jsonwebtoken';
1010
import { UpdateUserDto } from './dto/update-user.dto';
11+
import { ConfigService } from './../shared/config/config.service';
1112

1213
@Injectable()
1314
export class UsersService {
@@ -16,8 +17,9 @@ export class UsersService {
1617
constructor(
1718
@Inject('UsersRepository')
1819
private readonly usersRepository: typeof User,
20+
private readonly configService: ConfigService,
1921
) {
20-
this.jwtPrivateKey = 'jwtPrivateKey';
22+
this.jwtPrivateKey = this.configService.jwtConfig.privateKey;
2123
}
2224

2325
async findAll(): Promise<UserDto[]> {

0 commit comments

Comments
 (0)