feat(dashboard, api): enhance dashboard card calculations and add team membership check
This commit is contained in:
@@ -6,10 +6,12 @@ import { UserAnalysis } from '../types/accounts';
|
||||
|
||||
export type AccountWithParams =
|
||||
Database['medreport']['Tables']['accounts']['Row'] & {
|
||||
account_params: Pick<
|
||||
Database['medreport']['Tables']['account_params']['Row'],
|
||||
'weight' | 'height'
|
||||
> | null;
|
||||
account_params:
|
||||
| Pick<
|
||||
Database['medreport']['Tables']['account_params']['Row'],
|
||||
'weight' | 'height'
|
||||
>[]
|
||||
| null;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -222,6 +224,24 @@ class AccountsApi {
|
||||
),
|
||||
}));
|
||||
}
|
||||
|
||||
async hasAccountTeamMembership(accountId?: string) {
|
||||
if (!accountId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const { count, error } = await this.client
|
||||
.schema('medreport')
|
||||
.from('accounts_memberships')
|
||||
.select('account_id', { count: 'exact', head: true })
|
||||
.eq('account_id', accountId);
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return (count ?? 0) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
export function createAccountsApi(client: SupabaseClient<Database>) {
|
||||
|
||||
Reference in New Issue
Block a user