2026-04-14-8 auth and commercial 0

This commit is contained in:
Hamza-Ayed
2026-04-14 21:49:08 +03:00
parent f5b3f9f790
commit 50573eb9d3
2 changed files with 12 additions and 6 deletions
+4 -1
View File
@@ -43,7 +43,10 @@ export class MapsController {
}
const profile = query.profile || 'car';
return this.mapsService.getRoute(waypoints, profile);
const steps = query.steps === 'true';
const locale = query.locale || 'en';
return this.mapsService.getRoute(waypoints, profile, steps, locale);
}
@Get('config')
+8 -5
View File
@@ -22,7 +22,7 @@ export class MapsService {
this.graphHopperUrl = this.configService.get('GRAPH_HOPPER_URL', 'http://routing:8080');
}
async getRoute(waypoints: [number, number][], profile: string = 'car') {
async getRoute(waypoints: [number, number][], profile: string = 'car', steps: boolean = false, locale: string = 'en') {
if (waypoints.length < 2) {
throw new HttpException('At least two waypoints are required', HttpStatus.BAD_REQUEST);
}
@@ -57,9 +57,10 @@ export class MapsService {
const payload: any = {
points: ghPoints,
profile: profile,
locale: 'en',
locale: locale,
calc_points: true,
points_encoded: true,
instructions: steps,
};
// GraphHopper ONLY supports alternative routes if there are exactly 2 points (Start and End)
@@ -71,7 +72,7 @@ export class MapsService {
payload['alternative_route.max_share_factor'] = 0.6;
}
console.log(`Routing Request: ${waypoints.length} points via ${profile} on ${this.graphHopperUrl}`);
console.log(`Routing Request: ${waypoints.length} points via ${profile} on ${this.graphHopperUrl} | Steps: ${steps} | Locale: ${locale}`);
const response = await axios.post(`${this.graphHopperUrl}/route`, payload, { timeout: 10000 });
console.log('Routing SUCCESS');
@@ -96,7 +97,8 @@ export class MapsService {
distance: alt.distance,
duration: Math.round(alt.time / 1000),
points: alt.points,
bbox: alt.bbox
bbox: alt.bbox,
instructions: alt.instructions // Include instructions for alternatives if requested
}));
return {
@@ -108,7 +110,8 @@ export class MapsService {
endName,
points: route.points,
bbox: route.bbox,
alternatives: alternatives // NEW: array of other routes
instructions: route.instructions, // Added: turn-by-turn maneuvers
alternatives: alternatives
};
} catch (error) {
const msg = error.response ? `GH Error: ${JSON.stringify(error.response.data)}` : `DNS/Connection Error: ${error.message}`;