Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@nestjs/axios": "^3.1.3",
"@nestjs/common": "^10.4.15",
"@nestjs/core": "^10.4.15",
"@nestjs/terminus": "^10.2.3",
"@nestjs/platform-express": "^10.4.15",
"@nestjs/swagger": "^8.1.0",
"@nestjs/typeorm": "^10.0.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { applyDecorators, Type } from '@nestjs/common';
import { ApiBadRequestResponse, ApiInternalServerErrorResponse, ApiNotFoundResponse, ApiOkResponse, ApiOperation, ApiUnauthorizedResponse } from '@nestjs/swagger';
import { ErrorResponse } from '@application/web/response/error/error.response';

export function ApiDocGenericGet(value: string, modelType: Type) {
return applyDecorators(
ApiOperation({ summary: `Return the ${value}.` }),
ApiOkResponse({
description: `Data from ${value} requested.`,
type: modelType,
}),
ApiBadRequestResponse({ description: 'Bad request.', type: ErrorResponse }),
ApiUnauthorizedResponse({ description: 'Unauthorized.', type: ErrorResponse }),
ApiNotFoundResponse({ description: 'Resource not found.', type: ErrorResponse }),
ApiInternalServerErrorResponse({ description: 'Internal server error.', type: ErrorResponse }),
);
}
1 change: 1 addition & 0 deletions app/src/application/web/config/swagger/decorators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './api-doc-generic-delete.decorator';
export * from './api-doc-generic-get-all.decorator';
export * from './api-doc-generic-get-one.decorator';
export * from './api-doc-generic-get-pagination.decorator';
export * from './api-doc-generic-get.decorator';
export * from './api-doc-generic-patch.decorator';
export * from './api-doc-generic-post.decorator';
export * from './api-doc-generic-put.decorator';
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Module } from '@nestjs/common';
import { HealthController } from '@application/web/controllers/health/health.controller';
import { TerminusModule } from '@nestjs/terminus';

@Module({
imports: [TerminusModule],
controllers: [HealthController],
})
export class HealthAppModule {}
36 changes: 21 additions & 15 deletions app/src/application/web/controllers/health/health.controller.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import { Controller, Get, HttpCode } from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ErrorResponse } from '@application/web/response/error/error.response';
import { ApiTags } from '@nestjs/swagger';
import { HealthCheck, HealthCheckService, TypeOrmHealthIndicator } from '@nestjs/terminus';
import { ApiDocGenericGet } from '@application/web/config/swagger/decorators';
import { HealthCheckResultResponse } from '@application/web/response/health';
import { HealthCheckResultMapper } from '@application/web/mappers/health/health.check.result.mapper';

