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:
SepehrYahyaee
2026-10-11 10:42:44 +03:30
parent 4302be8595
commit 0c272f1e86
19 changed files with 1930 additions and 7 deletions
+187
View File
@@ -0,0 +1,187 @@
import {
ApiProperty,
ApiPropertyOptional,
OmitType,
PartialType,
PickType,
} from "@nestjs/swagger";
import { Transform, Type } from "class-transformer";
import {
ArrayMaxSize,
IsArray,
IsEmail,
IsIn,
IsInt,
IsMongoId,
IsNotEmpty,
IsOptional,
IsString,
Matches,
MaxLength,
Min,
MinLength,
ValidateNested,
} from "class-validator";
import { RoleEnum } from "src/Types&Enums/role.enum";
import { ClientDto } from "src/client/dto/create-client.dto";
import { CreateBranchDto } from "src/client/dto/create-branch.dto";
import { ExpertLocationDto } from "src/expert-insurer/dto/create-insurer-expert.dto";
export const STAFF_ROLES = [
RoleEnum.EXPERT,
RoleEnum.DAMAGE_EXPERT,
RoleEnum.FIELD_EXPERT,
RoleEnum.FILE_MAKER,
RoleEnum.FILE_REVIEWER,
RoleEnum.CALL_CENTER,
] as const;
export type StaffRole = (typeof STAFF_ROLES)[number];
const trim = ({ value }: { value: unknown }) =>
typeof value === "string" ? value.trim() : value;
const optionalText = ({ value }: { value: unknown }) =>
typeof value === "string" && !value.trim() ? null : trim({ value });
export class CreateManagedStaffDto {
@ApiProperty({ enum: STAFF_ROLES }) @IsIn(STAFF_ROLES) role: StaffRole;
@ApiProperty()
@Transform(trim)
@IsString()
@IsNotEmpty()
@MaxLength(100)
firstName: string;
@ApiProperty()
@Transform(trim)
@IsString()
@IsNotEmpty()
@MaxLength(100)
lastName: string;
@ApiProperty() @Transform(trim) @Matches(/^\d{10}$/) nationalCode: string;
@ApiPropertyOptional()
@Transform(optionalText)
@IsOptional()
@IsEmail()
email?: string;
@ApiProperty({ minLength: 6 })
@IsString()
@MinLength(6)
@MaxLength(200)
password: string;
@ApiPropertyOptional()
@Transform(optionalText)
@IsOptional()
@Matches(/^09\d{9}$/)
mobile?: string;
@ApiPropertyOptional()
@Transform(optionalText)
@IsOptional()
@IsMongoId()
branchId?: string;
@ApiPropertyOptional()
@Transform(optionalText)
@IsOptional()
@IsString()
@MaxLength(30)
phone?: string;
@ApiPropertyOptional()
@Transform(optionalText)
@IsOptional()
@IsString()
@MaxLength(100)
city?: string;
@ApiPropertyOptional()
@Transform(optionalText)
@IsOptional()
@IsString()
@MaxLength(100)
state?: string;
@ApiPropertyOptional()
@Transform(optionalText)
@IsOptional()
@IsString()
@MaxLength(1000)
address?: string;
@ApiPropertyOptional()
@Transform(optionalText)
@IsOptional()
@Matches(/^\d+$/)
expertCode?: string;
@ApiPropertyOptional({ type: [ExpertLocationDto] })
@IsOptional()
@IsArray()
@ArrayMaxSize(100)
@ValidateNested({ each: true })
@Type(() => ExpertLocationDto)
locations?: ExpertLocationDto[];
@ApiPropertyOptional({ description: "کارشناس مسئول پرونده مالی" })
@Transform(optionalText)
@IsOptional()
@Matches(/^\d+$/)
ThirdPartyClaimExpertId?: string;
@ApiPropertyOptional({ description: "کارشناس مسئول پرونده بدنه" })
@Transform(optionalText)
@IsOptional()
@Matches(/^\d+$/)
CarBodyClaimExpertId?: string;
@ApiPropertyOptional({ description: "کارشناس ارزیاب خسارت ثالث مالی" })
@Transform(optionalText)
@IsOptional()
@Matches(/^\d+$/)
ThirdPartyExpertiseClaim?: string;
@ApiPropertyOptional({ description: "کارشناس ارزیاب خسارت بدنه" })
@Transform(optionalText)
@IsOptional()
@Matches(/^\d+$/)
CarBodyExpertiseClaim?: string;
}
export class UpdateManagedStaffDto extends PartialType(
OmitType(CreateManagedStaffDto, ["role"] as const),
) {}
export class CreateManagedAccountDto extends PickType(CreateManagedStaffDto, [
"firstName",
"lastName",
"email",
"password",
"mobile",
"phone",
"city",
"state",
"address",
] as const) {}
export class UpdateManagedAccountDto extends PartialType(
CreateManagedAccountDto,
) {}
export class UpdateManagedBranchDto extends PartialType(CreateBranchDto) {}
export class CreateManagedClientDto extends PickType(ClientDto, [
"clientName",
"clientCode",
"useExpertMode",
] as const) {
@ApiProperty() @IsInt() @Min(1) clientCode: number;
}
export class UpdateManagedClientDto extends PartialType(
CreateManagedClientDto,
) {}
export class ManagedListQueryDto {
@ApiPropertyOptional() @IsOptional() @IsMongoId() clientId?: string;
@ApiPropertyOptional({ enum: STAFF_ROLES })
@IsOptional()
@IsIn(STAFF_ROLES)
role?: StaffRole;
@ApiPropertyOptional()
@IsOptional()
@IsString()
@MaxLength(100)
search?: string;
@ApiPropertyOptional({ default: 1 })
@Type(() => Number)
@IsOptional()
@IsInt()
@Min(1)
page?: number;
@ApiPropertyOptional({ default: 20 })
@Type(() => Number)
@IsOptional()
@IsInt()
@Min(1)
limit?: number;
}