Skip to content

Commit

Permalink
Allow unsubscribed users to re-subscribe. Closes #588
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Jan 30, 2022
1 parent d2cf6e0 commit d0b32b9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ WITH sub AS (
INSERT INTO subscribers (uuid, email, name, status, attribs)
VALUES($1, $2, $3, $4, $5)
ON CONFLICT(email) DO UPDATE SET updated_at=NOW()
returning id
returning id, status
),
listIDs AS (
SELECT id FROM lists WHERE
Expand All @@ -75,7 +75,12 @@ subs AS (
(CASE WHEN $4='blocklisted' THEN 'unsubscribed'::subscription_status ELSE $8::subscription_status END)
)
ON CONFLICT (subscriber_id, list_id) DO UPDATE
SET updated_at=NOW()
SET updated_at=NOW(),
status=(
CASE WHEN $4='blocklisted' OR (SELECT status FROM sub)='blocklisted'
THEN 'unsubscribed'::subscription_status
ELSE $8::subscription_status END
)
)
SELECT id from sub;

Expand Down

0 comments on commit d0b32b9

Please sign in to comment.