fix account balance for deleted users
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import type { AccountBalanceEntry } from '../../types/account-balance-entry';
|
||||
import { createAccountsApi } from '../api';
|
||||
|
||||
export type AccountBalanceSummary = {
|
||||
totalBalance: number;
|
||||
@@ -88,6 +89,11 @@ export class AccountBalanceService {
|
||||
* Get balance summary for dashboard display
|
||||
*/
|
||||
async getBalanceSummary(accountId: string): Promise<AccountBalanceSummary> {
|
||||
const api = createAccountsApi(this.supabase);
|
||||
|
||||
const hasAccountTeamMembership =
|
||||
await api.hasAccountTeamMembership(accountId);
|
||||
|
||||
const [balance, entries] = await Promise.all([
|
||||
this.getAccountBalance(accountId),
|
||||
this.getAccountBalanceEntries(accountId, { limit: 5 }),
|
||||
@@ -113,6 +119,14 @@ export class AccountBalanceService {
|
||||
const expiringSoon =
|
||||
expiringData?.reduce((sum, entry) => sum + (entry.amount || 0), 0) || 0;
|
||||
|
||||
if (!hasAccountTeamMembership) {
|
||||
return {
|
||||
totalBalance: 0,
|
||||
expiringSoon,
|
||||
recentEntries: entries.entries,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
totalBalance: balance,
|
||||
expiringSoon,
|
||||
|
||||
Reference in New Issue
Block a user