Add preconfirm_subscriptions
to subscriber update. Closes #426.
This commit is contained in:
parent
fb48477aa7
commit
e6566189ed
2 changed files with 16 additions and 6 deletions
|
@ -44,9 +44,10 @@ type subsWrap struct {
|
|||
|
||||
type subUpdateReq struct {
|
||||
models.Subscriber
|
||||
RawAttribs json.RawMessage `json:"attribs"`
|
||||
Lists pq.Int64Array `json:"lists"`
|
||||
ListUUIDs pq.StringArray `json:"list_uuids"`
|
||||
RawAttribs json.RawMessage `json:"attribs"`
|
||||
Lists pq.Int64Array `json:"lists"`
|
||||
ListUUIDs pq.StringArray `json:"list_uuids"`
|
||||
PreconfirmSubs bool `json:"preconfirm_subscriptions"`
|
||||
}
|
||||
|
||||
// subProfileData represents a subscriber's collated data in JSON
|
||||
|
@ -327,12 +328,18 @@ func handleUpdateSubscriber(c echo.Context) error {
|
|||
}
|
||||
}
|
||||
|
||||
subStatus := models.SubscriptionStatusUnconfirmed
|
||||
if req.PreconfirmSubs {
|
||||
subStatus = models.SubscriptionStatusConfirmed
|
||||
}
|
||||
|
||||
_, err := app.queries.UpdateSubscriber.Exec(id,
|
||||
strings.ToLower(strings.TrimSpace(req.Email)),
|
||||
strings.TrimSpace(req.Name),
|
||||
req.Status,
|
||||
req.RawAttribs,
|
||||
req.Lists)
|
||||
req.Lists,
|
||||
subStatus)
|
||||
if err != nil {
|
||||
app.log.Printf("error updating subscriber: %v", err)
|
||||
return echo.NewHTTPError(http.StatusInternalServerError,
|
||||
|
@ -345,7 +352,10 @@ func handleUpdateSubscriber(c echo.Context) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, _ = sendOptinConfirmation(sub, []int64(req.Lists), app)
|
||||
|
||||
if !req.PreconfirmSubs {
|
||||
_, _ = sendOptinConfirmation(sub, []int64(req.Lists), app)
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, okResp{sub})
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ INSERT INTO subscriber_lists (subscriber_id, list_id, status)
|
|||
VALUES(
|
||||
(SELECT id FROM s),
|
||||
UNNEST($6),
|
||||
(CASE WHEN $4='blocklisted' THEN 'unsubscribed'::subscription_status ELSE 'unconfirmed' END)
|
||||
(CASE WHEN $4='blocklisted' THEN 'unsubscribed'::subscription_status ELSE $7::subscription_status END)
|
||||
)
|
||||
ON CONFLICT (subscriber_id, list_id) DO UPDATE
|
||||
SET status = (CASE WHEN $4='blocklisted' THEN 'unsubscribed'::subscription_status ELSE subscriber_lists.status END);
|
||||
|
|
Loading…
Reference in a new issue