- Added pnpm-workspace.yaml to define package structure. - Created prepare-local-env.py script for local environment setup. - Introduced tsconfig.json for TypeScript configuration. - Added turbo.json for task management with Turbo.
60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import type { EmailAddress, Name, UniqueID } from "@repo/rdx-ddd";
|
|
import { DomainEntity } from "@repo/rdx-ddd";
|
|
import { Result } from "@repo/rdx-utils";
|
|
|
|
import { CompanyError } from "./company-error";
|
|
import type { PhoneNumber } from "./value-objects/phone-number";
|
|
|
|
export type ContactProps = Readonly<{
|
|
companyId: UniqueID;
|
|
name: Name;
|
|
position: Name;
|
|
email: EmailAddress;
|
|
phone: PhoneNumber;
|
|
active: boolean;
|
|
}>;
|
|
export class Contact extends DomainEntity<ContactProps> {
|
|
static create(props: ContactProps): Result<Contact, CompanyError> {
|
|
if (props.name.toPrimitive().length > 100 || props.position.toPrimitive().length > 100) {
|
|
return Result.fail(new CompanyError("INVALID_REQUEST"));
|
|
}
|
|
return Result.ok(new Contact(props));
|
|
}
|
|
static rehydrate(props: ContactProps, id: UniqueID): Contact {
|
|
return new Contact(props, id);
|
|
}
|
|
get companyId() {
|
|
return this.props.companyId;
|
|
}
|
|
get name() {
|
|
return this.props.name;
|
|
}
|
|
get position() {
|
|
return this.props.position;
|
|
}
|
|
get email() {
|
|
return this.props.email;
|
|
}
|
|
get phone() {
|
|
return this.props.phone;
|
|
}
|
|
get active() {
|
|
return this.props.active;
|
|
}
|
|
update(values: Omit<ContactProps, "companyId">): Result<Contact, CompanyError> {
|
|
if (values.name.toPrimitive().length > 100 || values.position.toPrimitive().length > 100) {
|
|
return Result.fail(new CompanyError("INVALID_REQUEST"));
|
|
}
|
|
if (
|
|
this.name.equals(values.name) &&
|
|
this.position.equals(values.position) &&
|
|
this.email.equals(values.email) &&
|
|
this.phone.equals(values.phone) &&
|
|
this.active === values.active
|
|
) {
|
|
return Result.ok(this);
|
|
}
|
|
return Result.ok(new Contact({ ...values, companyId: this.companyId }, this.id));
|
|
}
|
|
}
|