Combine journey creation and filtering to avoid missing results
This commit is contained in:
parent
945ce80840
commit
0dc01da2b0
|
@ -1,28 +1,28 @@
|
||||||
import {
|
import {
|
||||||
AggregateRoot,
|
|
||||||
AggregateID,
|
AggregateID,
|
||||||
|
AggregateRoot,
|
||||||
ArgumentInvalidException,
|
ArgumentInvalidException,
|
||||||
} from '@mobicoop/ddd-library';
|
} from '@mobicoop/ddd-library';
|
||||||
|
import { Role } from './ad.types';
|
||||||
|
import { CalendarTools } from './calendar-tools.service';
|
||||||
import {
|
import {
|
||||||
CandidateProps,
|
CandidateProps,
|
||||||
CreateCandidateProps,
|
CreateCandidateProps,
|
||||||
Target,
|
Target,
|
||||||
} from './candidate.types';
|
} from './candidate.types';
|
||||||
|
import { ActorTime } from './value-objects/actor-time.value-object';
|
||||||
|
import { Actor } from './value-objects/actor.value-object';
|
||||||
import {
|
import {
|
||||||
CarpoolPathItem,
|
CarpoolPathItem,
|
||||||
CarpoolPathItemProps,
|
CarpoolPathItemProps,
|
||||||
} from './value-objects/carpool-path-item.value-object';
|
} from './value-objects/carpool-path-item.value-object';
|
||||||
import { Step, StepProps } from './value-objects/step.value-object';
|
import { JourneyItem } from './value-objects/journey-item.value-object';
|
||||||
|
import { Journey, JourneyProps } from './value-objects/journey.value-object';
|
||||||
import {
|
import {
|
||||||
ScheduleItem,
|
ScheduleItem,
|
||||||
ScheduleItemProps,
|
ScheduleItemProps,
|
||||||
} from './value-objects/schedule-item.value-object';
|
} from './value-objects/schedule-item.value-object';
|
||||||
import { Journey } from './value-objects/journey.value-object';
|
import { Step, StepProps } from './value-objects/step.value-object';
|
||||||
import { CalendarTools } from './calendar-tools.service';
|
|
||||||
import { JourneyItem } from './value-objects/journey-item.value-object';
|
|
||||||
import { Actor } from './value-objects/actor.value-object';
|
|
||||||
import { ActorTime } from './value-objects/actor-time.value-object';
|
|
||||||
import { Role } from './ad.types';
|
|
||||||
|
|
||||||
export class CandidateEntity extends AggregateRoot<CandidateProps> {
|
export class CandidateEntity extends AggregateRoot<CandidateProps> {
|
||||||
protected readonly _id: AggregateID;
|
protected readonly _id: AggregateID;
|
||||||
|
@ -63,18 +63,23 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
|
||||||
// driver and passenger schedules are eventually mandatory
|
// driver and passenger schedules are eventually mandatory
|
||||||
if (!this.props.driverSchedule) this._createDriverSchedule();
|
if (!this.props.driverSchedule) this._createDriverSchedule();
|
||||||
if (!this.props.passengerSchedule) this._createPassengerSchedule();
|
if (!this.props.passengerSchedule) this._createPassengerSchedule();
|
||||||
try {
|
this.props.journeys = this.props.driverSchedule!.reduce(
|
||||||
this.props.journeys = (this.props.driverSchedule as ScheduleItemProps[])
|
(accJourneys: JourneyProps[], driverScheduleItem: ScheduleItem) => {
|
||||||
// first we create the journeys
|
try {
|
||||||
.map((driverScheduleItem: ScheduleItem) =>
|
// first we create the journeys
|
||||||
this._createJourney(driverScheduleItem),
|
const journey = this._createJourney(driverScheduleItem);
|
||||||
)
|
// then we filter the ones with invalid pickups
|
||||||
// then we filter the ones with invalid pickups
|
if (journey.hasValidPickUp()) {
|
||||||
.filter((journey: Journey) => journey.hasValidPickUp());
|
accJourneys.push(journey);
|
||||||
} catch (e) {
|
}
|
||||||
// irrelevant journeys fall here
|
} catch (e) {
|
||||||
// eg. no available day for the given date range
|
// irrelevant journeys fall here
|
||||||
}
|
// eg. no available day for the given date range
|
||||||
|
}
|
||||||
|
return accJourneys;
|
||||||
|
},
|
||||||
|
new Array<JourneyProps>(),
|
||||||
|
);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue