forked from mtusi2026/mtusi2026lab2
37 lines
835 B
TypeScript
37 lines
835 B
TypeScript
import { Controller, Get, HttpStatus } from '@nestjs/common';
|
|
import { AppService } from './app.service';
|
|
import { PrismaService } from './prisma/prisma.service';
|
|
import { ApiException } from './common/exceptions/api.exception';
|
|
|
|
@Controller()
|
|
export class AppController {
|
|
constructor(
|
|
private readonly appService: AppService,
|
|
private readonly prisma: PrismaService,
|
|
) {}
|
|
|
|
@Get()
|
|
getHello(): string {
|
|
return this.appService.getHello();
|
|
}
|
|
|
|
@Get('health/live')
|
|
live() {
|
|
return { status: 'ok' };
|
|
}
|
|
|
|
@Get('health/ready')
|
|
async ready() {
|
|
try {
|
|
await this.prisma.$queryRaw`SELECT 1`;
|
|
} catch {
|
|
throw new ApiException(
|
|
HttpStatus.SERVICE_UNAVAILABLE,
|
|
'unavailable',
|
|
'База данных недоступна',
|
|
);
|
|
}
|
|
return { status: 'ok' };
|
|
}
|
|
}
|