-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #892 from 0xsend/use_tag_for_affiliate_referral_link
Use tag for affiliate referral link
- Loading branch information
Showing
6 changed files
with
37 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
supabase/migrations/20241123134635_fix_and_refactor_affiliate_stats_function.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
DROP FUNCTION IF EXISTS get_affiliate_stats_summary(); | ||
|
||
CREATE OR REPLACE FUNCTION get_affiliate_stats_summary() | ||
RETURNS TABLE( | ||
id uuid, | ||
created_at timestamptz, | ||
user_id uuid, | ||
referral_count bigint) | ||
LANGUAGE plpgsql | ||
SECURITY DEFINER | ||
SET search_path = public | ||
AS $$ | ||
BEGIN | ||
RETURN QUERY | ||
SELECT | ||
a.id, | ||
a.created_at, | ||
a.user_id, | ||
COUNT(DISTINCT r.tag)::bigint AS referral_count | ||
FROM | ||
affiliate_stats a | ||
LEFT JOIN referrals r ON r.referrer_id = a.user_id | ||
WHERE | ||
a.user_id = auth.uid() | ||
GROUP BY | ||
a.id, | ||
a.created_at, | ||
a.user_id; | ||
END; | ||
$$; | ||
|
Oops, something went wrong.