This commit is contained in:
SepehrYahyaee
2026-07-11 12:00:11 +03:30
parent 04f51167c2
commit da3f57870e

View File

@@ -99,20 +99,32 @@ export class ExpertInsurerController {
@Put("branches/:branchId/status") @Put("branches/:branchId/status")
@ApiParam({ name: "branchId" }) @ApiParam({ name: "branchId" })
@ApiQuery({ name: "isActive", type: Boolean }) @ApiBody({
schema: {
type: "object",
properties: { isActive: { type: "boolean" } },
required: ["isActive"],
},
})
async setBranchStatus( async setBranchStatus(
@CurrentUser() insurer, @CurrentUser() insurer,
@Param("branchId") branchId: string, @Param("branchId") branchId: string,
@Query("isActive") isActive: string, @Body("isActive") isActive: unknown,
) { ) {
if (!insurer) { if (!insurer) {
throw new UnauthorizedException("Could not identify the current user."); throw new UnauthorizedException("Could not identify the current user.");
} }
const normalized = String(isActive).trim().toLowerCase(); // Accept native boolean (JSON body) or string coercion (legacy query/form usage)
let active: boolean;
if (typeof isActive === "boolean") {
active = isActive;
} else {
const normalized = String(isActive ?? "").trim().toLowerCase();
if (!["true", "false", "1", "0", "yes", "no"].includes(normalized)) { if (!["true", "false", "1", "0", "yes", "no"].includes(normalized)) {
throw new BadRequestException("isActive must be true/false"); throw new BadRequestException("isActive must be a boolean");
}
active = ["true", "1", "yes"].includes(normalized);
} }
const active = ["true", "1", "yes"].includes(normalized);
return this.expertInsurerService.setBranchActive( return this.expertInsurerService.setBranchActive(
insurer.clientKey, insurer.clientKey,
branchId, branchId,