extract carpool informations from geography module

This commit is contained in:
sbriat 2023-09-07 14:31:32 +02:00
parent d1a314f011
commit 6b4ac1792c
1 changed files with 14 additions and 14 deletions

View File

@ -18,7 +18,7 @@ export class CarpoolRouteProvider implements CarpoolRouteProviderPort {
roles: Role[],
waypoints: Waypoint[],
): Promise<CarpoolRoute> => {
const paths: Path[] = this.getPaths(roles, waypoints);
const paths: Path[] = this._getPaths(roles, waypoints);
const typeRoutes: TypeRoute[] = await Promise.all(
paths.map(
async (path: Path) =>
@ -77,39 +77,39 @@ export class CarpoolRouteProvider implements CarpoolRouteProviderPort {
};
};
private getPaths = (roles: Role[], waypoints: Waypoint[]): Path[] => {
private _getPaths = (roles: Role[], waypoints: Waypoint[]): Path[] => {
const paths: Path[] = [];
if (roles.includes(Role.DRIVER) && roles.includes(Role.PASSENGER)) {
if (waypoints.length == 2) {
// 2 points => same route for driver and passenger
paths.push(this.createGenericPath(waypoints));
paths.push(this._createGenericPath(waypoints));
} else {
paths.push(
this.createDriverPath(waypoints),
this.createPassengerPath(waypoints),
this._createDriverPath(waypoints),
this._createPassengerPath(waypoints),
);
}
} else if (roles.includes(Role.DRIVER)) {
paths.push(this.createDriverPath(waypoints));
paths.push(this._createDriverPath(waypoints));
} else if (roles.includes(Role.PASSENGER)) {
paths.push(this.createPassengerPath(waypoints));
paths.push(this._createPassengerPath(waypoints));
}
return paths;
};
private createGenericPath = (waypoints: Waypoint[]): Path =>
this.createPath(waypoints, PathType.GENERIC);
private _createGenericPath = (waypoints: Waypoint[]): Path =>
this._createPath(waypoints, PathType.GENERIC);
private createDriverPath = (waypoints: Waypoint[]): Path =>
this.createPath(waypoints, PathType.DRIVER);
private _createDriverPath = (waypoints: Waypoint[]): Path =>
this._createPath(waypoints, PathType.DRIVER);
private createPassengerPath = (waypoints: Waypoint[]): Path =>
this.createPath(
private _createPassengerPath = (waypoints: Waypoint[]): Path =>
this._createPath(
[waypoints[0], waypoints[waypoints.length - 1]],
PathType.PASSENGER,
);
private createPath = (waypoints: Waypoint[], type: PathType): Path => ({
private _createPath = (waypoints: Waypoint[], type: PathType): Path => ({
type,
waypoints,
});