mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
- backend implementation location query
This commit is contained in:
parent
0d3863fb9a
commit
d9e553b800
@ -121,6 +121,7 @@ export default shield(
|
||||
userData: isAuthenticated,
|
||||
MyInviteCodes: isAuthenticated,
|
||||
isValidInviteCode: allow,
|
||||
queryLocations: isAuthenticated,
|
||||
},
|
||||
Mutation: {
|
||||
'*': deny,
|
||||
|
||||
@ -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)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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]!
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user