Refactor code structure for improved readability and maintainability
Test Suite / test (24.15.0) (push) Has been cancelled

This commit is contained in:
Nils-Johan Gynther
2026-05-06 07:37:59 +02:00
parent e4f201ea36
commit 969dafdbc6
273 changed files with 11357 additions and 39 deletions
+8
View File
@@ -0,0 +1,8 @@
import { Response } from 'express';
import { HealthService } from './health.service';
export declare class HealthController {
private readonly healthService;
constructor(healthService: HealthService);
getHealth(res: Response): Promise<void>;
getDatabaseHealth(res: Response): Promise<void>;
}
+64
View File
@@ -0,0 +1,64 @@
"use strict";
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 health_service_1 = require("./health.service");
const public_decorator_1 = require("../auth/decorators/public.decorator");
let HealthController = class HealthController {
constructor(healthService) {
this.healthService = healthService;
}
async getHealth(res) {
const health = await this.healthService.getOverallHealth();
res.status(health.statusCode).json({
status: health.status,
service: health.service,
timestamp: health.timestamp,
uptime: health.uptime,
checks: health.checks,
});
}
async getDatabaseHealth(res) {
const dbHealth = await this.healthService.getDatabaseHealth();
res.status(dbHealth.statusCode).json({
status: dbHealth.status,
database: dbHealth.database,
responseTime: `${dbHealth.responseTime}ms`,
timestamp: dbHealth.timestamp,
details: dbHealth.details,
});
}
};
exports.HealthController = HealthController;
__decorate([
(0, common_1.Get)(),
__param(0, (0, common_1.Res)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], HealthController.prototype, "getHealth", null);
__decorate([
(0, common_1.Get)('db'),
__param(0, (0, common_1.Res)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], HealthController.prototype, "getDatabaseHealth", null);
exports.HealthController = HealthController = __decorate([
(0, public_decorator_1.Public)(),
(0, common_1.Controller)('health'),
__metadata("design:paramtypes", [health_service_1.HealthService])
], HealthController);
//# sourceMappingURL=health.controller.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"health.controller.js","sourceRoot":"","sources":["../../src/health/health.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAgE;AAEhE,qDAAiD;AACjD,0EAA6D;AAItD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;IAAG,CAAC;IAOvD,AAAN,KAAK,CAAC,SAAS,CAAQ,GAAa;QAClC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE,CAAC;QAC3D,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;YACjC,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC,CAAC;IACL,CAAC;IAOK,AAAN,KAAK,CAAC,iBAAiB,CAAQ,GAAa;QAC1C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,iBAAiB,EAAE,CAAC;QAC9D,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;YACnC,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,YAAY,EAAE,GAAG,QAAQ,CAAC,YAAY,IAAI;YAC1C,SAAS,EAAE,QAAQ,CAAC,SAAS;YAC7B,OAAO,EAAE,QAAQ,CAAC,OAAO;SAC1B,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAlCY,4CAAgB;AAQrB;IADL,IAAA,YAAG,GAAE;IACW,WAAA,IAAA,YAAG,GAAE,CAAA;;;;iDASrB;AAOK;IADL,IAAA,YAAG,EAAC,IAAI,CAAC;IACe,WAAA,IAAA,YAAG,GAAE,CAAA;;;;yDAS7B;2BAjCU,gBAAgB;IAF5B,IAAA,yBAAM,GAAE;IACR,IAAA,mBAAU,EAAC,QAAQ,CAAC;qCAEyB,8BAAa;GAD9C,gBAAgB,CAkC5B"}
+2
View File
@@ -0,0 +1,2 @@
export declare class HealthModule {
}
+24
View File
@@ -0,0 +1,24 @@
"use strict";
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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HealthModule = void 0;
const common_1 = require("@nestjs/common");
const health_controller_1 = require("./health.controller");
const health_service_1 = require("./health.service");
const prisma_module_1 = require("../prisma/prisma.module");
let HealthModule = class HealthModule {
};
exports.HealthModule = HealthModule;
exports.HealthModule = HealthModule = __decorate([
(0, common_1.Module)({
imports: [prisma_module_1.PrismaModule],
controllers: [health_controller_1.HealthController],
providers: [health_service_1.HealthService],
})
], HealthModule);
//# sourceMappingURL=health.module.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"health.module.js","sourceRoot":"","sources":["../../src/health/health.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,2DAAuD;AACvD,qDAAiD;AACjD,2DAAuD;AAOhD,IAAM,YAAY,GAAlB,MAAM,YAAY;CAAG,CAAA;AAAf,oCAAY;uBAAZ,YAAY;IALxB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,4BAAY,CAAC;QACvB,WAAW,EAAE,CAAC,oCAAgB,CAAC;QAC/B,SAAS,EAAE,CAAC,8BAAa,CAAC;KAC3B,CAAC;GACW,YAAY,CAAG"}
+41
View File
@@ -0,0 +1,41 @@
import { PrismaService } from '../prisma/prisma.service';
export interface HealthStatus {
status: 'healthy' | 'degraded' | 'unhealthy';
service: string;
timestamp: string;
uptime: number;
checks: {
database: {
status: 'ok' | 'error';
responseTime: number;
details?: string;
};
};
}
export declare class HealthService {
private readonly prisma;
private readonly startTime;
constructor(prisma: PrismaService);
getOverallHealth(): Promise<{
status: 'healthy' | 'degraded' | 'unhealthy';
statusCode: number;
service: string;
timestamp: string;
uptime: number;
checks: {
database: {
status: 'ok' | 'error';
responseTime: number;
details?: string;
};
};
}>;
getDatabaseHealth(): Promise<{
status: 'ok' | 'error';
database: string;
responseTime: number;
timestamp: string;
details?: string;
statusCode: number;
}>;
}
+89
View File
@@ -0,0 +1,89 @@
"use strict";
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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HealthService = void 0;
const common_1 = require("@nestjs/common");
const prisma_service_1 = require("../prisma/prisma.service");
let HealthService = class HealthService {
constructor(prisma) {
this.prisma = prisma;
this.startTime = Date.now();
}
async getOverallHealth() {
const timestamp = new Date().toISOString();
const uptime = Date.now() - this.startTime;
const dbStart = Date.now();
let dbStatus = 'ok';
let dbResponseTime = 0;
let dbDetails;
try {
await this.prisma.$queryRaw `SELECT 1`;
dbResponseTime = Date.now() - dbStart;
}
catch (error) {
dbStatus = 'error';
dbResponseTime = Date.now() - dbStart;
dbDetails = error instanceof Error ? error.message : 'Unknown database error';
}
let overallStatus = 'healthy';
if (dbStatus === 'error') {
overallStatus = 'unhealthy';
}
const statusCode = overallStatus === 'unhealthy' ? 503 : 200;
return {
status: overallStatus,
statusCode,
service: 'recipe-api',
timestamp,
uptime,
checks: {
database: {
status: dbStatus,
responseTime: dbResponseTime,
details: dbDetails,
},
},
};
}
async getDatabaseHealth() {
const timestamp = new Date().toISOString();
const startTime = Date.now();
try {
await this.prisma.$queryRaw `SELECT 1`;
const responseTime = Date.now() - startTime;
return {
status: 'ok',
database: 'connected',
responseTime,
timestamp,
statusCode: 200,
};
}
catch (error) {
const responseTime = Date.now() - startTime;
const details = error instanceof Error ? error.message : 'Unknown database error';
return {
status: 'error',
database: 'not reachable',
responseTime,
timestamp,
details,
statusCode: 503,
};
}
}
};
exports.HealthService = HealthService;
exports.HealthService = HealthService = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
], HealthService);
//# sourceMappingURL=health.service.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"health.service.js","sourceRoot":"","sources":["../../src/health/health.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,6DAAyD;AAiBlD,IAAM,aAAa,GAAnB,MAAM,aAAa;IAGxB,YAA6B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