mirror of
http://172.20.10.11:3000/gitadmin/INSIGHT-MVP.git
synced 2026-06-25 01:56:39 +02:00
Eigenstaendiger NestJS-Service unter packages/crm-service/ mit: - Prisma Schema (app_crm): Contact, Activity, Pipeline, PipelineStage, Deal - JWT RS256 Auth mit shared Public Key und Token-Revocation - Multi-Tenancy: TenantGuard + tenantId-Filter auf allen Queries - CRUD-Module: Contacts, Activities, Pipelines, Deals - Docker-Integration: docker-compose.crm.yml (Port 3100, Traefik-Route /api/v1/crm) - Health-Check, Swagger, GlobalExceptionFilter, Pagination Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
74 lines
1.8 KiB
TypeScript
74 lines
1.8 KiB
TypeScript
import { Controller, Get } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation } from '@nestjs/swagger';
|
|
import { Public } from '../common/decorators/public.decorator';
|
|
import { CrmPrismaService } from '../prisma/crm-prisma.service';
|
|
import { RedisService } from '../redis/redis.service';
|
|
|
|
interface HealthResponse {
|
|
status: 'ok' | 'error';
|
|
service: string;
|
|
timestamp: string;
|
|
version: string;
|
|
services: {
|
|
database: 'up' | 'down';
|
|
redis: 'up' | 'down';
|
|
};
|
|
}
|
|
|
|
@ApiTags('Health')
|
|
@Controller('health')
|
|
export class HealthController {
|
|
constructor(
|
|
private readonly prisma: CrmPrismaService,
|
|
private readonly redis: RedisService,
|
|
) {}
|
|
|
|
@Get()
|
|
@Public()
|
|
@ApiOperation({ summary: 'Health-Check fuer CRM-Service' })
|
|
async check(): Promise<HealthResponse> {
|
|
const [dbStatus, redisStatus] = await Promise.allSettled([
|
|
this.checkDatabase(),
|
|
this.checkRedis(),
|
|
]);
|
|
|
|
const allUp =
|
|
dbStatus.status === 'fulfilled' &&
|
|
dbStatus.value &&
|
|
redisStatus.status === 'fulfilled' &&
|
|
redisStatus.value;
|
|
|
|
return {
|
|
status: allUp ? 'ok' : 'error',
|
|
service: 'crm-service',
|
|
timestamp: new Date().toISOString(),
|
|
version: '0.1.0',
|
|
services: {
|
|
database:
|
|
dbStatus.status === 'fulfilled' && dbStatus.value ? 'up' : 'down',
|
|
redis:
|
|
redisStatus.status === 'fulfilled' && redisStatus.value
|
|
? 'up'
|
|
: 'down',
|
|
},
|
|
};
|
|
}
|
|
|
|
private async checkDatabase(): Promise<boolean> {
|
|
try {
|
|
await this.prisma.$queryRaw`SELECT 1`;
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private async checkRedis(): Promise<boolean> {
|
|
try {
|
|
const pong = await this.redis.ping();
|
|
return pong === 'PONG';
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
}
|