2026-04-12-1

This commit is contained in:
Hamza-Ayed
2026-04-12 22:35:38 +03:00
parent e3799c422c
commit 5ebd7ea3b1
84 changed files with 532 additions and 5136 deletions
+34 -8
View File
@@ -10,14 +10,40 @@ export class MapsController {
constructor(private readonly mapsService: MapsService) {}
@Get('route')
@ApiOperation({ summary: 'Calculate a route between two points 🚗' })
async getRoute(
@Query('fromLat') fromLat: number,
@Query('fromLng') fromLng: number,
@Query('toLat') toLat: number,
@Query('toLng') toLng: number,
) {
return this.mapsService.getRoute([fromLat, fromLng], [toLat, toLng]);
@ApiOperation({ summary: 'Calculate a route with dynamic waypoints 🚗' })
async getRoute(@Query() query: any) {
const waypoints: [number, number][] = [];
// 1. Extract Origin (fromLat, fromLng)
if (query.fromLat && query.fromLng) {
waypoints.push([parseFloat(query.fromLat), parseFloat(query.fromLng)]);
}
// 2. Extract Intermediate Stops (stop1Lat, stop1Lng, stop2Lat, etc.)
// We sort keys to ensure stops are in order: stop1, stop2, stop3...
const stopKeys = Object.keys(query)
.filter(key => key.startsWith('stop') && key.endsWith('Lat'))
.sort((a, b) => {
const numA = parseInt(a.replace('stop', '').replace('Lat', ''), 10);
const numB = parseInt(b.replace('stop', '').replace('Lat', ''), 10);
return numA - numB;
});
for (const latKey of stopKeys) {
const prefix = latKey.replace('Lat', '');
const lngKey = `${prefix}Lng`;
if (query[latKey] && query[lngKey]) {
waypoints.push([parseFloat(query[latKey]), parseFloat(query[lngKey])]);
}
}
// 3. Extract Destination (toLat, toLng)
if (query.toLat && query.toLng) {
waypoints.push([parseFloat(query.toLat), parseFloat(query.toLng)]);
}
const profile = query.profile || 'car';
return this.mapsService.getRoute(waypoints, profile);
}
@Get('config')