8355-testToMaster #3336

Merged
alexm merged 241 commits from 8355-testToMaster into master 2025-01-07 06:44:57 +00:00
3 changed files with 19 additions and 9 deletions
Showing only changes of commit 0bb9282953 - Show all commits

View File

@ -38,7 +38,9 @@ module.exports = Self => {
const concatCoords = coords const concatCoords = coords
.map(coord => `${coord.longitude},${coord.latitude}`) .map(coord => `${coord.longitude},${coord.latitude}`)
.join(';'); .join(';');
const response = await axios.post(`${locationiqConfig.url}${concatCoords}?key=${locationiqConfig.key}`); const response = await axios.post(`
${locationiqConfig.url}optimize/driving/${concatCoords}?key=${locationiqConfig.key}
`);
const tolerance = locationiqConfig.tolerance; const tolerance = locationiqConfig.tolerance;
for (waypoint of response.data.waypoints) { for (waypoint of response.data.waypoints) {
@ -46,10 +48,14 @@ module.exports = Self => {
const latitude = waypoint.location[1]; const latitude = waypoint.location[1];
const matchedAddress = coords.find(coord => const matchedAddress = coords.find(coord =>
!coord.position &&
Math.abs(coord.latitude - latitude) <= tolerance && Math.abs(coord.latitude - latitude) <= tolerance &&
Math.abs(coord.longitude - longitude) <= tolerance Math.abs(coord.longitude - longitude) <= tolerance
); );
if (matchedAddress) matchedAddress.position = waypoint.waypoint_index; if (matchedAddress)
matchedAddress.position = waypoint.waypoint_index;
else
console.log(`Las coordenadas no se han podido asociar: ${latitude} | ${longitude}`);
} }
coords.sort((a, b) => { coords.sort((a, b) => {
const posA = a.position !== undefined ? a.position : Infinity; const posA = a.position !== undefined ? a.position : Infinity;
@ -58,9 +64,9 @@ module.exports = Self => {
}); });
// Temporal para abrir en maps // Temporal para abrir en maps
const coordsString = coords const coordsString = coords
.map(item => `${item.latitude},${item.longitude}`) .map(item => `point=${item.latitude},${item.longitude}`)
.join('/'); .join('&');
console.log(`https://www.google.es/maps/dir/${coordsString}`); console.log(`https://graphhopper.com/maps/?${coordsString}&profile=small_truck`);
// --------- // ---------
return coords; return coords;
} catch (err) { } catch (err) {
@ -69,6 +75,8 @@ module.exports = Self => {
throw new UserError('No trips found because input coordinates are not connected'); throw new UserError('No trips found because input coordinates are not connected');
case 'NotImplemented': case 'NotImplemented':
throw new UserError('This request is not supported'); throw new UserError('This request is not supported');
case 'InvalidOptions':
throw new UserError('Invalid options or too many coordinates');
default: default:
throw err; throw err;
} }

View File

@ -1,8 +1,9 @@
CREATE TABLE `vn`.`locationiqConfig` ( CREATE TABLE `vn`.`locationiqConfig` (
`id` int(10) unsigned NOT NULL, `id` int(10) unsigned NOT NULL,
`url` varchar(100) NOT NULL, `url` varchar(100) NOT NULL COMMENT 'Dirección base de la API',
`key` varchar(100) NOT NULL, `key` varchar(100) NOT NULL COMMENT 'Access token',
`tolerance` decimal(6,6) NOT NULL DEFAULT 0, `tolerance` decimal(6,6) NOT NULL DEFAULT 0 COMMENT 'Tolerancia entre las coordenadas enviadas y las retornadas',
`maxCoordsRequest` int(10) unsigned DEFAULT NULL COMMENT 'Número máximo de coordenadas por petición',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
CONSTRAINT `locationiqConfig_check` CHECK (`id` = 1) CONSTRAINT `locationiqConfig_check` CHECK (`id` = 1)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;

View File

@ -392,5 +392,6 @@
"The raid information is not correct": "La información de la redada no es correcta", "The raid information is not correct": "La información de la redada no es correcta",
"There are tickets to be invoiced": "Hay tickets para esta zona, borralos primero", "There are tickets to be invoiced": "Hay tickets para esta zona, borralos primero",
"No trips found because input coordinates are not connected": "No se encontraron rutas porque las coordenadas de entrada no están conectadas", "No trips found because input coordinates are not connected": "No se encontraron rutas porque las coordenadas de entrada no están conectadas",
"This request is not supported": "Esta solicitud no es compatible" "This request is not supported": "Esta solicitud no es compatible",
"Invalid options or too many coordinates": "Opciones invalidas o demasiadas coordenadas"
} }