Skip to content

Commit

Permalink
Disable template type updation after creation to prevent breaking of …
Browse files Browse the repository at this point in the history
…campaign relations.
  • Loading branch information
knadh committed Jul 9, 2022
1 parent 4de5d53 commit e99c8ed
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func handleUpdateTemplate(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}

out, err := app.core.UpdateTemplate(id, o.Name, o.Type, o.Subject, []byte(o.Body))
out, err := app.core.UpdateTemplate(id, o.Name, o.Subject, []byte(o.Body))
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/TemplateForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</div>
<div class="column is-3">
<b-field :label="$t('globals.fields.type')" label-position="on-border">
<b-select v-model="form.type" expanded>
<b-select v-model="form.type" :disabled="isEditing" expanded>
<option value="campaign">{{ $tc('globals.terms.campaign') }}</option>
<option value="tx">{{ $tc('globals.terms.tx') }}</option>
</b-select>
Expand All @@ -31,7 +31,7 @@
<div class="column is-12">
<b-field :label="$t('templates.subject')" label-position="on-border">
<b-input :maxlength="200" :ref="'focus'" v-model="form.subject" name="name"
:placeholder="$t('templates.subject')" required />
:placeholder="$t('templates.subject')" required />
</b-field>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions internal/core/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (c *Core) CreateTemplate(name, typ, subject string, body []byte) (models.Te
}

// UpdateTemplate updates a given template.
func (c *Core) UpdateTemplate(id int, name, typ, subject string, body []byte) (models.Template, error) {
res, err := c.q.UpdateTemplate.Exec(id, name, typ, subject, body)
func (c *Core) UpdateTemplate(id int, name, subject string, body []byte) (models.Template, error) {
res, err := c.q.UpdateTemplate.Exec(id, name, subject, body)
if err != nil {
return models.Template{}, echo.NewHTTPError(http.StatusInternalServerError,
c.i18n.Ts("globals.messages.errorUpdating", "name", "{globals.terms.template}", "error", pqErrMsg(err)))
Expand Down
5 changes: 2 additions & 3 deletions queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,8 @@ INSERT INTO templates (name, type, subject, body) VALUES($1, $2, $3, $4) RETURNI
-- name: update-template
UPDATE templates SET
name=(CASE WHEN $2 != '' THEN $2 ELSE name END),
type=(CASE WHEN $3 != '' THEN $3::template_type ELSE type END),
subject=(CASE WHEN $4 != '' THEN $4 ELSE name END),
body=(CASE WHEN $5 != '' THEN $5 ELSE body END),
subject=(CASE WHEN $3 != '' THEN $3 ELSE name END),
body=(CASE WHEN $4 != '' THEN $4 ELSE body END),
updated_at=NOW()
WHERE id = $1;

Expand Down

0 comments on commit e99c8ed

Please sign in to comment.