update passenger oriented selector to handle empty schedule; improve punctual where part
This commit is contained in:
parent
6b9bf53b4a
commit
90ae3cf9cb
|
@ -19,7 +19,6 @@ export class PassengerOrientedSelector extends Selector {
|
||||||
query: this._createQueryString(Role.PASSENGER),
|
query: this._createQueryString(Role.PASSENGER),
|
||||||
role: Role.PASSENGER,
|
role: Role.PASSENGER,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
queryStringRoles.map<Promise<AdsRole>>(
|
queryStringRoles.map<Promise<AdsRole>>(
|
||||||
|
@ -74,7 +73,7 @@ export class PassengerOrientedSelector extends Selector {
|
||||||
driverSchedule:
|
driverSchedule:
|
||||||
adsRole.role == Role.PASSENGER
|
adsRole.role == Role.PASSENGER
|
||||||
? adEntity.getProps().schedule
|
? adEntity.getProps().schedule
|
||||||
: this.query.schedule.map((scheduleItem: ScheduleItem) => ({
|
: this.query.schedule?.map((scheduleItem: ScheduleItem) => ({
|
||||||
day: scheduleItem.day as number,
|
day: scheduleItem.day as number,
|
||||||
time: scheduleItem.time,
|
time: scheduleItem.time,
|
||||||
margin: scheduleItem.margin as number,
|
margin: scheduleItem.margin as number,
|
||||||
|
@ -82,7 +81,7 @@ export class PassengerOrientedSelector extends Selector {
|
||||||
passengerSchedule:
|
passengerSchedule:
|
||||||
adsRole.role == Role.DRIVER
|
adsRole.role == Role.DRIVER
|
||||||
? adEntity.getProps().schedule
|
? adEntity.getProps().schedule
|
||||||
: this.query.schedule.map((scheduleItem: ScheduleItem) => ({
|
: this.query.schedule?.map((scheduleItem: ScheduleItem) => ({
|
||||||
day: scheduleItem.day as number,
|
day: scheduleItem.day as number,
|
||||||
time: scheduleItem.time,
|
time: scheduleItem.time,
|
||||||
margin: scheduleItem.margin as number,
|
margin: scheduleItem.margin as number,
|
||||||
|
@ -155,7 +154,9 @@ export class PassengerOrientedSelector extends Selector {
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
private _whereDate = (): string =>
|
private _whereDate = (): string =>
|
||||||
`(\
|
this.query.frequency == Frequency.PUNCTUAL
|
||||||
|
? `("fromDate" <= '${this.query.fromDate}' AND "toDate" >= '${this.query.fromDate}')`
|
||||||
|
: `(\
|
||||||
(\
|
(\
|
||||||
"fromDate" <= '${this.query.fromDate}' AND "fromDate" <= '${this.query.toDate}' AND\
|
"fromDate" <= '${this.query.fromDate}' AND "fromDate" <= '${this.query.toDate}' AND\
|
||||||
"toDate" >= '${this.query.toDate}' AND "toDate" >= '${this.query.fromDate}'\
|
"toDate" >= '${this.query.toDate}' AND "toDate" >= '${this.query.fromDate}'\
|
||||||
|
@ -172,6 +173,8 @@ export class PassengerOrientedSelector extends Selector {
|
||||||
)`;
|
)`;
|
||||||
|
|
||||||
private _whereSchedule = (role: Role): string => {
|
private _whereSchedule = (role: Role): string => {
|
||||||
|
// no schedule filtering if schedule is not set
|
||||||
|
if (this.query.schedule === undefined) return '';
|
||||||
const schedule: string[] = [];
|
const schedule: string[] = [];
|
||||||
// we need full dates to compare times, because margins can lead to compare on previous or next day
|
// we need full dates to compare times, because margins can lead to compare on previous or next day
|
||||||
// - first we establish a base calendar (up to a week)
|
// - first we establish a base calendar (up to a week)
|
||||||
|
@ -182,7 +185,7 @@ export class PassengerOrientedSelector extends Selector {
|
||||||
// - then we compare each resulting day of the schedule with each day of calendar,
|
// - then we compare each resulting day of the schedule with each day of calendar,
|
||||||
// adding / removing margin depending on the role
|
// adding / removing margin depending on the role
|
||||||
scheduleDates.map((date: Date) => {
|
scheduleDates.map((date: Date) => {
|
||||||
this.query.schedule
|
(this.query.schedule as ScheduleItem[])
|
||||||
.filter(
|
.filter(
|
||||||
(scheduleItem: ScheduleItem) => date.getUTCDay() == scheduleItem.day,
|
(scheduleItem: ScheduleItem) => date.getUTCDay() == scheduleItem.day,
|
||||||
)
|
)
|
||||||
|
@ -310,6 +313,11 @@ export class PassengerOrientedSelector extends Selector {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of dates containing all the dates (limited to 7 by default) between 2 boundary dates.
|
||||||
|
*
|
||||||
|
* The array length can be limited to a _max_ number of dates (default: 7)
|
||||||
|
*/
|
||||||
private _datesBetweenBoundaries = (
|
private _datesBetweenBoundaries = (
|
||||||
firstDate: string,
|
firstDate: string,
|
||||||
lastDate: string,
|
lastDate: string,
|
||||||
|
|
Loading…
Reference in New Issue