diff --git a/src/modules/ad/core/application/queries/match/selector/passenger-oriented.selector.ts b/src/modules/ad/core/application/queries/match/selector/passenger-oriented.selector.ts index 4116167..2239f0d 100644 --- a/src/modules/ad/core/application/queries/match/selector/passenger-oriented.selector.ts +++ b/src/modules/ad/core/application/queries/match/selector/passenger-oriented.selector.ts @@ -19,7 +19,6 @@ export class PassengerOrientedSelector extends Selector { query: this._createQueryString(Role.PASSENGER), role: Role.PASSENGER, }); - return ( await Promise.all( queryStringRoles.map>( @@ -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,