feat(MED-131): handle analysis order
This commit is contained in:
41
lib/services/account.service.ts
Normal file
41
lib/services/account.service.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { getSupabaseServerClient } from "@kit/supabase/server-client";
|
||||
import { getSupabaseServerAdminClient } from "@kit/supabase/server-admin-client";
|
||||
import type { Tables } from "@/packages/supabase/src/database.types";
|
||||
|
||||
type Account = Tables<{ schema: 'medreport' }, 'accounts'>;
|
||||
type Membership = Tables<{ schema: 'medreport' }, 'accounts_memberships'>;
|
||||
|
||||
export type AccountWithMemberships = Account & { memberships: Membership[] }
|
||||
|
||||
export async function getAccount(id: string): Promise<AccountWithMemberships> {
|
||||
const { data } = await getSupabaseServerClient()
|
||||
.schema('medreport')
|
||||
.from('accounts')
|
||||
.select('*, memberships: accounts_memberships (*)')
|
||||
.eq('id', id)
|
||||
.single()
|
||||
.throwOnError();
|
||||
|
||||
return data as unknown as AccountWithMemberships;
|
||||
}
|
||||
|
||||
export async function getAccountAdmin({
|
||||
primaryOwnerUserId,
|
||||
}: {
|
||||
primaryOwnerUserId: string;
|
||||
}): Promise<AccountWithMemberships> {
|
||||
const query = getSupabaseServerAdminClient()
|
||||
.schema('medreport')
|
||||
.from('accounts')
|
||||
.select('*, memberships: accounts_memberships (*)')
|
||||
|
||||
if (primaryOwnerUserId) {
|
||||
query.eq('primary_owner_user_id', primaryOwnerUserId);
|
||||
} else {
|
||||
throw new Error('primaryOwnerUserId is required');
|
||||
}
|
||||
|
||||
const { data } = await query.single().throwOnError();
|
||||
|
||||
return data as unknown as AccountWithMemberships;
|
||||
}
|
||||
Reference in New Issue
Block a user