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