This commit updates diverse packages such as "@makerkit/data-loader-supabase-core" and "@makerkit/data-loader-supabase-nextjs" to the new versions in the package.json files. Also, several refactorings were done in logging within services and loaders by progressing 'server-only' imports and improving context handling. Additionally, type annotations have been added to several exported functions for better code readability and maintainability.
58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
import 'server-only';
|
|
|
|
import { SupabaseClient } from '@supabase/supabase-js';
|
|
|
|
import { getLogger } from '@kit/shared/logger';
|
|
import { Database } from '@kit/supabase/database';
|
|
|
|
export class DeleteTeamAccountService {
|
|
private readonly namespace = 'accounts.delete';
|
|
|
|
/**
|
|
* Deletes a team account. Permissions are not checked here, as they are
|
|
* checked in the server action.
|
|
*
|
|
* USE WITH CAUTION. THE USER MUST HAVE THE NECESSARY PERMISSIONS.
|
|
*
|
|
* @param adminClient
|
|
* @param params
|
|
*/
|
|
async deleteTeamAccount(
|
|
adminClient: SupabaseClient<Database>,
|
|
params: {
|
|
accountId: string;
|
|
userId: string;
|
|
},
|
|
) {
|
|
const logger = await getLogger();
|
|
|
|
const ctx = {
|
|
accountId: params.accountId,
|
|
userId: params.userId,
|
|
name: this.namespace,
|
|
};
|
|
|
|
logger.info(ctx, `Requested team account deletion. Processing...`);
|
|
|
|
// we can use the admin client to delete the account.
|
|
const { error } = await adminClient
|
|
.from('accounts')
|
|
.delete()
|
|
.eq('id', params.accountId);
|
|
|
|
if (error) {
|
|
logger.error(
|
|
{
|
|
...ctx,
|
|
error,
|
|
},
|
|
'Failed to delete team account',
|
|
);
|
|
|
|
throw new Error('Failed to delete team account');
|
|
}
|
|
|
|
logger.info(ctx, 'Successfully deleted team account');
|
|
}
|
|
}
|