39 lines
885 B
TypeScript
39 lines
885 B
TypeScript
|
|
import { Injectable } from '@nestjs/common';
|
||
|
|
import { ConfigService } from '@nestjs/config';
|
||
|
|
import { PrismaService } from './prisma';
|
||
|
|
|
||
|
|
@Injectable()
|
||
|
|
export class AppService {
|
||
|
|
constructor(
|
||
|
|
private readonly configService: ConfigService,
|
||
|
|
private readonly prisma: PrismaService,
|
||
|
|
) {}
|
||
|
|
|
||
|
|
getHello(): string {
|
||
|
|
return 'Real Estate Agent Platform API v1.0';
|
||
|
|
}
|
||
|
|
|
||
|
|
async getHealth() {
|
||
|
|
const dbHealthy = await this.checkDatabaseHealth();
|
||
|
|
|
||
|
|
return {
|
||
|
|
status: 'ok',
|
||
|
|
timestamp: new Date().toISOString(),
|
||
|
|
environment: this.configService.get<string>('app.env'),
|
||
|
|
version: '1.0.0',
|
||
|
|
services: {
|
||
|
|
database: dbHealthy ? 'healthy' : 'unhealthy',
|
||
|
|
},
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
private async checkDatabaseHealth(): Promise<boolean> {
|
||
|
|
try {
|
||
|
|
await this.prisma.$queryRaw`SELECT 1`;
|
||
|
|
return true;
|
||
|
|
} catch {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|