Files
speckle-server/packages/frontend-2/middleware/thread.ts
T
Kristaps Fabians Geikins 0b2ca9a515 feat: add missing FE1 fields to the FE2 GQL schema (#2471)
* WIP version create

* commitCreate migrated

* minor cleanup

* commitReceived migrated

* added Project.object

* Project.comment introduced

* moving away old API usages in FE1

* ProjectMutations.batchDelete

* project pending access requests

* WIP project access req tests

* project access req tests done

* ModelByName test

* version mutation tests

* project.object tests

* batch delete tests

* minor improvements to redirect logging
2024-07-10 11:33:53 +02:00

54 lines
1.3 KiB
TypeScript

import { useApolloClientFromNuxt } from '~/lib/common/composables/graphql'
import { graphql } from '~/lib/common/generated/gql'
import { convertThrowIntoFetchResult } from '~/lib/common/helpers/graphql'
import { getLinkToThread } from '~/lib/viewer/helpers/comments'
const resolveLinkQuery = graphql(`
query ResolveCommentLink($commentId: String!, $projectId: String!) {
project(id: $projectId) {
comment(id: $commentId) {
id
...LinkableComment
}
}
}
`)
export default defineNuxtRouteMiddleware(async (to) => {
const client = useApolloClientFromNuxt()
const threadId = to.params.threadId as string
const projectId = to.params.id as string
const res = await client
.query({
query: resolveLinkQuery,
variables: {
commentId: threadId,
projectId
}
})
.catch(convertThrowIntoFetchResult)
const comment = res.data?.project?.comment
if (!comment) {
return abortNavigation(
createError({
message: 'Comment thread not found',
statusCode: 404
})
)
}
const link = getLinkToThread(projectId, comment)
if (!link) {
return abortNavigation(
createError({
message: 'Comment thread not found',
statusCode: 404
})
)
}
return navigateTo(link)
})