Add health check and retry logic and circuit breaker

This commit is contained in:
SepehrYahyaee
2026-09-28 17:01:53 +03:30
parent 22371f4a03
commit 03fa5e0f20
67 changed files with 3101 additions and 410 deletions
+37 -4
View File
@@ -1,9 +1,15 @@
import { Controller, Get, Query, UseGuards } from '@nestjs/common';
import { Controller, Delete, Get, Query, Req, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { Request } from 'express';
import { AuditEvent } from '../common/enums/audit-event.enum';
import { AppException } from '../common/exceptions/app-exception';
import { AuditService } from '../audit/audit.service';
import { CurrentUser } from '../auth/decorators/current-user.decorator';
import { AuthenticatedUser } from '../auth/interfaces/authenticated-user.interface';
import { Roles } from '../auth/decorators/roles.decorator';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { RolesGuard } from '../auth/guards/roles.guard';
import { ADMIN_ROLES } from '../common/enums/role.enum';
import { Role } from '../common/enums/role.enum';
import { InquiryLogQueryDto, InquiryLogTimelineQueryDto } from './dto/inquiry-log-query.dto';
import { InquiryLogService } from './inquiry-log.service';
@@ -11,9 +17,36 @@ import { InquiryLogService } from './inquiry-log.service';
@ApiBearerAuth()
@Controller('inquiry-logs')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(...ADMIN_ROLES)
// Inquiry logs contain operational and potentially sensitive provider payloads.
// Keep the dashboard data restricted to the seeded/managed SUPER_ADMIN role.
@Roles(Role.SUPER_ADMIN)
export class InquiryLogsController {
constructor(private readonly inquiryLogService: InquiryLogService) {}
constructor(
private readonly inquiryLogService: InquiryLogService,
private readonly auditService: AuditService,
) {}
@Delete()
@ApiOperation({ summary: 'Delete all inquiry request logs (explicitly enabled local maintenance action)' })
async purgeAll(
@CurrentUser() user: AuthenticatedUser,
@Req() request: Request,
): Promise<{ deletedCount: number }> {
if (process.env.INQUIRY_LOG_PURGE_ENABLED !== 'true') {
throw new AppException('INQUIRY_LOG_PURGE_DISABLED');
}
const result = await this.inquiryLogService.purgeAll();
await this.auditService.log(AuditEvent.INQUIRY_LOGS_PURGED, {
userId: user.id,
username: user.username,
ip: request.ip,
userAgent: request.headers['user-agent'],
metadata: { deletedCount: result.deletedCount },
});
return result;
}
@Get()
@ApiOperation({ summary: 'Search inquiry request logs' })