27 lines
1015 B
TypeScript
27 lines
1015 B
TypeScript
|
|
import type { CompanyDTO, CompanySummaryDTO } from "../../common";
|
||
|
|
import type { Company } from "../domain/company.aggregate";
|
||
|
|
|
||
|
|
export function buildCompanySummary(company: Company): CompanySummaryDTO {
|
||
|
|
return { id: company.id.toPrimitive(), name: company.name.toPrimitive(), active: company.active };
|
||
|
|
}
|
||
|
|
export function buildCompanyResponse(company: Company): CompanyDTO {
|
||
|
|
return {
|
||
|
|
...buildCompanySummary(company),
|
||
|
|
contacts: company.contacts.map((contact) => ({
|
||
|
|
id: contact.id.toPrimitive(),
|
||
|
|
companyId: contact.companyId.toPrimitive(),
|
||
|
|
name: contact.name.toPrimitive(),
|
||
|
|
position: contact.position.toPrimitive(),
|
||
|
|
email: contact.email.toPrimitive(),
|
||
|
|
phone: contact.phone.toPrimitive(),
|
||
|
|
active: contact.active,
|
||
|
|
})),
|
||
|
|
sites: company.sites.map((site) => ({
|
||
|
|
id: site.id.toPrimitive(),
|
||
|
|
companyId: site.companyId.toPrimitive(),
|
||
|
|
name: site.name.toPrimitive(),
|
||
|
|
address: site.address.getOrUndefined()?.toPrimitive() ?? null,
|
||
|
|
})),
|
||
|
|
};
|
||
|
|
}
|