25 lines
538 B
TypeScript
25 lines
538 B
TypeScript
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
|
|
import type { Database } from '@kit/supabase/database';
|
|
|
|
/**
|
|
* Resolve an account slug to its UUID.
|
|
* Used by every data loader in the CMS.
|
|
*/
|
|
export async function resolveAccountId(
|
|
client: SupabaseClient<Database>,
|
|
slug: string,
|
|
): Promise<string> {
|
|
const { data, error } = await client
|
|
.from('accounts')
|
|
.select('id')
|
|
.eq('slug', slug)
|
|
.single();
|
|
|
|
if (error || !data) {
|
|
throw new Error(`Account not found: ${slug}`);
|
|
}
|
|
|
|
return data.id;
|
|
}
|