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:
@@ -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>) {
|
||||
|
||||
Reference in New Issue
Block a user