"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MapsController = void 0; const common_1 = require("@nestjs/common"); const swagger_1 = require("@nestjs/swagger"); const maps_service_1 = require("./maps.service"); const api_key_guard_1 = require("../common/guards/api-key.guard"); let MapsController = class MapsController { mapsService; constructor(mapsService) { this.mapsService = mapsService; } async getRoute(query) { const waypoints = []; if (query.fromLat && query.fromLng) { waypoints.push([parseFloat(query.fromLat), parseFloat(query.fromLng)]); } 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])]); } } if (query.toLat && query.toLng) { waypoints.push([parseFloat(query.toLat), parseFloat(query.toLng)]); } const profile = query.profile || 'car'; return this.mapsService.getRoute(waypoints, profile); } async getConfig() { return this.mapsService.getMapConfig(); } }; exports.MapsController = MapsController; __decorate([ (0, common_1.Get)('route'), (0, swagger_1.ApiOperation)({ summary: 'Calculate a route with dynamic waypoints πŸš—' }), __param(0, (0, common_1.Query)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], MapsController.prototype, "getRoute", null); __decorate([ (0, common_1.Get)('config'), (0, swagger_1.ApiOperation)({ summary: 'Get map configuration for the region πŸ—ΊοΈ' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], MapsController.prototype, "getConfig", null); exports.MapsController = MapsController = __decorate([ (0, swagger_1.ApiTags)('maps'), (0, common_1.Controller)('maps'), (0, common_1.UseGuards)(api_key_guard_1.ApiKeyGuard), __metadata("design:paramtypes", [maps_service_1.MapsService]) ], MapsController); //# sourceMappingURL=maps.controller.js.map