@ApiTags('Health')
@ApiResponse({
status: 500,
description: 'Internal server error',
type: ErrorResponse,
})
@Controller('/health')
@Controller('health')
export class HealthController {
constructor(
private readonly healthCheckService: HealthCheckService,
private readonly dbHealthIndicator: TypeOrmHealthIndicator,
) {}

@Get()
@HttpCode(200)
@ApiOkResponse({ description: 'Health was successful.', type: String })
@ApiOperation({
summary: 'Returns the health of the API.',
description: 'Returns the health of the API.',
})
getHealth(): string {
return 'OK';
@ApiDocGenericGet('health', HealthCheckResultResponse)
@HealthCheck()
async check(): Promise<HealthCheckResultResponse> {
const healthCheckResult = await this.healthCheckService.check([async () => this.dbHealthIndicator.pingCheck('database', { timeout: 3000 })]);
const info = { ...healthCheckResult.info };
info['application'] = {
status: 'up',
uptime: process.uptime(),
};
return HealthCheckResultMapper.toApi({ ...healthCheckResult, info: info });
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { HealthCheckResultResponse } from '@application/web/response/health';
import { HealthCheckResult } from '@nestjs/terminus';

export class HealthCheckResultMapper {
public static toApi(healthCheckResult: HealthCheckResult): HealthCheckResultResponse {
return {
status: healthCheckResult.status,
info: healthCheckResult.info,
error: healthCheckResult.error,
details: healthCheckResult.details,
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ApiProperty } from '@nestjs/swagger';
import type { HealthIndicatorResult } from '@nestjs/terminus/dist/health-indicator';
import { HealthCheckStatus } from '@nestjs/terminus/dist/health-check/health-check-result.interface';

export class HealthCheckResultResponse {
@ApiProperty({
description: 'Health check show status.',
example: 'ok',
})
status: HealthCheckStatus;

@ApiProperty({
description: 'Health check show information.',
example: {
database: {
status: 'up',
},
},
})
info?: HealthIndicatorResult;

@ApiProperty({
description: 'Health check show error.',
example: {
error: {},
},
})
error?: HealthIndicatorResult;

@ApiProperty({
description: 'Health check show details.',
example: {
database: {
status: 'up',
},
},
})
details: HealthIndicatorResult;
}
1 change: 1 addition & 0 deletions app/src/application/web/response/health/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './health.check.result.response';
53 changes: 52 additions & 1 deletion app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,14 @@
path-to-regexp "3.3.0"
swagger-ui-dist "5.18.2"

"@nestjs/terminus@^10.2.3":
version "10.2.3"
resolved "https://registry.yarnpkg.com/@nestjs/terminus/-/terminus-10.2.3.tgz#72c8a66d04df52aeaae807551245480fd7239a75"
integrity sha512-iX7gXtAooePcyQqFt57aDke5MzgdkBeYgF5YsFNNFwOiAFdIQEhfv3PR0G+HlH9F6D7nBCDZt9U87Pks/qHijg==
dependencies:
boxen "5.1.2"
check-disk-space "3.4.0"

"@nestjs/testing@^10.4.15":
version "10.4.15"
resolved "https://registry.yarnpkg.com/@nestjs/testing/-/testing-10.4.15.tgz#4c9fe17bf026c0142040cbe3db464c526f89d36a"
Expand Down Expand Up @@ -2358,6 +2366,13 @@ ajv@^8.0.0, ajv@^8.9.0:
json-schema-traverse "^1.0.0"
require-from-string "^2.0.2"

ansi-align@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-3.0.1.tgz#0cdf12e111ace773a86e9a1fad1225c43cb19a59"
integrity sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w==
dependencies:
string-width "^4.1.0"

ansi-colors@4.1.3:
version "4.1.3"
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.3.tgz#37611340eb2243e70cc604cad35d63270d48781b"
Expand Down Expand Up @@ -2601,6 +2616,20 @@ bowser@^2.11.0:
resolved "https://registry.yarnpkg.com/bowser/-/bowser-2.11.0.tgz#5ca3c35757a7aa5771500c70a73a9f91ef420a8f"
integrity sha512-AlcaJBi/pqqJBIQ8U9Mcpc9i8Aqxn88Skv5d+xBX006BY5u8N3mGLHa5Lgppa7L/HfwgwLgZ6NYs+Ag6uUmJRA==

boxen@5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/boxen/-/boxen-5.1.2.tgz#788cb686fc83c1f486dfa8a40c68fc2b831d2b50"
integrity sha512-9gYgQKXx+1nP8mP7CzFyaUARhg7D3n1dF/FnErWmu9l6JvGpNUN278h0aSb+QjoiKSWG+iZ3uHrcqk0qrY9RQQ==
dependencies:
ansi-align "^3.0.0"
camelcase "^6.2.0"
chalk "^4.1.0"
cli-boxes "^2.2.1"
string-width "^4.2.2"
type-fest "^0.20.2"
widest-line "^3.1.0"
wrap-ansi "^7.0.0"

brace-expansion@^1.1.7:
version "1.1.11"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
Expand Down Expand Up @@ -2778,6 +2807,11 @@ chardet@^0.7.0:
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==

check-disk-space@3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/check-disk-space/-/check-disk-space-3.4.0.tgz#eb8e69eee7a378fd12e35281b8123a8b4c4a8ff7"
integrity sha512-drVkSqfwA+TvuEhFipiR1OC9boEGZL5RrWvVsOthdcvQNXyCCuKkEiTOTXZ7qxSf/GLwq4GvzfrQD/Wz325hgw==

chokidar@3.6.0, chokidar@^3.5.3:
version "3.6.0"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.6.0.tgz#197c6cc669ef2a8dc5e7b4d97ee4e092c3eb0d5b"
Expand Down Expand Up @@ -2837,6 +2871,11 @@ clean-stack@^2.0.0:
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
integrity sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==

cli-boxes@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-2.2.1.tgz#ddd5035d25094fce220e9cab40a45840a440318f"
integrity sha512-y4coMcylgSCdVinjiDBuR8PCC2bLjyGTwEmPb9NHR/QaNU6EUOXcTY/s6VjGMD6ENSEaeQYHCY0GNGS5jfMwPw==

cli-cursor@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-3.1.0.tgz#264305a7ae490d1d03bf0c9ba7c925d1753af307"
Expand Down Expand Up @@ -6107,7 +6146,7 @@ string-length@^4.0.1:
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -6473,6 +6512,11 @@ type-detect@4.0.8:
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==

type-fest@^0.20.2:
version "0.20.2"
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.20.2.tgz#1bf207f4b28f91583666cb5fbd327887301cd5f4"
integrity sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==

type-fest@^0.21.3:
version "0.21.3"
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37"
Expand Down Expand Up @@ -6713,6 +6757,13 @@ wide-align@^1.1.5:
dependencies:
string-width "^1.0.2 || 2 || 3 || 4"

widest-line@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/widest-line/-/widest-line-3.1.0.tgz#8292333bbf66cb45ff0de1603b136b7ae1496eca"
integrity sha512-NsmoXalsWVDMGupxZ5R08ka9flZjjiLvHVAWYOKtiKM8ujtZWr9cRffak+uSE48+Ob8ObalXpwyeUiyDD6QFgg==
dependencies:
string-width "^4.0.0"

word-wrap@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34"
Expand Down
Loading