improve creation of schedules

This commit is contained in:
Sylvain Briat 2024-04-02 11:09:59 +02:00 committed by sbriat
parent 100fb3487d
commit 0446d267ef
1 changed files with 82 additions and 62 deletions

View File

@ -96,7 +96,8 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
* Create the driver schedule based on the passenger schedule
*/
private _createDriverSchedule = (): void => {
let driverSchedule: ScheduleItemProps[] = this.props.passengerSchedule!.map(
let driverSchedule: Array<ScheduleItemProps | undefined> =
this.props.passengerSchedule!.map(
(scheduleItemProps: ScheduleItemProps) => ({
day: scheduleItemProps.day,
time: scheduleItemProps.time,
@ -106,8 +107,9 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
// adjust the driver theoretical schedule :
// we guess the ideal driver departure time based on the duration to
// reach the passenger starting point from the driver starting point
driverSchedule = driverSchedule.map(
(scheduleItemProps: ScheduleItemProps) => {
driverSchedule = driverSchedule
.map((scheduleItemProps: ScheduleItemProps) => {
try {
const driverDate: Date = CalendarTools.firstDate(
scheduleItemProps.day,
this.props.dateInterval,
@ -117,7 +119,7 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
scheduleItemProps.time,
-this._passengerStartDuration(),
);
return {
return <ScheduleItemProps>{
day: driverDate.getUTCDay(),
margin: scheduleItemProps.margin,
time: `${driverStartDatetime
@ -128,7 +130,15 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
.toString()
.padStart(2, '0')}`,
};
},
} catch (e) {
// no possible driver date or time
// TODO : find a test case !
return undefined;
}
})
.filter(
(scheduleItemProps: ScheduleItemProps | undefined) =>
scheduleItemProps !== undefined,
);
this.props.driverSchedule = driverSchedule.map(
(scheduleItemProps: ScheduleItemProps) => ({
@ -159,7 +169,8 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
* Create the passenger schedule based on the driver schedule
*/
private _createPassengerSchedule = (): void => {
let passengerSchedule: ScheduleItemProps[] = this.props.driverSchedule!.map(
let passengerSchedule: Array<ScheduleItemProps | undefined> =
this.props.driverSchedule!.map(
(scheduleItemProps: ScheduleItemProps) => ({
day: scheduleItemProps.day,
time: scheduleItemProps.time,
@ -169,8 +180,9 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
// adjust the passenger theoretical schedule :
// we guess the ideal passenger departure time based on the duration to
// reach the passenger starting point from the driver starting point
passengerSchedule = passengerSchedule.map(
(scheduleItemProps: ScheduleItemProps) => {
passengerSchedule = passengerSchedule
.map((scheduleItemProps: ScheduleItemProps) => {
try {
const passengerDate: Date = CalendarTools.firstDate(
scheduleItemProps.day,
this.props.dateInterval,
@ -191,7 +203,15 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
.toString()
.padStart(2, '0')}`,
};
},
} catch (e) {
// no possible passenger date or time
// TODO : find a test case !
return undefined;
}
})
.filter(
(scheduleItemProps: ScheduleItemProps | undefined) =>
scheduleItemProps !== undefined,
);
this.props.passengerSchedule = passengerSchedule.map(
(scheduleItemProps: ScheduleItemProps) => ({