26 lines
877 B
TypeScript
26 lines
877 B
TypeScript
import { AggregateRoot, AggregateID } from '@mobicoop/ddd-library';
|
|
import { CandidateProps, CreateCandidateProps } from './candidate.types';
|
|
import { WayStepProps } from './value-objects/waystep.value-object';
|
|
|
|
export class CandidateEntity extends AggregateRoot<CandidateProps> {
|
|
protected readonly _id: AggregateID;
|
|
|
|
static create = (create: CreateCandidateProps): CandidateEntity => {
|
|
const props: CandidateProps = { ...create };
|
|
return new CandidateEntity({ id: create.id, props });
|
|
};
|
|
|
|
setCarpoolPath = (waySteps: WayStepProps[]): void => {
|
|
this.props.carpoolSteps = waySteps;
|
|
};
|
|
|
|
setMetrics = (distance: number, duration: number): void => {
|
|
this.props.distance = distance;
|
|
this.props.duration = duration;
|
|
};
|
|
|
|
validate(): void {
|
|
// entity business rules validation to protect it's invariant before saving entity to a database
|
|
}
|
|
}
|