Add sane defaults to POST creation APIs.

This commit is contained in:
Kailash Nadh 2021-09-26 16:43:10 +05:30
parent f6cd24d6c9
commit 4056187fec
3 changed files with 20 additions and 0 deletions

View file

@ -251,6 +251,15 @@ func handleCreateCampaign(c echo.Context) error {
return err
}
o = op
} else if o.Type == "" {
o.Type = models.CampaignTypeRegular
}
if o.ContentType == "" {
o.ContentType = models.CampaignContentTypeRichtext
}
if o.Messenger == "" {
o.Messenger = "email"
}
// Validate.

View file

@ -132,6 +132,13 @@ func handleCreateList(c echo.Context) error {
app.i18n.Ts("globals.messages.errorUUID", "error", err.Error()))
}
if o.Type == "" {
o.Type = models.ListTypePrivate
}
if o.Optin == "" {
o.Optin = models.ListOptinSingle
}
// Insert and read ID.
var newID int
o.UUID = uu.String()

View file

@ -704,6 +704,10 @@ func insertSubscriber(req subimporter.SubReq, app *App) (models.Subscriber, bool
subStatus = models.SubscriptionStatusConfirmed
}
if req.Status == "" {
req.Status = models.UserStatusEnabled
}
if err = app.queries.InsertSubscriber.Get(&req.ID,
req.UUID,
req.Email,