diff --git a/apps/server/src/api/v2/title/GET.ts b/apps/server/src/api/v2/title/GET.ts index c2adf97fa..395eac76e 100644 --- a/apps/server/src/api/v2/title/GET.ts +++ b/apps/server/src/api/v2/title/GET.ts @@ -1,5 +1,4 @@ -import { getChatTitle } from '@buster/database/queries/chats'; -import { getCollectionTitle, getDashboardTitle, getMetricTitle } from '@buster/database/queries/assets'; +import { getChatTitle, getCollectionTitle, getDashboardTitle, getMetricTitle, getUserOrganizationId } from '@buster/database'; import { GetTitleRequestSchema, type GetTitleResponse } from '@buster/server-shared/title'; import { zValidator } from '@hono/zod-validator'; import { Hono } from 'hono'; @@ -14,20 +13,25 @@ const app = new Hono() const { assetId, assetType } = c.req.valid('query'); const user = c.get('busterUser'); + const userOrg = await getUserOrganizationId(user.id); + if (!userOrg) { + throw new HTTPException(403, { message: 'User is not associated with an organization' }); + } + let title: string | null = null; switch (assetType) { case 'chat': - title = await getChatTitle({ assetId, organizationId: user.organizationId }); + title = await getChatTitle({ assetId, organizationId: userOrg.organizationId }); break; case 'metric': - title = await getMetricTitle({ assetId, organizationId: user.organizationId }); + title = await getMetricTitle({ assetId, organizationId: userOrg.organizationId }); break; case 'collection': - title = await getCollectionTitle({ assetId, organizationId: user.organizationId }); + title = await getCollectionTitle({ assetId, organizationId: userOrg.organizationId }); break; case 'dashboard': - title = await getDashboardTitle({ assetId, organizationId: user.organizationId }); + title = await getDashboardTitle({ assetId, organizationId: userOrg.organizationId }); break; default: const _exhaustive: never = assetType;