fix(comm): handle JSON tags array in lead creation
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -92,6 +92,7 @@ func (h *LeadHandler) CreateLead(w http.ResponseWriter, r *http.Request) {
|
|||||||
var lead Lead
|
var lead Lead
|
||||||
var nextActionAt *time.Time
|
var nextActionAt *time.Time
|
||||||
var nextActionType sql.NullString
|
var nextActionType sql.NullString
|
||||||
|
var tagsJSON []byte
|
||||||
err := h.db.QueryRow(`
|
err := h.db.QueryRow(`
|
||||||
INSERT INTO leads (tenant_id, contact_id, conversation_id, source, source_metadata,
|
INSERT INTO leads (tenant_id, contact_id, conversation_id, source, source_metadata,
|
||||||
interest, product, urgency, customer_type, tags, status)
|
interest, product, urgency, customer_type, tags, status)
|
||||||
@@ -104,7 +105,7 @@ func (h *LeadHandler) CreateLead(w http.ResponseWriter, r *http.Request) {
|
|||||||
&lead.ID, &lead.TenantID, &lead.ContactID, &lead.ConversationID, &lead.Source, &lead.Status,
|
&lead.ID, &lead.TenantID, &lead.ContactID, &lead.ConversationID, &lead.Source, &lead.Status,
|
||||||
&lead.Interest, &lead.Product, &lead.Urgency, &lead.CustomerType, &lead.Owner,
|
&lead.Interest, &lead.Product, &lead.Urgency, &lead.CustomerType, &lead.Owner,
|
||||||
&lead.LeadScore, &lead.QualificationComplete, &lead.LastInteractionAt, &nextActionAt,
|
&lead.LeadScore, &lead.QualificationComplete, &lead.LastInteractionAt, &nextActionAt,
|
||||||
&nextActionType, &lead.Tags, &lead.CreatedAt, &lead.UpdatedAt,
|
&nextActionType, &tagsJSON, &lead.CreatedAt, &lead.UpdatedAt,
|
||||||
)
|
)
|
||||||
if nextActionAt != nil {
|
if nextActionAt != nil {
|
||||||
lead.NextActionAt = nextActionAt
|
lead.NextActionAt = nextActionAt
|
||||||
@@ -112,6 +113,9 @@ func (h *LeadHandler) CreateLead(w http.ResponseWriter, r *http.Request) {
|
|||||||
if nextActionType.Valid {
|
if nextActionType.Valid {
|
||||||
lead.NextActionType = nextActionType.String
|
lead.NextActionType = nextActionType.String
|
||||||
}
|
}
|
||||||
|
if len(tagsJSON) > 0 {
|
||||||
|
json.Unmarshal(tagsJSON, &lead.Tags)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("Failed to create lead")
|
log.Error().Err(err).Msg("Failed to create lead")
|
||||||
writeError(w, http.StatusInternalServerError, "failed to create lead")
|
writeError(w, http.StatusInternalServerError, "failed to create lead")
|
||||||
|
|||||||
Reference in New Issue
Block a user