Add automatic unsub of users blacklisted from admin
This commit is contained in:
parent
4cd66d1790
commit
c132af22b1
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
|
-- name: insert-subscriber
|
||||||
WITH sub AS (
|
WITH sub AS (
|
||||||
INSERT INTO subscribers (uuid, email, name, attribs)
|
INSERT INTO subscribers (uuid, email, name, status, attribs)
|
||||||
VALUES($1, $2, $3, $4)
|
VALUES($1, $2, $3, $4, $5)
|
||||||
returning id
|
returning id
|
||||||
),
|
),
|
||||||
subs AS (
|
subs AS (
|
||||||
INSERT INTO subscriber_lists (subscriber_id, list_id)
|
INSERT INTO subscriber_lists (subscriber_id, list_id, status)
|
||||||
VALUES((SELECT id FROM sub), UNNEST($5::INT[]))
|
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
|
ON CONFLICT (subscriber_id, list_id) DO UPDATE
|
||||||
SET updated_at=NOW()
|
SET updated_at=NOW()
|
||||||
)
|
)
|
||||||
|
@ -101,9 +105,14 @@ WITH s AS (
|
||||||
d AS (
|
d AS (
|
||||||
DELETE FROM subscriber_lists WHERE subscriber_id = $1 AND list_id != ALL($6)
|
DELETE FROM subscriber_lists WHERE subscriber_id = $1 AND list_id != ALL($6)
|
||||||
)
|
)
|
||||||
INSERT INTO subscriber_lists (subscriber_id, list_id)
|
INSERT INTO subscriber_lists (subscriber_id, list_id, status)
|
||||||
VALUES( (SELECT id FROM s), UNNEST($6) )
|
VALUES(
|
||||||
ON CONFLICT (subscriber_id, list_id) DO NOTHING;
|
(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
|
-- name: delete-subscribers
|
||||||
-- Delete one or more subscribers.
|
-- Delete one or more subscribers.
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
// !!!!!!!!!!! TODO
|
|
||||||
// For non-flat JSON attribs, show the advanced editor instead of the key-value editor
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
@ -184,6 +181,7 @@ func handleCreateSubscriber(c echo.Context) error {
|
||||||
uuid.NewV4(),
|
uuid.NewV4(),
|
||||||
strings.ToLower(strings.TrimSpace(req.Email)),
|
strings.ToLower(strings.TrimSpace(req.Email)),
|
||||||
strings.TrimSpace(req.Name),
|
strings.TrimSpace(req.Name),
|
||||||
|
req.Status,
|
||||||
req.Attribs,
|
req.Attribs,
|
||||||
req.Lists)
|
req.Lists)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue