forked from Yara724/api
YARA-917
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user