Allow unsubscribed users to re-subscribe. Closes #588

This commit is contained in:
Kailash Nadh 2022-01-30 23:08:39 +05:30
parent d2cf6e0f14
commit d0b32b95c1

View file

@ -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
@ -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;