Refactor join service and fix imports

Join service was deleted and its functionality was integrated into the team-accounts API. General rearrangement and renaming of server-related files were made, particularly for billing-related services to ensure consistency. This made it necessary to fix import paths across multiple files.
This commit is contained in:
giancarlo
2024-04-22 12:52:09 +08:00
parent 56d532ab61
commit 7020e21193
11 changed files with 72 additions and 63 deletions

View File

@@ -10,6 +10,25 @@ import { Database } from '@kit/supabase/database';
export class TeamAccountsApi {
constructor(private readonly client: SupabaseClient<Database>) {}
/**
* @name getTeamAccountById
* @description Check if the user is already in the account.
* @param accountId
*/
async getTeamAccountById(accountId: string) {
const { data, error } = await this.client
.from('accounts')
.select('*')
.eq('id', accountId)
.maybeSingle();
if (error) {
throw error;
}
return data;
}
/**
* @name getAccountWorkspace
* @description Get the account workspace data.
@@ -135,6 +154,40 @@ export class TeamAccountsApi {
return data?.customer_id;
}
/**
* @name getInvitation
* @description Get the invitation data from the invite token.
* @param adminClient - The admin client instance. Since the user is not yet part of the account, we need to use an admin client to read the pending membership
* @param token - The invitation token.
*/
async getInvitation(adminClient: SupabaseClient<Database>, token: string) {
const { data: invitation, error } = await adminClient
.from('invitations')
.select<
string,
{
id: string;
account: {
id: string;
name: string;
slug: string;
picture_url: string;
};
}
>(
'id, expires_at, account: account_id !inner (id, name, slug, picture_url)',
)
.eq('invite_token', token)
.gte('expires_at', new Date().toISOString())
.single();
if (!invitation ?? error) {
return null;
}
return invitation;
}
}
export function createTeamAccountsApi(client: SupabaseClient<Database>) {