Take care of candidate processing peculiarities of having pax and driver depart on different day
This commit is contained in:
parent
3c65582d8e
commit
e2beba299b
|
@ -1,6 +1,7 @@
|
||||||
import { AdEntity } from '@modules/ad/core/domain/ad.entity';
|
import { AdEntity } from '@modules/ad/core/domain/ad.entity';
|
||||||
import { Frequency, Role } from '@modules/ad/core/domain/ad.types';
|
import { Frequency, Role } from '@modules/ad/core/domain/ad.types';
|
||||||
import { CandidateEntity } from '@modules/ad/core/domain/candidate.entity';
|
import { CandidateEntity } from '@modules/ad/core/domain/candidate.entity';
|
||||||
|
import { DateInterval } from '../../../../domain/candidate.types';
|
||||||
import { Point } from '../../../types/point.type';
|
import { Point } from '../../../types/point.type';
|
||||||
import { Waypoint } from '../../../types/waypoint.type';
|
import { Waypoint } from '../../../types/waypoint.type';
|
||||||
import { Selector } from '../algorithm.abstract';
|
import { Selector } from '../algorithm.abstract';
|
||||||
|
@ -46,7 +47,7 @@ export class PassengerOrientedSelector extends Selector {
|
||||||
id: adEntity.id,
|
id: adEntity.id,
|
||||||
role: adsRole.role == Role.DRIVER ? Role.PASSENGER : Role.DRIVER,
|
role: adsRole.role == Role.DRIVER ? Role.PASSENGER : Role.DRIVER,
|
||||||
frequency: adEntity.getProps().frequency,
|
frequency: adEntity.getProps().frequency,
|
||||||
dateInterval: {
|
dateInterval: this._fixDateInterval({
|
||||||
lowerDate: this._maxDateString(
|
lowerDate: this._maxDateString(
|
||||||
this.query.fromDate,
|
this.query.fromDate,
|
||||||
adEntity.getProps().fromDate,
|
adEntity.getProps().fromDate,
|
||||||
|
@ -55,7 +56,7 @@ export class PassengerOrientedSelector extends Selector {
|
||||||
this.query.toDate,
|
this.query.toDate,
|
||||||
adEntity.getProps().toDate,
|
adEntity.getProps().toDate,
|
||||||
),
|
),
|
||||||
},
|
}),
|
||||||
driverWaypoints:
|
driverWaypoints:
|
||||||
adsRole.role == Role.PASSENGER
|
adsRole.role == Role.PASSENGER
|
||||||
? adEntity.getProps().waypoints
|
? adEntity.getProps().waypoints
|
||||||
|
@ -297,11 +298,26 @@ export class PassengerOrientedSelector extends Selector {
|
||||||
azimuth + margin > 360 ? azimuth + margin - 360 : azimuth + margin,
|
azimuth + margin > 360 ? azimuth + margin - 360 : azimuth + margin,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//TODO If the dates are always formatted with '%Y-%m-%d', no conversion to Date is needed
|
||||||
private _maxDateString = (date1: string, date2: string): string =>
|
private _maxDateString = (date1: string, date2: string): string =>
|
||||||
new Date(date1) > new Date(date2) ? date1 : date2;
|
new Date(date1) > new Date(date2) ? date1 : date2;
|
||||||
|
|
||||||
private _minDateString = (date1: string, date2: string): string =>
|
private _minDateString = (date1: string, date2: string): string =>
|
||||||
new Date(date1) < new Date(date2) ? date1 : date2;
|
new Date(date1) < new Date(date2) ? date1 : date2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When a punctual ad matches a punctual query, it may be on a different date than the query
|
||||||
|
* (for routes by night), and the range produced by _minDateString and _maxDateString is not correct.
|
||||||
|
* This function fixes that by inverting the dates if necessary.
|
||||||
|
*/
|
||||||
|
private _fixDateInterval(interval: DateInterval): DateInterval {
|
||||||
|
if (interval.lowerDate > interval.higherDate) {
|
||||||
|
const tmp = interval.lowerDate;
|
||||||
|
interval.lowerDate = interval.higherDate;
|
||||||
|
interval.higherDate = tmp;
|
||||||
|
}
|
||||||
|
return interval;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type QueryStringRole = {
|
export type QueryStringRole = {
|
||||||
|
|
|
@ -323,7 +323,7 @@ export class CandidateEntity extends AggregateRoot<CandidateProps> {
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Use this class as part of the CandidateEntity aggregate
|
//TODO Use this class as part of the CandidateEntity aggregate
|
||||||
class Schedule extends ValueObject<{
|
export class Schedule extends ValueObject<{
|
||||||
items: ScheduleItemProps[];
|
items: ScheduleItemProps[];
|
||||||
dateInterval: DateInterval;
|
dateInterval: DateInterval;
|
||||||
}> {
|
}> {
|
||||||
|
|
Loading…
Reference in New Issue