8355-testToMaster #3336
|
@ -23,8 +23,8 @@ module.exports = Self => {
|
|||
Self.optimize = async addressIds => {
|
||||
const models = Self.app.models;
|
||||
try {
|
||||
const locationiqConfig = await models.LocationiqConfig.findOne();
|
||||
if (!locationiqConfig) throw new UserError(`LocationIQ service is not configured`);
|
||||
const osrmConfig = await models.OsrmConfig.findOne();
|
||||
if (!osrmConfig) throw new UserError(`OSRM service is not configured`);
|
||||
|
||||
let coords = [];
|
||||
for (const addressId of addressIds) {
|
||||
|
@ -39,10 +39,9 @@ module.exports = Self => {
|
|||
.map(coord => `${coord.longitude},${coord.latitude}`)
|
||||
.join(';');
|
||||
const response = await axios.post(`
|
||||
${locationiqConfig.url}optimize/driving/${concatCoords}?key=${locationiqConfig.key}
|
||||
${osrmConfig.url}/trip/v1/driving/${concatCoords}
|
||||
`);
|
||||
const tolerance = locationiqConfig.tolerance;
|
||||
|
||||
const tolerance = osrmConfig.tolerance;
|
||||
for (waypoint of response.data.waypoints) {
|
||||
const longitude = waypoint.location[0];
|
||||
const latitude = waypoint.location[1];
|
|
@ -88,7 +88,7 @@
|
|||
"Language": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"LocationiqConfig": {
|
||||
"OsrmConfig": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"Machine": {
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/locationiq-config/optimize')(Self);
|
||||
};
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/osrm-config/optimize')(Self);
|
||||
};
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"name": "LocationiqConfig",
|
||||
"name": "OsrmConfig",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "locationiqConfig"
|
||||
"table": "osrmConfig"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
|
@ -16,10 +16,6 @@
|
|||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
"key": {
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
"tolerance": {
|
||||
"type": "number",
|
||||
"required": false
|
|
@ -1,9 +1,7 @@
|
|||
CREATE TABLE `vn`.`locationiqConfig` (
|
||||
CREATE TABLE `vn`.`osrmConfig` (
|
||||
`id` int(10) unsigned NOT NULL,
|
||||
`url` varchar(100) NOT NULL COMMENT 'Dirección base de la API',
|
||||
`key` varchar(100) NOT NULL COMMENT 'Access token',
|
||||
`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`),
|
||||
CONSTRAINT `locationiqConfig_check` CHECK (`id` = 1)
|
||||
CONSTRAINT `osrmConfig_check` CHECK (`id` = 1)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
Loading…
Reference in New Issue