forked from Yara724/api
added offline inquiry in system setting also fix some bugs
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Get, Patch, UseGuards } from "@nestjs/common";
|
||||
import { Body, Controller, Get, Patch, Post, UseGuards } from "@nestjs/common";
|
||||
import {
|
||||
ApiBearerAuth,
|
||||
ApiOperation,
|
||||
@@ -10,11 +10,23 @@ import { RolesGuard } from "src/auth/guards/role.guard";
|
||||
import { Roles } from "src/decorators/roles.decorator";
|
||||
import { RoleEnum } from "src/Types&Enums/role.enum";
|
||||
import {
|
||||
OfflineInquirySettingsViewDto,
|
||||
SystemSettingsResponseDto,
|
||||
UpdateOfflineInquirySettingsDto,
|
||||
UpdateSystemSettingsDto,
|
||||
} from "./dto/system-settings.dto";
|
||||
import { SystemSettingsService } from "./system-settings.service";
|
||||
|
||||
const EXPERT_AND_ADMIN_ROLES = [
|
||||
RoleEnum.ADMIN,
|
||||
RoleEnum.SUPER_ADMIN,
|
||||
RoleEnum.EXPERT,
|
||||
RoleEnum.DAMAGE_EXPERT,
|
||||
RoleEnum.FIELD_EXPERT,
|
||||
RoleEnum.FILE_MAKER,
|
||||
RoleEnum.FILE_REVIEWER,
|
||||
] as const;
|
||||
|
||||
@ApiTags("system-settings")
|
||||
@ApiBearerAuth()
|
||||
@Controller("system-settings")
|
||||
@@ -27,7 +39,7 @@ export class SystemSettingsController {
|
||||
@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.",
|
||||
"Shows whether SandHub/Tejarat live HTTP is enabled, and whether offline seeded inquiries are enabled.",
|
||||
})
|
||||
@ApiResponse({ status: 200, type: SystemSettingsResponseDto })
|
||||
getSettings(): Promise<SystemSettingsResponseDto> {
|
||||
@@ -40,7 +52,7 @@ export class SystemSettingsController {
|
||||
@ApiOperation({
|
||||
summary: "Update global system settings",
|
||||
description:
|
||||
"Set `externalApis.sandHubUseLiveApi` to true for live inquiries, false for mock/offline mode.",
|
||||
"Set `externalApis.sandHubUseLiveApi` and/or `offlineInquiry.enabled`.",
|
||||
})
|
||||
@ApiResponse({ status: 200, type: SystemSettingsResponseDto })
|
||||
updateSettings(
|
||||
@@ -48,4 +60,55 @@ export class SystemSettingsController {
|
||||
): Promise<SystemSettingsResponseDto> {
|
||||
return this.systemSettingsService.updateSettings(body);
|
||||
}
|
||||
|
||||
@Post("fanavaran-config/reload")
|
||||
@UseGuards(SettingsJwtGuard, RolesGuard)
|
||||
@Roles(...EXPERT_AND_ADMIN_ROLES)
|
||||
@ApiOperation({
|
||||
summary: "Reload Fanavaran client config cache from Mongo",
|
||||
description:
|
||||
"Re-reads `fanavaranClientConfigs` into the runtime profile cache. If auth fields changed, cached Fanavaran tokens are invalidated so the next call re-logins. Allowed for admin and expert roles.",
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: "Cache reloaded",
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
ok: { type: "boolean", example: true },
|
||||
message: { type: "string" },
|
||||
},
|
||||
},
|
||||
})
|
||||
reloadFanavaranConfigCache(): Promise<{ ok: true; message: string }> {
|
||||
return this.systemSettingsService.reloadFanavaranConfigCache();
|
||||
}
|
||||
|
||||
@Get("offline-inquiry")
|
||||
@UseGuards(SettingsJwtGuard, RolesGuard)
|
||||
@Roles(...EXPERT_AND_ADMIN_ROLES)
|
||||
@ApiOperation({
|
||||
summary: "Get offline inquiry master switch",
|
||||
description:
|
||||
"When enabled, matching `offlineInquiries` seeds short-circuit live plate inquiry. When disabled, live/mock paths run as usual.",
|
||||
})
|
||||
@ApiResponse({ status: 200, type: OfflineInquirySettingsViewDto })
|
||||
getOfflineInquirySettings(): Promise<OfflineInquirySettingsViewDto> {
|
||||
return this.systemSettingsService.getOfflineInquirySettings();
|
||||
}
|
||||
|
||||
@Patch("offline-inquiry")
|
||||
@UseGuards(SettingsJwtGuard, RolesGuard)
|
||||
@Roles(...EXPERT_AND_ADMIN_ROLES)
|
||||
@ApiOperation({
|
||||
summary: "Enable or disable offline seeded plate inquiries",
|
||||
description:
|
||||
"Global master switch stored in `system_settings.offlineInquiry.enabled`. Per-seed `enabled` flags still apply when this is on.",
|
||||
})
|
||||
@ApiResponse({ status: 200, type: OfflineInquirySettingsViewDto })
|
||||
updateOfflineInquirySettings(
|
||||
@Body() body: UpdateOfflineInquirySettingsDto,
|
||||
): Promise<OfflineInquirySettingsViewDto> {
|
||||
return this.systemSettingsService.updateOfflineInquirySettings(body);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user