B2B-30: adds personal code to account, company admins invites members

This commit is contained in:
devmc-ee
2025-06-22 15:22:07 +03:00
parent 39c02c6d34
commit 251f2a4ef1
50 changed files with 3546 additions and 2611 deletions

View File

@@ -47,23 +47,61 @@ class AccountsApi {
}
/**
* @name loadUserAccounts
* Load the user accounts.
*/
* @name loadUserAccounts
* Load only user-owned accounts (not just memberships).
*/
async loadUserAccounts() {
const authUser = await this.client.auth.getUser();
const {
data,
error: userError,
} = authUser
if (userError) {
throw userError;
}
const { user } = data;
const { data: accounts, error } = await this.client
.from('user_accounts')
.select(`name, slug, picture_url`);
.from('accounts_memberships')
.select(`
account_id,
user_accounts (
name,
slug,
picture_url
)
`)
.eq('user_id', user.id)
.eq('account_role', 'owner');
if (error) {
throw error;
}
return accounts.map(({ name, slug, picture_url }) => {
return accounts.map(({ user_accounts }) => ({
label: user_accounts.name,
value: user_accounts.slug,
image: user_accounts.picture_url,
}));
}
async loadTempUserAccounts() {
const { data: accounts, error } = await this.client
.from('user_accounts')
.select(`name, slug`);
if (error) {
throw error;
}
return accounts.map(({ name, slug }) => {
return {
label: name,
value: slug,
image: picture_url,
};
});
}