|
|
|
|
|
|
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
filters := []crmdSearchFilter{ |
|
|
|
|
|
{"id", "equals", id}, |
|
|
|
|
|
} |
|
|
|
|
|
cs, err := crmSearchEntity(entityType, filters) |
|
|
|
|
|
if err != nil || cs.Total < 1 { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
total, list, err := crmFindEntityByAttr(entityType, "id", id) |
|
|
|
|
|
|
|
|
if cs.Total > 1 { |
|
|
|
|
|
log.Printf("ERROR: more than one(%d) %s associated with %s", cs.Total, entityType, id) |
|
|
|
|
|
|
|
|
if total > 1 { |
|
|
|
|
|
log.Printf("ERROR: more than one(%d) %s associated with %s", total, entityType, id) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
switch entityType { |
|
|
switch entityType { |
|
|
case "Lead": |
|
|
case "Lead": |
|
|
e := []crmdLead{} |
|
|
|
|
|
err = json.Unmarshal(*cs.List, &e) |
|
|
|
|
|
if (err != nil) || (len(e) != cs.Total) { |
|
|
|
|
|
|
|
|
e, ok := list.([]crmdLead) |
|
|
|
|
|
if (!ok) || (len(e) != total) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
entity = e[0] |
|
|
entity = e[0] |
|
|
case "Livecast": |
|
|
case "Livecast": |
|
|
e := []crmdLiveCast{} |
|
|
|
|
|
err = json.Unmarshal(*cs.List, &e) |
|
|
|
|
|
if (err != nil) || (len(e) != cs.Total) { |
|
|
|
|
|
|
|
|
e, ok := list.([]crmdLiveCast) |
|
|
|
|
|
if (!ok) || (len(e) != total) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
entity = e[0] |
|
|
entity = e[0] |
|
|
case "Meeting": |
|
|
case "Meeting": |
|
|
e := []crmdMeeting{} |
|
|
|
|
|
err = json.Unmarshal(*cs.List, &e) |
|
|
|
|
|
if (err != nil) || (len(e) != cs.Total) { |
|
|
|
|
|
|
|
|
e, ok := list.([]crmdMeeting) |
|
|
|
|
|
if (!ok) || (len(e) != total) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
entity = e[0] |
|
|
entity = e[0] |
|
|
|
|
|
|
|
|
if err != nil || cs.Total < 1 { |
|
|
if err != nil || cs.Total < 1 { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
total = cs.Total |
|
|
|
|
|
|
|
|
return cs.toEntityList(entityType) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (m crmdSearchResult) toEntityList(entityType string) (total int, list interface{}, err error) { |
|
|
|
|
|
total = m.Total |
|
|
switch entityType { |
|
|
switch entityType { |
|
|
case "Lead": |
|
|
case "Lead": |
|
|
e := []crmdLead{} |
|
|
e := []crmdLead{} |
|
|
err = json.Unmarshal(*cs.List, &e) |
|
|
|
|
|
|
|
|
err = json.Unmarshal(*m.List, &e) |
|
|
|
|
|
list = e |
|
|
|
|
|
case "Livecast": |
|
|
|
|
|
e := []crmdLiveCast{} |
|
|
|
|
|
err = json.Unmarshal(*m.List, &e) |
|
|
list = e |
|
|
list = e |
|
|
case "Account": |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case "Meeting": |
|
|
|
|
|
e := []crmdMeeting{} |
|
|
|
|
|
err = json.Unmarshal(*m.List, &e) |
|
|
|
|
|
list = e |
|
|
|
|
|
default: |
|
|
|
|
|
err = errors.New("unknown entity type " + entityType) |
|
|
} |
|
|
} |
|
|
return |
|
|
return |
|
|
} |
|
|
} |