Add automatic unsub of users blacklisted from admin
This commit is contained in:
parent
4cd66d1790
commit
c132af22b1
2 changed files with 17 additions and 10 deletions
23
queries.sql
23
queries.sql
|
@ -41,13 +41,17 @@ SELECT COUNT(subscribers.id) as num FROM subscribers INNER JOIN subscriber_lists
|
|||
|
||||
-- name: insert-subscriber
|
||||
WITH sub AS (
|
||||
INSERT INTO subscribers (uuid, email, name, attribs)
|
||||
VALUES($1, $2, $3, $4)
|
||||
INSERT INTO subscribers (uuid, email, name, status, attribs)
|
||||
VALUES($1, $2, $3, $4, $5)
|
||||
returning id
|
||||
),
|
||||
subs AS (
|
||||
INSERT INTO subscriber_lists (subscriber_id, list_id)
|
||||
VALUES((SELECT id FROM sub), UNNEST($5::INT[]))
|
||||
INSERT INTO subscriber_lists (subscriber_id, list_id, status)
|
||||
VALUES(
|
||||
(SELECT id FROM sub),
|
||||
UNNEST($6::INT[]),
|
||||
(CASE WHEN $4='blacklisted' THEN 'unsubscribed'::subscription_status ELSE 'unconfirmed' END)
|
||||
)
|
||||
ON CONFLICT (subscriber_id, list_id) DO UPDATE
|
||||
SET updated_at=NOW()
|
||||
)
|
||||
|
@ -101,9 +105,14 @@ WITH s AS (
|
|||
d AS (
|
||||
DELETE FROM subscriber_lists WHERE subscriber_id = $1 AND list_id != ALL($6)
|
||||
)
|
||||
INSERT INTO subscriber_lists (subscriber_id, list_id)
|
||||
VALUES( (SELECT id FROM s), UNNEST($6) )
|
||||
ON CONFLICT (subscriber_id, list_id) DO NOTHING;
|
||||
INSERT INTO subscriber_lists (subscriber_id, list_id, status)
|
||||
VALUES(
|
||||
(SELECT id FROM s),
|
||||
UNNEST($6),
|
||||
(CASE WHEN $4='blacklisted' THEN 'unsubscribed'::subscription_status ELSE 'unconfirmed' END)
|
||||
)
|
||||
ON CONFLICT (subscriber_id, list_id) DO UPDATE
|
||||
SET status = (CASE WHEN $4='blacklisted' THEN 'unsubscribed'::subscription_status ELSE 'unconfirmed' END);
|
||||
|
||||
-- name: delete-subscribers
|
||||
-- Delete one or more subscribers.
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package main
|
||||
|
||||
// !!!!!!!!!!! TODO
|
||||
// For non-flat JSON attribs, show the advanced editor instead of the key-value editor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
@ -184,6 +181,7 @@ func handleCreateSubscriber(c echo.Context) error {
|
|||
uuid.NewV4(),
|
||||
strings.ToLower(strings.TrimSpace(req.Email)),
|
||||
strings.TrimSpace(req.Name),
|
||||
req.Status,
|
||||
req.Attribs,
|
||||
req.Lists)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue