locations dynamically in fanavaran

This commit is contained in:
2026-09-02 15:31:55 +03:30
parent ebfeef9e01
commit 5c2b660600
10 changed files with 307 additions and 4 deletions

View File

@@ -1,8 +1,30 @@
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { IsEmail, IsEnum, IsMongoId, IsNotEmpty, IsOptional, IsString } from "class-validator";
import { Type } from "class-transformer";
import {
IsArray,
IsEmail,
IsEnum,
IsMongoId,
IsNotEmpty,
IsOptional,
IsString,
ValidateNested,
} from "class-validator";
import { RoleEnum } from "src/Types&Enums/role.enum";
import { UserType } from "src/Types&Enums/userType.enum";
export class ExpertLocationDto {
@ApiProperty({ example: "210050", description: "Fanavaran Location / OpBUId" })
@IsString()
@IsNotEmpty()
id: string;
@ApiProperty({ example: "شعبه غرب" })
@IsString()
@IsNotEmpty()
name: string;
}
export class CreateInsurerExpertDto {
@ApiProperty({ example: "Ali" })
@IsString()
@@ -88,6 +110,17 @@ export class CreateFileMakerByInsurerDto extends CreateInsurerExpertDto {
default: RoleEnum.FILE_MAKER,
})
role?: RoleEnum.FILE_MAKER;
@ApiPropertyOptional({
type: [ExpertLocationDto],
description:
"Fanavaran Location entries (id = OpBUId). Used for Parsian V4/V5 submits.",
})
@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => ExpertLocationDto)
locations?: ExpertLocationDto[];
}
export class CreateFileReviewerByInsurerDto extends CreateInsurerExpertDto {
@@ -96,4 +129,15 @@ export class CreateFileReviewerByInsurerDto extends CreateInsurerExpertDto {
default: RoleEnum.FILE_REVIEWER,
})
role?: RoleEnum.FILE_REVIEWER;
@ApiPropertyOptional({
type: [ExpertLocationDto],
description:
"Fanavaran Location entries. Must overlap FileMaker locations on Parsian V4/V5 cases.",
})
@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => ExpertLocationDto)
locations?: ExpertLocationDto[];
}

View File

@@ -2018,6 +2018,19 @@ export class ExpertInsurerService {
return rest;
}
private normalizeExpertLocations(
locations?: Array<{ id?: string; name?: string }> | null,
): Array<{ id: string; name: string }> | undefined {
if (!Array.isArray(locations) || locations.length === 0) return undefined;
const normalized = locations
.map((entry) => ({
id: String(entry?.id ?? "").trim(),
name: String(entry?.name ?? "").trim(),
}))
.filter((entry) => entry.id && entry.name);
return normalized.length > 0 ? normalized : undefined;
}
private async createExpertForInsurer(
insurerClientKey: string,
payload: CreateInsurerExpertDto,
@@ -2132,6 +2145,7 @@ export class ExpertInsurerService {
}
const hashedPassword = await this.hashService.hash(payload.password);
const locations = this.normalizeExpertLocations(payload.locations);
const created = await this.fileMakerDbService.create({
...payload,
email,
@@ -2140,6 +2154,7 @@ export class ExpertInsurerService {
role: RoleEnum.FILE_MAKER,
clientKey: clientObjectId,
branchId: new Types.ObjectId(payload.branchId),
...(locations ? { locations } : {}),
});
return {
@@ -2184,6 +2199,7 @@ export class ExpertInsurerService {
}
const hashedPassword = await this.hashService.hash(payload.password);
const locations = this.normalizeExpertLocations(payload.locations);
const created = await this.fileReviewerDbService.create({
...payload,
email,
@@ -2192,6 +2208,7 @@ export class ExpertInsurerService {
role: RoleEnum.FILE_REVIEWER,
clientKey: clientObjectId,
branchId: new Types.ObjectId(payload.branchId),
...(locations ? { locations } : {}),
});
return {