improve candidate entity for empty driver or passenger schedule

This commit is contained in:
Sylvain Briat 2024-03-29 15:10:04 +01:00
parent 212b609e26
commit 739d05b095
1 changed files with 79 additions and 85 deletions

View File

@ -60,7 +60,7 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
* This is a tedious process : additional information can be found in deeper methods !
*/
createJourneys = (): CandidateEntity => {
// driver and passenger schedules are mandatory
// driver and passenger schedules are eventually mandatory
if (!this.props.driverSchedule) this._createDriverSchedule();
if (!this.props.passengerSchedule) this._createPassengerSchedule();
try {
@ -96,9 +96,7 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
* Create the driver schedule based on the passenger schedule
*/
private _createDriverSchedule = (): void => {
if (this.props.passengerSchedule) {
let driverSchedule: ScheduleItemProps[] =
this.props.passengerSchedule.map(
let driverSchedule: ScheduleItemProps[] = this.props.passengerSchedule!.map(
(scheduleItemProps: ScheduleItemProps) => ({
day: scheduleItemProps.day,
time: scheduleItemProps.time,
@ -139,7 +137,6 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
margin: scheduleItemProps.margin,
}),
);
}
};
/**
@ -162,9 +159,7 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
* Create the passenger schedule based on the driver schedule
*/
private _createPassengerSchedule = (): void => {
if (this.props.driverSchedule) {
let passengerSchedule: ScheduleItemProps[] =
this.props.driverSchedule.map(
let passengerSchedule: ScheduleItemProps[] = this.props.driverSchedule!.map(
(scheduleItemProps: ScheduleItemProps) => ({
day: scheduleItemProps.day,
time: scheduleItemProps.time,
@ -205,7 +200,6 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
margin: scheduleItemProps.margin,
}),
);
}
};
private _createJourney = (driverScheduleItem: ScheduleItem): Journey =>