metis-desk/modules/companies/src/api/domain/department.entity.ts
David 18324f92bd feat: add person and department management features
- Implemented Person entity with validation and update methods.
- Created CalendarDate value object for date validation.
- Developed migration script to transition company_contacts to person and department structures.
- Established Sequelize models for departments and assignments.
- Introduced request DTOs for person and department management.
- Added shared DTO schemas for validation.
- Built assignment and department forms with validation and submission handling.
- Created people section to manage and display company personnel.
- Implemented person form for adding and editing personnel details.
2026-10-03 13:13:15 +02:00

35 lines
1.2 KiB
TypeScript

import type { Name, UniqueID } from "@repo/rdx-ddd";
import { DomainEntity } from "@repo/rdx-ddd";
import { Result } from "@repo/rdx-utils";
import { CompanyError } from "./company-error";
export type DepartmentProps = Readonly<{ companyId: UniqueID; name: Name; active: boolean }>;
export class Department extends DomainEntity<DepartmentProps> {
static create(props: DepartmentProps): Result<Department, CompanyError> {
if (props.name.toPrimitive().length > 100) {
return Result.fail(new CompanyError("INVALID_REQUEST"));
}
return Result.ok(new Department(props));
}
static rehydrate(props: DepartmentProps, id: UniqueID) {
return new Department(props, id);
}
get companyId() {
return this.props.companyId;
}
get name() {
return this.props.name;
}
get active() {
return this.props.active;
}
update(values: Omit<DepartmentProps, "companyId">): Result<Department, CompanyError> {
if (values.name.toPrimitive().length > 100) {
return Result.fail(new CompanyError("INVALID_REQUEST"));
}
return this.name.equals(values.name) && this.active === values.active
? Result.ok(this)
: Result.ok(new Department({ ...values, companyId: this.companyId }, this.id));
}
}