Added rpc definition

This commit is contained in:
rafaelsideguide 2024-05-15 08:40:21 -03:00
parent 47c20c80ab
commit d4574851be

View File

@ -48,6 +48,22 @@ export async function supaAuthenticateUser(
const { data, error } = await supabase_service.rpc( const { data, error } = await supabase_service.rpc(
'get_key_and_price_id_2', { api_key: normalizedApi } 'get_key_and_price_id_2', { api_key: normalizedApi }
); );
// get_key_and_price_id_2 rpc definition:
// create or replace function get_key_and_price_id_2(api_key uuid)
// returns table(key uuid, team_id uuid, price_id text) as $$
// begin
// if api_key is null then
// return query
// select null::uuid as key, null::uuid as team_id, null::text as price_id;
// end if;
// return query
// select ak.key, ak.team_id, s.price_id
// from api_keys ak
// left join subscriptions s on ak.team_id = s.team_id
// where ak.key = api_key;
// end;
// $$ language plpgsql;
if (error) { if (error) {
console.error('Error fetching key and price_id:', error); console.error('Error fetching key and price_id:', error);