Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix template field to save null when empty #226

Merged
merged 4 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions core/models/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ type Msg struct {
URNAuth null.String `db:"urn_auth" json:"urn_auth,omitempty"`
OrgID OrgID `db:"org_id" json:"org_id"`
TopupID TopupID `db:"topup_id" json:"-"`
Template string `db:"template" json:"template"`
Template null.String `db:"template" json:"template"`

SessionID SessionID `json:"session_id,omitempty"`
SessionStatus SessionStatus `json:"session_status,omitempty"`
Expand Down Expand Up @@ -179,7 +179,7 @@ func (m *Msg) TopupID() TopupID { return m.m.TopupID }
func (m *Msg) ContactID() ContactID { return m.m.ContactID }
func (m *Msg) ContactURNID() *URNID { return m.m.ContactURNID }
func (m *Msg) IsResend() bool { return m.m.IsResend }
func (m *Msg) Template() string { return m.m.Template }
func (m *Msg) Template() null.String { return m.m.Template }

func (m *Msg) SetTopup(topupID TopupID) { m.m.TopupID = topupID }

Expand Down Expand Up @@ -383,6 +383,7 @@ func newOutgoingMsg(rt *runtime.Runtime, org *Org, channel *Channel, contactID C
m.OrgID = org.ID()
m.TopupID = NilTopupID
m.CreatedOn = createdOn
m.Template = null.NullString

msg.SetChannel(channel)
msg.SetURN(out.URN())
Expand Down Expand Up @@ -436,7 +437,7 @@ func newOutgoingMsg(rt *runtime.Runtime, org *Org, channel *Channel, contactID C
}
if out.Templating() != nil {
metadata["templating"] = out.Templating()
m.Template = out.Templating().Template().Name
m.Template = null.String(out.Templating().Template().Name)
}
if out.Topic() != flows.NilMsgTopic {
metadata["topic"] = string(out.Topic())
Expand Down Expand Up @@ -661,7 +662,7 @@ func newOutgoingMsgWpp(rt *runtime.Runtime, org *Org, channel *Channel, contactI
}
if msgWpp.Templating() != nil {
metadata["templating"] = msgWpp.Templating()
m.Template = msgWpp.Templating().Template().Name
m.Template = null.String(msgWpp.Templating().Template().Name)
}

m.Metadata = null.NewMap(metadata)
Expand Down
4 changes: 2 additions & 2 deletions core/models/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func TestMarshalMsg(t *testing.T) {
"session_id": %d,
"session_status": "W",
"status": "Q",
"template": "",
"template": null,
"text": "Hi there",
"tps_cost": 2,
"urn": "tel:+250700000001?id=10000",
Expand Down Expand Up @@ -333,7 +333,7 @@ func TestMarshalMsg(t *testing.T) {
"session_id": %d,
"session_status": "W",
"status": "Q",
"template": "",
"template": null,
"text": "Hi there",
"tps_cost": 1,
"urn": "tel:+250700000001?id=10000",
Expand Down
Loading