forked from Yara724/api
Added API for externalAPI, added env for clients
This commit is contained in:
@@ -1,17 +1,24 @@
|
||||
import { Body, Controller, Get, Post, UseGuards } from "@nestjs/common";
|
||||
import { ApiBearerAuth, ApiTags } from "@nestjs/swagger";
|
||||
import { GlobalGuard } from "src/auth/guards/global.guard";
|
||||
import { RolesGuard } from "src/auth/guards/role.guard";
|
||||
import { Roles } from "src/decorators/roles.decorator";
|
||||
import { Body, Controller, Get, Patch, Post } from "@nestjs/common";
|
||||
import {
|
||||
ApiBody,
|
||||
ApiOperation,
|
||||
ApiResponse,
|
||||
ApiTags,
|
||||
} from "@nestjs/swagger";
|
||||
import { CurrentUser } from "src/decorators/user.decorator";
|
||||
import { RoleEnum } from "src/Types&Enums/role.enum";
|
||||
import { SystemSettingsResponseDto } from "src/system-settings/dto/system-settings.dto";
|
||||
import { SystemSettingsService } from "src/system-settings/system-settings.service";
|
||||
import { ClientService } from "./client.service";
|
||||
import { ClientDto } from "./dto/create-client.dto";
|
||||
import { SetExternalInquiriesLiveDto } from "./dto/external-inquiries-live.dto";
|
||||
|
||||
@Controller("client")
|
||||
@ApiTags("client-management")
|
||||
export class ClientController {
|
||||
constructor(private readonly clientService: ClientService) {}
|
||||
constructor(
|
||||
private readonly clientService: ClientService,
|
||||
private readonly systemSettingsService: SystemSettingsService,
|
||||
) {}
|
||||
|
||||
@Post()
|
||||
async addClient(@Body() client: ClientDto) {
|
||||
@@ -27,4 +34,33 @@ export class ClientController {
|
||||
async getClientList(@CurrentUser() user) {
|
||||
return await this.clientService.getClientList();
|
||||
}
|
||||
|
||||
/** Toggle SandHub/Tejarat live HTTP vs mock inquiries (`system_settings.externalApis.sandHubUseLiveApi`). */
|
||||
@Patch("external-inquiries-live")
|
||||
@ApiOperation({
|
||||
summary: "Enable or disable live external inquiries",
|
||||
description:
|
||||
"Updates `system_settings.externalApis.sandHubUseLiveApi`. No auth required. Use the request examples below to switch between live Tejarat/SandHub HTTP and offline mock mode.",
|
||||
})
|
||||
@ApiBody({
|
||||
type: SetExternalInquiriesLiveDto,
|
||||
examples: {
|
||||
enableLive: {
|
||||
summary: "Enable live inquiries",
|
||||
description: "Call real SandHub/Tejarat HTTP APIs.",
|
||||
value: { enabled: true },
|
||||
},
|
||||
disableLive: {
|
||||
summary: "Disable live inquiries (mock mode)",
|
||||
description: "Use mocked inquiry responses; flows continue without external connectivity.",
|
||||
value: { enabled: false },
|
||||
},
|
||||
},
|
||||
})
|
||||
@ApiResponse({ status: 200, type: SystemSettingsResponseDto })
|
||||
async setExternalInquiriesLive(@Body() body?: SetExternalInquiriesLiveDto) {
|
||||
return this.systemSettingsService.updateSettings({
|
||||
externalApis: { sandHubUseLiveApi: body?.enabled === true },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user