2026-10-03 10:36:03 +00:00
|
|
|
import type { CompanyDTO, CompanySummaryDTO } from "../../common";
|
|
|
|
|
import type { Company } from "../domain/company.aggregate";
|
2026-10-03 11:13:15 +00:00
|
|
|
import type { AssignmentValues } from "../domain/department-assignment.entity";
|
2026-10-03 10:36:03 +00:00
|
|
|
export function buildCompanySummary(company: Company): CompanySummaryDTO {
|
2026-10-08 16:31:46 +00:00
|
|
|
return {
|
|
|
|
|
id: company.id.toPrimitive(),
|
|
|
|
|
name: company.name.toPrimitive(),
|
|
|
|
|
active: company.active,
|
|
|
|
|
logoVersion: company.logoVersion,
|
|
|
|
|
};
|
2026-10-03 10:36:03 +00:00
|
|
|
}
|
2026-10-03 11:13:15 +00:00
|
|
|
export function buildAssignmentValues(values: AssignmentValues) {
|
|
|
|
|
return {
|
|
|
|
|
position: values.position.getOrUndefined()?.toPrimitive() ?? null,
|
|
|
|
|
startDate: values.startDate.toPrimitive(),
|
|
|
|
|
endDate: values.endDate.getOrUndefined()?.toPrimitive() ?? null,
|
|
|
|
|
isPrimary: values.isPrimary,
|
|
|
|
|
};
|
|
|
|
|
}
|
2026-10-03 10:36:03 +00:00
|
|
|
export function buildCompanyResponse(company: Company): CompanyDTO {
|
2026-10-03 11:13:15 +00:00
|
|
|
const people = company.people.map((person) => ({
|
|
|
|
|
id: person.id.toPrimitive(),
|
|
|
|
|
companyId: person.companyId.toPrimitive(),
|
|
|
|
|
name: person.name.toPrimitive(),
|
|
|
|
|
position: person.position.getOrUndefined()?.toPrimitive() ?? null,
|
|
|
|
|
email: person.email.getOrUndefined()?.toPrimitive() ?? null,
|
|
|
|
|
phone: person.phone.getOrUndefined()?.toPrimitive() ?? null,
|
|
|
|
|
active: person.active,
|
|
|
|
|
isContact: person.isContact,
|
|
|
|
|
}));
|
2026-10-03 10:36:03 +00:00
|
|
|
return {
|
|
|
|
|
...buildCompanySummary(company),
|
2026-10-03 11:13:15 +00:00
|
|
|
people,
|
|
|
|
|
contacts: people.filter((person) => person.isContact),
|
|
|
|
|
departments: company.departments.map((item) => ({
|
|
|
|
|
id: item.id.toPrimitive(),
|
|
|
|
|
companyId: item.companyId.toPrimitive(),
|
|
|
|
|
name: item.name.toPrimitive(),
|
|
|
|
|
active: item.active,
|
|
|
|
|
})),
|
|
|
|
|
assignments: company.assignments.map((item) => ({
|
|
|
|
|
id: item.id.toPrimitive(),
|
|
|
|
|
companyId: item.companyId.toPrimitive(),
|
|
|
|
|
personId: item.personId.toPrimitive(),
|
|
|
|
|
departmentId: item.departmentId.toPrimitive(),
|
|
|
|
|
...buildAssignmentValues(item.values),
|
|
|
|
|
history: item.history.map((revision) => ({
|
|
|
|
|
id: revision.id.toPrimitive(),
|
|
|
|
|
recordedAt: revision.values.recordedAt,
|
|
|
|
|
...buildAssignmentValues(revision.values),
|
|
|
|
|
})),
|
2026-10-03 10:36:03 +00:00
|
|
|
})),
|
|
|
|
|
sites: company.sites.map((site) => ({
|
|
|
|
|
id: site.id.toPrimitive(),
|
|
|
|
|
companyId: site.companyId.toPrimitive(),
|
|
|
|
|
name: site.name.toPrimitive(),
|
|
|
|
|
address: site.address.getOrUndefined()?.toPrimitive() ?? null,
|
|
|
|
|
})),
|
|
|
|
|
};
|
|
|
|
|
}
|