Fix CI failures: correct import paths and user organization access

- Import database queries from main @buster/database package
- Use getUserOrganizationId() instead of user.organizationId
- Add proper error handling for users without organizations
- Follow existing patterns from other API handlers

Co-Authored-By: nate@buster.so <nate@buster.so>
This commit is contained in:
Devin AI 2025-07-23 13:26:58 +00:00
parent 5b40205275
commit 783b95b190
1 changed files with 10 additions and 6 deletions

View File

@ -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;