-
Notifications
You must be signed in to change notification settings - Fork 30
[codex] Fix affiliate approval counts #276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ifanatics-media
wants to merge
6
commits into
profullstack:master
Choose a base branch
from
ifanatics-media:codex/fix-affiliate-approval-count
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
33de205
Fix affiliate approval counts
ifanatics-media c4552a9
Handle affiliate count update failures
ifanatics-media a6414b0
Make affiliate status count updates atomic
ifanatics-media 5901afa
Remove orphaned affiliate decrement RPC
ifanatics-media 9a6cba3
Restrict affiliate status RPC execution
ifanatics-media a7dd665
Assert affiliate rejection notification
ifanatics-media File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
59 changes: 59 additions & 0 deletions
59
supabase/migrations/20260527161500_update_affiliate_application_status.sql
This file contains hidden or 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,59 @@ | ||
| CREATE OR REPLACE FUNCTION public.update_affiliate_application_status( | ||
| p_application_id UUID, | ||
| p_offer_id UUID, | ||
| p_status affiliate_application_status | ||
| ) | ||
| RETURNS VOID | ||
| LANGUAGE plpgsql | ||
| SECURITY DEFINER | ||
| SET search_path = public | ||
| AS $$ | ||
| DECLARE | ||
| previous_status affiliate_application_status; | ||
| BEGIN | ||
| SELECT status | ||
| INTO previous_status | ||
| FROM public.affiliate_applications | ||
| WHERE id = p_application_id | ||
| AND offer_id = p_offer_id | ||
| FOR UPDATE; | ||
|
|
||
| IF NOT FOUND THEN | ||
| RAISE EXCEPTION 'Application not found'; | ||
| END IF; | ||
|
|
||
| UPDATE public.affiliate_applications | ||
| SET | ||
| status = p_status, | ||
| approved_at = CASE WHEN p_status = 'approved' THEN NOW() ELSE approved_at END, | ||
| updated_at = NOW() | ||
| WHERE id = p_application_id | ||
| AND offer_id = p_offer_id; | ||
|
|
||
| IF p_status = 'approved' AND previous_status <> 'approved' THEN | ||
| UPDATE public.affiliate_offers | ||
| SET | ||
| total_affiliates = total_affiliates + 1, | ||
| updated_at = NOW() | ||
| WHERE id = p_offer_id; | ||
| ELSIF p_status = 'rejected' AND previous_status = 'approved' THEN | ||
| UPDATE public.affiliate_offers | ||
| SET | ||
| total_affiliates = GREATEST(total_affiliates - 1, 0), | ||
| updated_at = NOW() | ||
| WHERE id = p_offer_id; | ||
| END IF; | ||
| END; | ||
| $$; | ||
|
|
||
| REVOKE ALL ON FUNCTION public.update_affiliate_application_status( | ||
| UUID, | ||
| UUID, | ||
| affiliate_application_status | ||
| ) FROM PUBLIC; | ||
|
|
||
| GRANT EXECUTE ON FUNCTION public.update_affiliate_application_status( | ||
| UUID, | ||
| UUID, | ||
| affiliate_application_status | ||
| ) TO service_role; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.