mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Fix bug if id is undefined on post route
@itbsStefan this is the fix for the bug during our pair-programming. The request to the server was returning *all* posts if `id` was undefined and the post for redirecting was the most recently created.
This commit is contained in:
parent
9545e20a22
commit
40224ab18d
@ -77,7 +77,7 @@ export default {
|
||||
error,
|
||||
app: { apolloProvider }
|
||||
} = context
|
||||
const idOrSlug = id
|
||||
const idOrSlug = id || slug
|
||||
|
||||
const variables = { idOrSlug }
|
||||
const client = apolloProvider.defaultClient
|
||||
@ -87,13 +87,16 @@ export default {
|
||||
response = await client.query({ query: queryId, variables })
|
||||
post = response.data.Post[0]
|
||||
if (post && post.slug === slug) return // all good
|
||||
if (post && post.slug !== slug) redirect(`/post/${post.id}/${post.slug}`)
|
||||
if (post && post.slug !== slug) {
|
||||
return redirect(`/post/${post.id}/${post.slug}`)
|
||||
}
|
||||
|
||||
response = await client.query({ query: querySlug, variables })
|
||||
post = response.data.Post[0]
|
||||
if (post) redirect(`/post/${post.id}/${post.slug}`)
|
||||
if (post) return redirect(`/post/${post.id}/${post.slug}`)
|
||||
|
||||
return error({ statusCode: 404 })
|
||||
const message = 'This post could not be found'
|
||||
return error({ statusCode: 404, message })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -40,13 +40,16 @@ export default {
|
||||
response = await client.query({ query: queryId, variables })
|
||||
user = response.data.User[0]
|
||||
if (user && user.slug === slug) return // all good
|
||||
if (user && user.slug !== slug) redirect(`/profile/${user.id}/${user.slug}`)
|
||||
if (user && user.slug !== slug) {
|
||||
return redirect(`/profile/${user.id}/${user.slug}`)
|
||||
}
|
||||
|
||||
response = await client.query({ query: querySlug, variables })
|
||||
user = response.data.User[0]
|
||||
if (user) redirect(`/profile/${user.id}/${user.slug}`)
|
||||
if (user) return redirect(`/profile/${user.id}/${user.slug}`)
|
||||
|
||||
return error({ statusCode: 404 })
|
||||
const message = 'This user could not be found'
|
||||
return error({ statusCode: 404, message })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user