improve candidate entity for empty driver or passenger schedule
This commit is contained in:
parent
212b609e26
commit
739d05b095
|
@ -60,7 +60,7 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
|
||||||
* This is a tedious process : additional information can be found in deeper methods !
|
* This is a tedious process : additional information can be found in deeper methods !
|
||||||
*/
|
*/
|
||||||
createJourneys = (): CandidateEntity => {
|
createJourneys = (): CandidateEntity => {
|
||||||
// driver and passenger schedules are 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 {
|
try {
|
||||||
|
@ -96,50 +96,47 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
|
||||||
* Create the driver schedule based on the passenger schedule
|
* Create the driver schedule based on the passenger schedule
|
||||||
*/
|
*/
|
||||||
private _createDriverSchedule = (): void => {
|
private _createDriverSchedule = (): void => {
|
||||||
if (this.props.passengerSchedule) {
|
let driverSchedule: ScheduleItemProps[] = this.props.passengerSchedule!.map(
|
||||||
let driverSchedule: ScheduleItemProps[] =
|
(scheduleItemProps: ScheduleItemProps) => ({
|
||||||
this.props.passengerSchedule.map(
|
day: scheduleItemProps.day,
|
||||||
(scheduleItemProps: ScheduleItemProps) => ({
|
time: scheduleItemProps.time,
|
||||||
day: scheduleItemProps.day,
|
margin: scheduleItemProps.margin,
|
||||||
time: scheduleItemProps.time,
|
}),
|
||||||
margin: scheduleItemProps.margin,
|
);
|
||||||
}),
|
// 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) => {
|
||||||
|
const driverDate: Date = CalendarTools.firstDate(
|
||||||
|
scheduleItemProps.day,
|
||||||
|
this.props.dateInterval,
|
||||||
);
|
);
|
||||||
// adjust the driver theoretical schedule :
|
const driverStartDatetime: Date = CalendarTools.datetimeWithSeconds(
|
||||||
// we guess the ideal driver departure time based on the duration to
|
driverDate,
|
||||||
// reach the passenger starting point from the driver starting point
|
scheduleItemProps.time,
|
||||||
driverSchedule = driverSchedule.map(
|
-this._passengerStartDuration(),
|
||||||
(scheduleItemProps: ScheduleItemProps) => {
|
);
|
||||||
const driverDate: Date = CalendarTools.firstDate(
|
return {
|
||||||
scheduleItemProps.day,
|
day: driverDate.getUTCDay(),
|
||||||
this.props.dateInterval,
|
|
||||||
);
|
|
||||||
const driverStartDatetime: Date = CalendarTools.datetimeWithSeconds(
|
|
||||||
driverDate,
|
|
||||||
scheduleItemProps.time,
|
|
||||||
-this._passengerStartDuration(),
|
|
||||||
);
|
|
||||||
return {
|
|
||||||
day: driverDate.getUTCDay(),
|
|
||||||
margin: scheduleItemProps.margin,
|
|
||||||
time: `${driverStartDatetime
|
|
||||||
.getUTCHours()
|
|
||||||
.toString()
|
|
||||||
.padStart(2, '0')}:${driverStartDatetime
|
|
||||||
.getUTCMinutes()
|
|
||||||
.toString()
|
|
||||||
.padStart(2, '0')}`,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
);
|
|
||||||
this.props.driverSchedule = driverSchedule.map(
|
|
||||||
(scheduleItemProps: ScheduleItemProps) => ({
|
|
||||||
day: scheduleItemProps.day,
|
|
||||||
time: scheduleItemProps.time,
|
|
||||||
margin: scheduleItemProps.margin,
|
margin: scheduleItemProps.margin,
|
||||||
}),
|
time: `${driverStartDatetime
|
||||||
);
|
.getUTCHours()
|
||||||
}
|
.toString()
|
||||||
|
.padStart(2, '0')}:${driverStartDatetime
|
||||||
|
.getUTCMinutes()
|
||||||
|
.toString()
|
||||||
|
.padStart(2, '0')}`,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
);
|
||||||
|
this.props.driverSchedule = driverSchedule.map(
|
||||||
|
(scheduleItemProps: ScheduleItemProps) => ({
|
||||||
|
day: scheduleItemProps.day,
|
||||||
|
time: scheduleItemProps.time,
|
||||||
|
margin: scheduleItemProps.margin,
|
||||||
|
}),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -162,50 +159,47 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
|
||||||
* Create the passenger schedule based on the driver schedule
|
* Create the passenger schedule based on the driver schedule
|
||||||
*/
|
*/
|
||||||
private _createPassengerSchedule = (): void => {
|
private _createPassengerSchedule = (): void => {
|
||||||
if (this.props.driverSchedule) {
|
let passengerSchedule: ScheduleItemProps[] = this.props.driverSchedule!.map(
|
||||||
let passengerSchedule: ScheduleItemProps[] =
|
(scheduleItemProps: ScheduleItemProps) => ({
|
||||||
this.props.driverSchedule.map(
|
day: scheduleItemProps.day,
|
||||||
(scheduleItemProps: ScheduleItemProps) => ({
|
time: scheduleItemProps.time,
|
||||||
day: scheduleItemProps.day,
|
margin: scheduleItemProps.margin,
|
||||||
time: scheduleItemProps.time,
|
}),
|
||||||
margin: scheduleItemProps.margin,
|
);
|
||||||
}),
|
// 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) => {
|
||||||
|
const passengerDate: Date = CalendarTools.firstDate(
|
||||||
|
scheduleItemProps.day,
|
||||||
|
this.props.dateInterval,
|
||||||
);
|
);
|
||||||
// adjust the passenger theoretical schedule :
|
const passengeStartDatetime: Date = CalendarTools.datetimeWithSeconds(
|
||||||
// we guess the ideal passenger departure time based on the duration to
|
passengerDate,
|
||||||
// reach the passenger starting point from the driver starting point
|
scheduleItemProps.time,
|
||||||
passengerSchedule = passengerSchedule.map(
|
this._passengerStartDuration(),
|
||||||
(scheduleItemProps: ScheduleItemProps) => {
|
);
|
||||||
const passengerDate: Date = CalendarTools.firstDate(
|
return {
|
||||||
scheduleItemProps.day,
|
day: passengerDate.getUTCDay(),
|
||||||
this.props.dateInterval,
|
|
||||||
);
|
|
||||||
const passengeStartDatetime: Date = CalendarTools.datetimeWithSeconds(
|
|
||||||
passengerDate,
|
|
||||||
scheduleItemProps.time,
|
|
||||||
this._passengerStartDuration(),
|
|
||||||
);
|
|
||||||
return {
|
|
||||||
day: passengerDate.getUTCDay(),
|
|
||||||
margin: scheduleItemProps.margin,
|
|
||||||
time: `${passengeStartDatetime
|
|
||||||
.getUTCHours()
|
|
||||||
.toString()
|
|
||||||
.padStart(2, '0')}:${passengeStartDatetime
|
|
||||||
.getUTCMinutes()
|
|
||||||
.toString()
|
|
||||||
.padStart(2, '0')}`,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
);
|
|
||||||
this.props.passengerSchedule = passengerSchedule.map(
|
|
||||||
(scheduleItemProps: ScheduleItemProps) => ({
|
|
||||||
day: scheduleItemProps.day,
|
|
||||||
time: scheduleItemProps.time,
|
|
||||||
margin: scheduleItemProps.margin,
|
margin: scheduleItemProps.margin,
|
||||||
}),
|
time: `${passengeStartDatetime
|
||||||
);
|
.getUTCHours()
|
||||||
}
|
.toString()
|
||||||
|
.padStart(2, '0')}:${passengeStartDatetime
|
||||||
|
.getUTCMinutes()
|
||||||
|
.toString()
|
||||||
|
.padStart(2, '0')}`,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
);
|
||||||
|
this.props.passengerSchedule = passengerSchedule.map(
|
||||||
|
(scheduleItemProps: ScheduleItemProps) => ({
|
||||||
|
day: scheduleItemProps.day,
|
||||||
|
time: scheduleItemProps.time,
|
||||||
|
margin: scheduleItemProps.margin,
|
||||||
|
}),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
private _createJourney = (driverScheduleItem: ScheduleItem): Journey =>
|
private _createJourney = (driverScheduleItem: ScheduleItem): Journey =>
|
||||||
|
|
Loading…
Reference in New Issue