Robert Schäfer 2019-03-27 00:14:07 +01:00
parent 88ac0601f7
commit 76dfd08c82
2 changed files with 9 additions and 9 deletions

View File

@ -1,7 +1,7 @@
Feature: Persistent Links
As a user
I want to click on a link with an 'href' having an unmodifiable id of a user
In order to have persistent links even if the user changes a his/her slug
I want all links to carry permanent information that identifies the linked resource
In order to have persistent links even if a part of the URL might change
| | Modifiable | Referenceable | Unique | Purpose |
| -- | -- | -- | -- | -- |

View File

@ -14,17 +14,17 @@ export default function(options = {}) {
const client = apolloProvider.defaultClient
let response
let thing
let resource
response = await client.query({ query: queryId, variables })
thing = response.data[Object.keys(response.data)[0]][0]
if (thing && thing.slug === slug) return // all good
if (thing && thing.slug !== slug) {
return redirect(`/${path}/${thing.id}/${thing.slug}`)
resource = response.data[Object.keys(response.data)[0]][0]
if (resource && resource.slug === slug) return // all good
if (resource && resource.slug !== slug) {
return redirect(`/${path}/${resource.id}/${resource.slug}`)
}
response = await client.query({ query: querySlug, variables })
thing = response.data[Object.keys(response.data)[0]][0]
if (thing) return redirect(`/${path}/${thing.id}/${thing.slug}`)
resource = response.data[Object.keys(response.data)[0]][0]
if (resource) return redirect(`/${path}/${resource.id}/${resource.slug}`)
return error({ statusCode: 404, message })
}