improve creation of schedules
This commit is contained in:
parent
100fb3487d
commit
0446d267ef
|
@ -96,7 +96,8 @@ 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 => {
|
||||||
let driverSchedule: ScheduleItemProps[] = this.props.passengerSchedule!.map(
|
let driverSchedule: Array<ScheduleItemProps | undefined> =
|
||||||
|
this.props.passengerSchedule!.map(
|
||||||
(scheduleItemProps: ScheduleItemProps) => ({
|
(scheduleItemProps: ScheduleItemProps) => ({
|
||||||
day: scheduleItemProps.day,
|
day: scheduleItemProps.day,
|
||||||
time: scheduleItemProps.time,
|
time: scheduleItemProps.time,
|
||||||
|
@ -106,8 +107,9 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
|
||||||
// adjust the driver theoretical schedule :
|
// adjust the driver theoretical schedule :
|
||||||
// we guess the ideal driver departure time based on the duration to
|
// we guess the ideal driver departure time based on the duration to
|
||||||
// reach the passenger starting point from the driver starting point
|
// reach the passenger starting point from the driver starting point
|
||||||
driverSchedule = driverSchedule.map(
|
driverSchedule = driverSchedule
|
||||||
(scheduleItemProps: ScheduleItemProps) => {
|
.map((scheduleItemProps: ScheduleItemProps) => {
|
||||||
|
try {
|
||||||
const driverDate: Date = CalendarTools.firstDate(
|
const driverDate: Date = CalendarTools.firstDate(
|
||||||
scheduleItemProps.day,
|
scheduleItemProps.day,
|
||||||
this.props.dateInterval,
|
this.props.dateInterval,
|
||||||
|
@ -117,7 +119,7 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
|
||||||
scheduleItemProps.time,
|
scheduleItemProps.time,
|
||||||
-this._passengerStartDuration(),
|
-this._passengerStartDuration(),
|
||||||
);
|
);
|
||||||
return {
|
return <ScheduleItemProps>{
|
||||||
day: driverDate.getUTCDay(),
|
day: driverDate.getUTCDay(),
|
||||||
margin: scheduleItemProps.margin,
|
margin: scheduleItemProps.margin,
|
||||||
time: `${driverStartDatetime
|
time: `${driverStartDatetime
|
||||||
|
@ -128,7 +130,15 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
|
||||||
.toString()
|
.toString()
|
||||||
.padStart(2, '0')}`,
|
.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(
|
this.props.driverSchedule = driverSchedule.map(
|
||||||
(scheduleItemProps: ScheduleItemProps) => ({
|
(scheduleItemProps: ScheduleItemProps) => ({
|
||||||
|
@ -159,7 +169,8 @@ 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 => {
|
||||||
let passengerSchedule: ScheduleItemProps[] = this.props.driverSchedule!.map(
|
let passengerSchedule: Array<ScheduleItemProps | undefined> =
|
||||||
|
this.props.driverSchedule!.map(
|
||||||
(scheduleItemProps: ScheduleItemProps) => ({
|
(scheduleItemProps: ScheduleItemProps) => ({
|
||||||
day: scheduleItemProps.day,
|
day: scheduleItemProps.day,
|
||||||
time: scheduleItemProps.time,
|
time: scheduleItemProps.time,
|
||||||
|
@ -169,8 +180,9 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
|
||||||
// adjust the passenger theoretical schedule :
|
// adjust the passenger theoretical schedule :
|
||||||
// we guess the ideal passenger departure time based on the duration to
|
// we guess the ideal passenger departure time based on the duration to
|
||||||
// reach the passenger starting point from the driver starting point
|
// reach the passenger starting point from the driver starting point
|
||||||
passengerSchedule = passengerSchedule.map(
|
passengerSchedule = passengerSchedule
|
||||||
(scheduleItemProps: ScheduleItemProps) => {
|
.map((scheduleItemProps: ScheduleItemProps) => {
|
||||||
|
try {
|
||||||
const passengerDate: Date = CalendarTools.firstDate(
|
const passengerDate: Date = CalendarTools.firstDate(
|
||||||
scheduleItemProps.day,
|
scheduleItemProps.day,
|
||||||
this.props.dateInterval,
|
this.props.dateInterval,
|
||||||
|
@ -191,7 +203,15 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
|
||||||
.toString()
|
.toString()
|
||||||
.padStart(2, '0')}`,
|
.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(
|
this.props.passengerSchedule = passengerSchedule.map(
|
||||||
(scheduleItemProps: ScheduleItemProps) => ({
|
(scheduleItemProps: ScheduleItemProps) => ({
|
||||||
|
|
Loading…
Reference in New Issue