Skip to content

Commit 3486d74

Browse files
committed
fix import in health module to use token inject
1 parent ef0f195 commit 3486d74

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/common/common.module.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import { Module } from '@nestjs/common'
2-
import { ConnOptionsService } from './conn-options.service'
2+
import { ConnOptionsService, TOKEN } from './conn-options.service'
33

4+
export const TOKENS = {
5+
CONN_OPTIONS_SERVICE: TOKEN,
6+
}
47
@Module({
5-
providers: [ConnOptionsService],
8+
providers: [
9+
{
10+
provide: TOKENS.CONN_OPTIONS_SERVICE,
11+
useClass: ConnOptionsService,
12+
},
13+
],
614
exports: [
715
{
8-
provide: 'CONN_OPTIONS_SERVICE',
16+
provide: TOKENS.CONN_OPTIONS_SERVICE,
917
useClass: ConnOptionsService,
1018
},
1119
],

src/common/conn-options.service.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { RedisOptions, Transport } from '@nestjs/microservices'
33
import { MicroserviceHealthIndicatorOptions } from '@nestjs/terminus'
44
import { config } from 'dotenv'
55

6+
export const TOKEN = 'CONN_OPTIONS_SERVICE'
67
// ensure process.env is hydrated
78
config({
89
// items in .env take precedence

src/health/health.controller.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { Controller, Get } from '@nestjs/common'
1+
import { Controller, Get, Inject } from '@nestjs/common'
22
import {
33
HealthCheckService,
44
MemoryHealthIndicator,
55
HealthCheck,
66
MicroserviceHealthIndicator,
77
} from '@nestjs/terminus'
8-
import { ConnOptionsService } from '../common/conn-options.service'
8+
import { IConnOptionsService, TOKEN } from '../common/conn-options.service'
99

1010
@Controller('health')
1111
export class HealthController {
1212
private readonly health: HealthCheckService
1313
private readonly memory: MemoryHealthIndicator
1414
private readonly microservice: MicroserviceHealthIndicator
15-
private readonly connOptions: ConnOptionsService
15+
private readonly connOptions: IConnOptionsService
1616

1717
constructor(
1818
health: HealthCheckService,
1919
memory: MemoryHealthIndicator,
2020
microservice: MicroserviceHealthIndicator,
21-
connOptions: ConnOptionsService
21+
@Inject(TOKEN) connOptions: IConnOptionsService
2222
) {
2323
this.health = health
2424
this.memory = memory

0 commit comments

Comments
 (0)