Disable template type updation after creation to prevent breaking of campaign relations.

This commit is contained in:
Kailash Nadh 2022-07-03 10:59:40 +05:30
parent 4de5d53fe4
commit e99c8ed86b
4 changed files with 7 additions and 8 deletions

View file

@ -221,7 +221,7 @@ func handleUpdateTemplate(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, err.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 { if err != nil {
return err return err
} }

View file

@ -20,7 +20,7 @@
</div> </div>
<div class="column is-3"> <div class="column is-3">
<b-field :label="$t('globals.fields.type')" label-position="on-border"> <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="campaign">{{ $tc('globals.terms.campaign') }}</option>
<option value="tx">{{ $tc('globals.terms.tx') }}</option> <option value="tx">{{ $tc('globals.terms.tx') }}</option>
</b-select> </b-select>
@ -31,7 +31,7 @@
<div class="column is-12"> <div class="column is-12">
<b-field :label="$t('templates.subject')" label-position="on-border"> <b-field :label="$t('templates.subject')" label-position="on-border">
<b-input :maxlength="200" :ref="'focus'" v-model="form.subject" name="name" <b-input :maxlength="200" :ref="'focus'" v-model="form.subject" name="name"
:placeholder="$t('templates.subject')" required /> :placeholder="$t('templates.subject')" required />
</b-field> </b-field>
</div> </div>
</div> </div>

View file

@ -47,8 +47,8 @@ func (c *Core) CreateTemplate(name, typ, subject string, body []byte) (models.Te
} }
// UpdateTemplate updates a given template. // UpdateTemplate updates a given template.
func (c *Core) UpdateTemplate(id int, name, typ, subject string, body []byte) (models.Template, error) { func (c *Core) UpdateTemplate(id int, name, subject string, body []byte) (models.Template, error) {
res, err := c.q.UpdateTemplate.Exec(id, name, typ, subject, body) res, err := c.q.UpdateTemplate.Exec(id, name, subject, body)
if err != nil { if err != nil {
return models.Template{}, echo.NewHTTPError(http.StatusInternalServerError, return models.Template{}, echo.NewHTTPError(http.StatusInternalServerError,
c.i18n.Ts("globals.messages.errorUpdating", "name", "{globals.terms.template}", "error", pqErrMsg(err))) c.i18n.Ts("globals.messages.errorUpdating", "name", "{globals.terms.template}", "error", pqErrMsg(err)))

View file

@ -757,9 +757,8 @@ INSERT INTO templates (name, type, subject, body) VALUES($1, $2, $3, $4) RETURNI
-- name: update-template -- name: update-template
UPDATE templates SET UPDATE templates SET
name=(CASE WHEN $2 != '' THEN $2 ELSE name END), name=(CASE WHEN $2 != '' THEN $2 ELSE name END),
type=(CASE WHEN $3 != '' THEN $3::template_type ELSE type END), subject=(CASE WHEN $3 != '' THEN $3 ELSE name END),
subject=(CASE WHEN $4 != '' THEN $4 ELSE name END), body=(CASE WHEN $4 != '' THEN $4 ELSE body END),
body=(CASE WHEN $5 != '' THEN $5 ELSE body END),
updated_at=NOW() updated_at=NOW()
WHERE id = $1; WHERE id = $1;