From d9e553b800bc4bb48450472c2d50a74ead13c0ae Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 30 Jan 2021 00:18:26 +0100 Subject: [PATCH 01/14] - backend implementation location query --- backend/src/middleware/permissionsMiddleware.js | 1 + backend/src/schema/resolvers/locations.js | 11 +++++++++++ backend/src/schema/resolvers/users/location.js | 10 ++++++++++ backend/src/schema/types/{ => type}/Location.gql | 9 +++++++++ 4 files changed, 31 insertions(+) rename backend/src/schema/types/{ => type}/Location.gql (71%) diff --git a/backend/src/middleware/permissionsMiddleware.js b/backend/src/middleware/permissionsMiddleware.js index 6fe82951e..dae6f0e48 100644 --- a/backend/src/middleware/permissionsMiddleware.js +++ b/backend/src/middleware/permissionsMiddleware.js @@ -121,6 +121,7 @@ export default shield( userData: isAuthenticated, MyInviteCodes: isAuthenticated, isValidInviteCode: allow, + queryLocations: isAuthenticated, }, Mutation: { '*': deny, diff --git a/backend/src/schema/resolvers/locations.js b/backend/src/schema/resolvers/locations.js index be72001f7..fa0feafa1 100644 --- a/backend/src/schema/resolvers/locations.js +++ b/backend/src/schema/resolvers/locations.js @@ -1,4 +1,6 @@ +import { UserInputError } from 'apollo-server' import Resolver from './helpers/Resolver' +import { queryLocations } from './users/location' export default { Location: { @@ -16,4 +18,13 @@ export default { ], }), }, + Query: { + queryLocations: async (object, args, context, resolveInfo) => { + try { + return queryLocations(args) + } catch (e) { + throw new UserInputError(e.message) + } + }, + }, } diff --git a/backend/src/schema/resolvers/users/location.js b/backend/src/schema/resolvers/users/location.js index b58d8d1aa..70372e548 100644 --- a/backend/src/schema/resolvers/users/location.js +++ b/backend/src/schema/resolvers/users/location.js @@ -137,4 +137,14 @@ const createOrUpdateLocations = async (userId, locationName, session) => { }) } +export const queryLocations = async ({place, lang}) => { + const res = await fetch(`https://api.mapbox.com/geocoding/v5/mapbox.places/${place}.json?access_token=${CONFIG.MAPBOX_TOKEN}&types=region,place,country&language=${lang}`) + console.log(res) + if (!res || !res.features) { + // Return empty array if no location found or error occurred + return [] + } + return res.features +} + export default createOrUpdateLocations diff --git a/backend/src/schema/types/Location.gql b/backend/src/schema/types/type/Location.gql similarity index 71% rename from backend/src/schema/types/Location.gql rename to backend/src/schema/types/type/Location.gql index 78bc07656..d80c9bebb 100644 --- a/backend/src/schema/types/Location.gql +++ b/backend/src/schema/types/type/Location.gql @@ -16,3 +16,12 @@ type Location { parent: Location @cypher(statement: "MATCH (this)-[:IS_IN]->(l:Location) RETURN l") } +type Location2 { + id: ID! + place_name: String! +} + +type Query { + queryLocations(place: String!, lang: String!): [Location2]! +} + From c0b25040c3e3d1547b02c8ad9c47bbc11866a8bd Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 30 Jan 2021 00:18:55 +0100 Subject: [PATCH 02/14] - frontend implementation location query - remove mapboxtoken from .env template --- webapp/.env.template | 1 - webapp/graphql/location.js | 10 +++++++ webapp/pages/settings/index.vue | 47 +++++++++++---------------------- 3 files changed, 25 insertions(+), 33 deletions(-) create mode 100644 webapp/graphql/location.js diff --git a/webapp/.env.template b/webapp/.env.template index 198452e27..1acad49b4 100644 --- a/webapp/.env.template +++ b/webapp/.env.template @@ -1,4 +1,3 @@ -MAPBOX_TOKEN="pk.eyJ1IjoiYnVzZmFrdG9yIiwiYSI6ImNraDNiM3JxcDBhaWQydG1uczhpZWtpOW4ifQ.7TNRTO-o9aK1Y6MyW_Nd4g" SENTRY_DSN_WEBAPP= COMMIT= PUBLIC_REGISTRATION=false diff --git a/webapp/graphql/location.js b/webapp/graphql/location.js new file mode 100644 index 000000000..ba47a2983 --- /dev/null +++ b/webapp/graphql/location.js @@ -0,0 +1,10 @@ +import gql from 'graphql-tag' + +export const queryLocations = () => gql` + query($place: String!, $lang: String!) { + queryLocations(place: $place, lang: $lang) { + place_name + id + } + } +` \ No newline at end of file diff --git a/webapp/pages/settings/index.vue b/webapp/pages/settings/index.vue index 9766ab81c..be1c4800f 100644 --- a/webapp/pages/settings/index.vue +++ b/webapp/pages/settings/index.vue @@ -41,17 +41,15 @@