forked from Yara724/api
Add tenant-scoped insurer, staff and branch management APIs
Support all six staff roles and editable Fanavaran codes, insurer login accounts and optional branch details. Enforce tenant boundaries and role-specific fields, document setup and extend regression coverage.
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
Query,
|
||||
UseGuards,
|
||||
UsePipes,
|
||||
ValidationPipe,
|
||||
} from "@nestjs/common";
|
||||
import { ApiBearerAuth, ApiTags } from "@nestjs/swagger";
|
||||
import { LocalActorAuthGuard } from "src/auth/guards/actor-local.guard";
|
||||
import { RolesGuard } from "src/auth/guards/role.guard";
|
||||
import { Roles } from "src/decorators/roles.decorator";
|
||||
import { CurrentUser } from "src/decorators/user.decorator";
|
||||
import { RoleEnum } from "src/Types&Enums/role.enum";
|
||||
import { SuperAdminGuard } from "src/super-admin/guards/super-admin.guard";
|
||||
import { CreateBranchDto } from "src/client/dto/create-branch.dto";
|
||||
import {
|
||||
CreateManagedAccountDto,
|
||||
CreateManagedClientDto,
|
||||
CreateManagedStaffDto,
|
||||
ManagedListQueryDto,
|
||||
UpdateManagedAccountDto,
|
||||
UpdateManagedBranchDto,
|
||||
UpdateManagedClientDto,
|
||||
UpdateManagedStaffDto,
|
||||
} from "./management.dto";
|
||||
import { ManagementService } from "./management.service";
|
||||
const validation = new ValidationPipe({
|
||||
transform: true,
|
||||
whitelist: true,
|
||||
forbidNonWhitelisted: true,
|
||||
});
|
||||
|
||||
@ApiTags("super-admin-management")
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(SuperAdminGuard)
|
||||
@UsePipes(validation)
|
||||
@Controller("super-admin/management")
|
||||
export class SuperAdminManagementController {
|
||||
constructor(private management: ManagementService) {}
|
||||
@Get("clients") clients() {
|
||||
return this.management.listClients();
|
||||
}
|
||||
@Post("clients") createClient(@Body() body: CreateManagedClientDto) {
|
||||
return this.management.saveClient(body);
|
||||
}
|
||||
@Patch("clients/:id") updateClient(
|
||||
@Param("id") id: string,
|
||||
@Body() body: UpdateManagedClientDto,
|
||||
) {
|
||||
return this.management.saveClient(body, id);
|
||||
}
|
||||
@Get("clients/:clientId/accounts") accounts(
|
||||
@Param("clientId") id: string,
|
||||
@Query() query: ManagedListQueryDto,
|
||||
) {
|
||||
return this.management.listStaff(id, query, true);
|
||||
}
|
||||
@Post("clients/:clientId/accounts") createAccount(
|
||||
@Param("clientId") id: string,
|
||||
@Body() body: CreateManagedAccountDto,
|
||||
) {
|
||||
return this.management.createStaff(id, body, true);
|
||||
}
|
||||
@Patch("clients/:clientId/accounts/:id") updateAccount(
|
||||
@Param("clientId") client: string,
|
||||
@Param("id") id: string,
|
||||
@Body() body: UpdateManagedAccountDto,
|
||||
) {
|
||||
return this.management.updateStaff(
|
||||
client,
|
||||
RoleEnum.COMPANY,
|
||||
id,
|
||||
body,
|
||||
true,
|
||||
);
|
||||
}
|
||||
@Get("staff") staff(@Query() query: ManagedListQueryDto) {
|
||||
return this.management.listStaff(query.clientId, query);
|
||||
}
|
||||
@Post("staff") createStaff(
|
||||
@Query("clientId") client: string,
|
||||
@Body() body: CreateManagedStaffDto,
|
||||
) {
|
||||
return this.management.createStaff(client, body);
|
||||
}
|
||||
@Patch("staff/:role/:id") updateStaff(
|
||||
@Query("clientId") client: string,
|
||||
@Param("role") role: string,
|
||||
@Param("id") id: string,
|
||||
@Body() body: UpdateManagedStaffDto,
|
||||
) {
|
||||
return this.management.updateStaff(client, role, id, body);
|
||||
}
|
||||
@Get("branches") branches(@Query("clientId") client: string) {
|
||||
return this.management.listBranches(client);
|
||||
}
|
||||
@Post("branches") createBranch(
|
||||
@Query("clientId") client: string,
|
||||
@Body() body: CreateBranchDto,
|
||||
) {
|
||||
return this.management.saveBranch(client, body);
|
||||
}
|
||||
@Patch("branches/:id") updateBranch(
|
||||
@Query("clientId") client: string,
|
||||
@Param("id") id: string,
|
||||
@Body() body: UpdateManagedBranchDto,
|
||||
) {
|
||||
return this.management.saveBranch(client, body, id);
|
||||
}
|
||||
}
|
||||
@ApiTags("insurer-management")
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(LocalActorAuthGuard, RolesGuard)
|
||||
@Roles(RoleEnum.COMPANY)
|
||||
@UsePipes(validation)
|
||||
@Controller("expert-insurer/management")
|
||||
export class InsurerManagementController {
|
||||
constructor(private management: ManagementService) {}
|
||||
@Get("staff") staff(
|
||||
@CurrentUser() actor,
|
||||
@Query() query: ManagedListQueryDto,
|
||||
) {
|
||||
return this.management.listStaff(actor.clientKey, query);
|
||||
}
|
||||
@Post("staff") createStaff(
|
||||
@CurrentUser() actor,
|
||||
@Body() body: CreateManagedStaffDto,
|
||||
) {
|
||||
return this.management.createStaff(actor.clientKey, body);
|
||||
}
|
||||
@Patch("staff/:role/:id") updateStaff(
|
||||
@CurrentUser() actor,
|
||||
@Param("role") role: string,
|
||||
@Param("id") id: string,
|
||||
@Body() body: UpdateManagedStaffDto,
|
||||
) {
|
||||
return this.management.updateStaff(actor.clientKey, role, id, body);
|
||||
}
|
||||
@Get("branches") branches(@CurrentUser() actor) {
|
||||
return this.management.listBranches(actor.clientKey);
|
||||
}
|
||||
@Post("branches") createBranch(
|
||||
@CurrentUser() actor,
|
||||
@Body() body: CreateBranchDto,
|
||||
) {
|
||||
return this.management.saveBranch(actor.clientKey, body);
|
||||
}
|
||||
@Patch("branches/:id") updateBranch(
|
||||
@CurrentUser() actor,
|
||||
@Param("id") id: string,
|
||||
@Body() body: UpdateManagedBranchDto,
|
||||
) {
|
||||
return this.management.saveBranch(actor.clientKey, body, id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user