This repository has been archived by the owner on Mar 6, 2023. It is now read-only.
forked from jazibjohar/intercom-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
requestUserMapper.go
50 lines (45 loc) · 1.59 KB
/
requestUserMapper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package intercom
// A Company the User belongs to
// used to update Companies on a User.
type UserCompany struct {
CompanyID string `json:"company_id,omitempty"`
Name string `json:"name,omitempty"`
Remove *bool `json:"remove,omitempty"`
}
type RequestUserMapper struct{}
func (rum RequestUserMapper) ConvertUser(user *User) requestUser {
return requestUser{
ID: user.ID,
Email: user.Email,
Phone: user.Phone,
UserID: user.UserID,
Name: user.Name,
SignedUpAt: user.SignedUpAt,
RemoteCreatedAt: user.RemoteCreatedAt,
LastRequestAt: user.LastRequestAt,
LastSeenIP: user.LastSeenIP,
UnsubscribedFromEmails: user.UnsubscribedFromEmails,
Companies: rum.getCompaniesToSendFromUser(user),
CustomAttributes: user.CustomAttributes,
UpdateLastRequestAt: user.UpdateLastRequestAt,
NewSession: user.NewSession,
LastSeenUserAgent: user.LastSeenUserAgent,
}
}
func (rum RequestUserMapper) getCompaniesToSendFromUser(user *User) []UserCompany {
if user.Companies == nil {
return []UserCompany{}
}
return rum.MakeUserCompaniesFromCompanies(user.Companies.Companies)
}
func (rum RequestUserMapper) MakeUserCompaniesFromCompanies(companies []Company) []UserCompany {
userCompanies := make([]UserCompany, len(companies))
for i := 0; i < len(companies); i++ {
userCompanies[i] = UserCompany{
CompanyID: companies[i].CompanyID,
Name: companies[i].Name,
Remove: companies[i].Remove,
}
}
return userCompanies
}