- Implemented CompanyLogoUseCases for retrieving, saving, and removing company logos. - Created CompanyLogoError class for error handling related to logo operations. - Developed CompanyLogoProcessor to optimize and validate logo images. - Added HTTP routes for logo management, including GET and POST endpoints. - Created Sequelize-based repository for logo persistence. - Implemented migration for adding logoVersion to companies and creating company_logos table. - Added frontend components for displaying and managing company logos, including avatar and logo upload fields. - Wrote tests for logo processing and avatar components to ensure functionality and correctness.
61 lines
2.2 KiB
TypeScript
61 lines
2.2 KiB
TypeScript
import type { CompanyDTO, CompanySummaryDTO } from "../../common";
|
|
import type { Company } from "../domain/company.aggregate";
|
|
import type { AssignmentValues } from "../domain/department-assignment.entity";
|
|
export function buildCompanySummary(company: Company): CompanySummaryDTO {
|
|
return {
|
|
id: company.id.toPrimitive(),
|
|
name: company.name.toPrimitive(),
|
|
active: company.active,
|
|
logoVersion: company.logoVersion,
|
|
};
|
|
}
|
|
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,
|
|
};
|
|
}
|
|
export function buildCompanyResponse(company: Company): CompanyDTO {
|
|
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,
|
|
}));
|
|
return {
|
|
...buildCompanySummary(company),
|
|
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),
|
|
})),
|
|
})),
|
|
sites: company.sites.map((site) => ({
|
|
id: site.id.toPrimitive(),
|
|
companyId: site.companyId.toPrimitive(),
|
|
name: site.name.toPrimitive(),
|
|
address: site.address.getOrUndefined()?.toPrimitive() ?? null,
|
|
})),
|
|
};
|
|
}
|