diff --git a/backend/src/middleware/nodes/locations.js b/backend/src/middleware/nodes/locations.js index d7abb90ff..a90d8c0d7 100644 --- a/backend/src/middleware/nodes/locations.js +++ b/backend/src/middleware/nodes/locations.js @@ -1,9 +1,12 @@ import request from 'request' import { UserInputError } from 'apollo-server' import isEmpty from 'lodash/isEmpty' +import Debug from 'debug' import asyncForEach from '../../helpers/asyncForEach' import CONFIG from './../../config' +const debug = Debug('human-connection:location') + const fetch = url => { return new Promise((resolve, reject) => { request(url, function(error, response, body) { @@ -59,6 +62,7 @@ const createOrUpdateLocations = async (userId, locationName, driver) => { if (isEmpty(locationName)) { return } + const res = await fetch( `https://api.mapbox.com/geocoding/v5/mapbox.places/${encodeURIComponent( locationName, @@ -67,6 +71,8 @@ const createOrUpdateLocations = async (userId, locationName, driver) => { )}`, ) + debug(res) + if (!res || !res.features || !res.features[0]) { throw new UserInputError('locationName is invalid') } diff --git a/webapp/pages/settings/index.vue b/webapp/pages/settings/index.vue index 4ad57b49c..5c99f4b8b 100644 --- a/webapp/pages/settings/index.vue +++ b/webapp/pages/settings/index.vue @@ -101,7 +101,7 @@ export default { async submit() { this.loadingData = true const { name, about } = this.formData - let { locationName } = this.formData + let { locationName } = this.formData || this.currentUser locationName = locationName && (locationName['label'] || locationName) try { await this.$apollo.mutate({ @@ -159,7 +159,6 @@ export default { this.cities = [] return } - this.loadingGeo = true this.axiosSource = CancelToken.source()