feat(dashboard, api): enhance dashboard card calculations and add team membership check

This commit is contained in:
Danel Kungla
2025-08-21 21:32:22 +03:00
parent 492327c5c7
commit b1b0846234
2 changed files with 100 additions and 73 deletions

View File

@@ -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>) {