From cba5d88c5e36c92f7a35d6c48091cc0754f8e83f Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 9 Dec 2024 14:45:31 +0100 Subject: [PATCH] feat: refs #7882 Osrm service --- back/methods/osrm-config/optimize.js | 20 ++++++++++++--- .../route/back/methods/route/optimizeStops.js | 25 +++++++++++++++++++ modules/route/back/models/route.js | 1 + 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 modules/route/back/methods/route/optimizeStops.js diff --git a/back/methods/osrm-config/optimize.js b/back/methods/osrm-config/optimize.js index a7c81f33a..0c570b95a 100644 --- a/back/methods/osrm-config/optimize.js +++ b/back/methods/osrm-config/optimize.js @@ -27,19 +27,31 @@ module.exports = Self => { if (!osrmConfig) throw new UserError(`OSRM service is not configured`); let coords = []; - for (const addressId of addressIds) { - const address = await models.Address.findById(addressId); + + const address = await models.Address.findById(32308); // Aquí irá el address asociada a la zona + if (address.latitude && address.longitude) { coords.push({ - addressId, + addressId: address.id, latitude: address.latitude.toFixed(6), longitude: address.longitude.toFixed(6) }); } + + for (const addressId of addressIds) { + const address = await models.Address.findById(addressId); + if (address.latitude && address.longitude) { + coords.push({ + addressId, + latitude: address.latitude.toFixed(6), + longitude: address.longitude.toFixed(6) + }); + } + } const concatCoords = coords .map(coord => `${coord.longitude},${coord.latitude}`) .join(';'); const response = await axios.post(` - ${osrmConfig.url}/trip/v1/driving/${concatCoords} + ${osrmConfig.url}/trip/v1/driving/${concatCoords}?source=first&roundtrip=true `); const tolerance = osrmConfig.tolerance; for (waypoint of response.data.waypoints) { diff --git a/modules/route/back/methods/route/optimizeStops.js b/modules/route/back/methods/route/optimizeStops.js new file mode 100644 index 000000000..9666f201e --- /dev/null +++ b/modules/route/back/methods/route/optimizeStops.js @@ -0,0 +1,25 @@ +module.exports = Self => { + Self.remoteMethod('optimizeStops', { + description: 'Updates the ticket priority of tickets without priority', + accepts: [ + { + arg: 'routeFk', + type: 'number', + required: true + } + ], + returns: { + type: 'object', + root: true + }, + http: { + path: '/optimizeStops', + verb: 'post' + } + }); + + Self.optimizeStops = async(routeFk, options) => { + return; + }; +}; + diff --git a/modules/route/back/models/route.js b/modules/route/back/models/route.js index cd8685cec..e28b19a61 100644 --- a/modules/route/back/models/route.js +++ b/modules/route/back/models/route.js @@ -16,4 +16,5 @@ module.exports = Self => { require('../methods/route/downloadZip')(Self); require('../methods/route/getExpeditionSummary')(Self); require('../methods/route/getByWorker')(Self); + require('../methods/route/optimizeStops')(Self); };