Files
yara724api/src/system-settings/system-settings.controller.ts
SepehrYahyaee a7fe04c032 YARA-986
2026-07-11 17:51:14 +03:30

52 lines
1.8 KiB
TypeScript

import { Body, Controller, Get, Patch, UseGuards } from "@nestjs/common";
import {
ApiBearerAuth,
ApiOperation,
ApiResponse,
ApiTags,
} from "@nestjs/swagger";
import { SettingsJwtGuard } from "src/auth/guards/settings-jwt.guard";
import { RolesGuard } from "src/auth/guards/role.guard";
import { Roles } from "src/decorators/roles.decorator";
import { RoleEnum } from "src/Types&Enums/role.enum";
import {
SystemSettingsResponseDto,
UpdateSystemSettingsDto,
} from "./dto/system-settings.dto";
import { SystemSettingsService } from "./system-settings.service";
@ApiTags("system-settings")
@ApiBearerAuth()
@Controller("system-settings")
export class SystemSettingsController {
constructor(private readonly systemSettingsService: SystemSettingsService) {}
@Get()
@UseGuards(SettingsJwtGuard, RolesGuard)
@Roles(RoleEnum.ADMIN, RoleEnum.COMPANY, RoleEnum.SUPER_ADMIN)
@ApiOperation({
summary: "Get global system settings (external API toggles)",
description:
"Shows whether SandHub/Tejarat live HTTP is enabled. When disabled, the API uses mocks so flows continue without external connectivity.",
})
@ApiResponse({ status: 200, type: SystemSettingsResponseDto })
getSettings(): Promise<SystemSettingsResponseDto> {
return this.systemSettingsService.getSettingsView();
}
@Patch()
@UseGuards(SettingsJwtGuard, RolesGuard)
@Roles(RoleEnum.ADMIN, RoleEnum.SUPER_ADMIN)
@ApiOperation({
summary: "Update global system settings",
description:
"Set `externalApis.sandHubUseLiveApi` to true for live inquiries, false for mock/offline mode.",
})
@ApiResponse({ status: 200, type: SystemSettingsResponseDto })
updateSettings(
@Body() body: UpdateSystemSettingsDto,
): Promise<SystemSettingsResponseDto> {
return this.systemSettingsService.updateSettings(body);
}
}