forked from Yara724/api
locations dynamically in fanavaran
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user