mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2026-01-01 06:22:40 +00:00
update passenger oriented selector to handle empty schedule; improve punctual where part
This commit is contained in:
@@ -19,7 +19,6 @@ export class PassengerOrientedSelector extends Selector {
|
||||
query: this._createQueryString(Role.PASSENGER),
|
||||
role: Role.PASSENGER,
|
||||
});
|
||||
|
||||
return (
|
||||
await Promise.all(
|
||||
queryStringRoles.map<Promise<AdsRole>>(
|
||||
@@ -74,7 +73,7 @@ export class PassengerOrientedSelector extends Selector {
|
||||
driverSchedule:
|
||||
adsRole.role == Role.PASSENGER
|
||||
? adEntity.getProps().schedule
|
||||
: this.query.schedule.map((scheduleItem: ScheduleItem) => ({
|
||||
: this.query.schedule?.map((scheduleItem: ScheduleItem) => ({
|
||||
day: scheduleItem.day as number,
|
||||
time: scheduleItem.time,
|
||||
margin: scheduleItem.margin as number,
|
||||
@@ -82,7 +81,7 @@ export class PassengerOrientedSelector extends Selector {
|
||||
passengerSchedule:
|
||||
adsRole.role == Role.DRIVER
|
||||
? adEntity.getProps().schedule
|
||||
: this.query.schedule.map((scheduleItem: ScheduleItem) => ({
|
||||
: this.query.schedule?.map((scheduleItem: ScheduleItem) => ({
|
||||
day: scheduleItem.day as number,
|
||||
time: scheduleItem.time,
|
||||
margin: scheduleItem.margin as number,
|
||||
@@ -155,7 +154,9 @@ export class PassengerOrientedSelector extends Selector {
|
||||
: '';
|
||||
|
||||
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\
|
||||
"toDate" >= '${this.query.toDate}' AND "toDate" >= '${this.query.fromDate}'\
|
||||
@@ -172,6 +173,8 @@ export class PassengerOrientedSelector extends Selector {
|
||||
)`;
|
||||
|
||||
private _whereSchedule = (role: Role): string => {
|
||||
// no schedule filtering if schedule is not set
|
||||
if (this.query.schedule === undefined) return '';
|
||||
const schedule: string[] = [];
|
||||
// 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)
|
||||
@@ -182,7 +185,7 @@ export class PassengerOrientedSelector extends Selector {
|
||||
// - then we compare each resulting day of the schedule with each day of calendar,
|
||||
// adding / removing margin depending on the role
|
||||
scheduleDates.map((date: Date) => {
|
||||
this.query.schedule
|
||||
(this.query.schedule as ScheduleItem[])
|
||||
.filter(
|
||||
(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 = (
|
||||
firstDate: string,
|
||||
lastDate: string,
|
||||
|
||||
Reference in New Issue
Block a user