Fix error on campaign creation when there are 0 target in target lists

This commit is contained in:
Kailash Nadh 2018-11-01 17:50:03 +05:30
parent acee18c58c
commit d712afff97

View file

@ -132,7 +132,7 @@ DELETE FROM lists WHERE id = ALL($1);
-- name: create-campaign -- name: create-campaign
-- This creates the campaign and inserts campaign_lists relationships. -- This creates the campaign and inserts campaign_lists relationships.
WITH counts AS ( WITH counts AS (
SELECT COUNT(id) as to_send, MAX(id) as max_sub_id SELECT COALESCE(COUNT(id), 0) as to_send, COALESCE(MAX(id), 0) as max_sub_id
FROM subscribers FROM subscribers
LEFT JOIN subscriber_lists ON (subscribers.id = subscriber_lists.subscriber_id) LEFT JOIN subscriber_lists ON (subscribers.id = subscriber_lists.subscriber_id)
WHERE subscriber_lists.list_id=ANY($11::INT[]) WHERE subscriber_lists.list_id=ANY($11::INT[])
@ -143,7 +143,6 @@ camp AS (
SELECT $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, SELECT $1, $2, $3, $4, $5, $6, $7, $8, $9, $10,
(SELECT to_send FROM counts), (SELECT to_send FROM counts),
(SELECT max_sub_id FROM counts) (SELECT max_sub_id FROM counts)
WHERE (SELECT COALESCE(MAX(to_send), 0) FROM counts) > 0
RETURNING id RETURNING id
) )
INSERT INTO campaign_lists (campaign_id, list_id, list_name) INSERT INTO campaign_lists (campaign_id, list_id, list_name)