@jrosadob/nestjs-sophia-framework
Version:
Franework para microservicios en NestJS
61 lines • 2.96 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HealthController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const typeorm_1 = require("typeorm");
const database_1 = require("../database");
let HealthController = class HealthController {
constructor(dataSource) {
this.dataSource = dataSource;
}
liveness() {
return { status: 'ok' };
}
async readiness() {
try {
await this.dataSource.query('SELECT 1');
return { status: 'ok' };
}
catch (error) {
throw new common_1.HttpException({ status: 'error', message: 'Database connection failed' }, common_1.HttpStatus.SERVICE_UNAVAILABLE);
}
}
};
exports.HealthController = HealthController;
__decorate([
(0, common_1.Get)('liveness'),
(0, swagger_1.ApiOperation)({ summary: 'Enpoint liveness for Kubernetes' }),
(0, swagger_1.ApiResponse)({ status: 200, description: 'Ok' }),
(0, swagger_1.ApiResponse)({ status: 500, description: 'Internal server error' }),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], HealthController.prototype, "liveness", null);
__decorate([
(0, common_1.Get)('readiness'),
(0, swagger_1.ApiOperation)({ summary: 'Enpoint readiness for Kubernetes' }),
(0, swagger_1.ApiResponse)({ status: 200, description: 'Ok' }),
(0, swagger_1.ApiResponse)({ status: 503, description: 'Service unaivalable' }),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], HealthController.prototype, "readiness", null);
exports.HealthController = HealthController = __decorate([
(0, common_1.Controller)('health'),
__param(0, (0, common_1.Inject)(database_1.Providers.DATA_SOURCE)),
__metadata("design:paramtypes", [typeorm_1.DataSource])
], HealthController);
//# sourceMappingURL=health.controller.js.map