feat(account): refactor team account retrieval and update SQL function for workspace

This commit is contained in:
Danel Kungla
2025-08-18 15:59:59 +03:00
parent 1427bcd5a9
commit 937f3e4a71
4 changed files with 58 additions and 8 deletions

View File

@@ -1,11 +1,12 @@
import { getSupabaseServerClient } from "@kit/supabase/server-client";
import { getSupabaseServerAdminClient } from "@kit/supabase/server-admin-client";
import type { Tables } from "@/packages/supabase/src/database.types";
import type { Tables } from '@/packages/supabase/src/database.types';
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
type Account = Tables<{ schema: 'medreport' }, 'accounts'>;
type Membership = Tables<{ schema: 'medreport' }, 'accounts_memberships'>;
export type AccountWithMemberships = Account & { memberships: Membership[] }
export type AccountWithMemberships = Account & { memberships: Membership[] };
export async function getAccount(id: string): Promise<AccountWithMemberships> {
const { data } = await getSupabaseServerClient()
@@ -28,6 +29,7 @@ export async function getAccountAdmin({
.schema('medreport')
.from('accounts')
.select('*, memberships: accounts_memberships (*)')
.eq('is_personal_account', true);
if (primaryOwnerUserId) {
query.eq('primary_owner_user_id', primaryOwnerUserId);