lib/app/user-helpers.go

135 lines
4.6 KiB
Go
Raw Normal View History

2021-07-31 03:05:02 +00:00
package app
import (
"code.tnxs.net/telnexus/lib/api/auth/auth_models"
httptransport "github.com/go-openapi/runtime/client"
)
// MarshalAuthUserToSwagger is a helper function
func MarshalAuthUserToSwagger(obj *auth_models.User) *User {
var address *Address
if obj.Address != nil {
address = &Address{
City: obj.Address.City,
Country: obj.Address.Country,
CountryCode: obj.Address.CountryCode,
PostalCode: obj.Address.PostalCode,
State: obj.Address.State,
StateCode: obj.Address.StateCode,
Street: obj.Address.Street,
}
}
var userRoles []*UserRole
if obj.UserRoles != nil {
userRoles = []*UserRole{}
for _, itm := range obj.UserRoles {
userRoles = append(userRoles, reMarshalUserRole(itm))
}
}
var tenantUsers []*TenantUser
if obj.TenantUsers != nil {
tenantUsers = []*TenantUser{}
for _, itm := range obj.TenantUsers {
tenantUsers = append(tenantUsers, reMarshalTenantUser(itm))
}
}
return &User{
ID: obj.ID,
AboutMe: obj.AboutMe,
AccountID: obj.AccountID,
Address: address,
Alias: obj.Alias,
APIKey: obj.APIKey,
Auth: httptransport.APIKeyAuth("X-API-Key", "header", obj.APIKey),
Auth0UserID: obj.Auth0UserID,
CommunityNickname: obj.CommunityNickname,
CompanyName: obj.CompanyName,
ContactID: obj.ContactID,
CreatedByID: obj.CreatedByID,
CreatedDate: obj.CreatedDate,
DelegatedApproverID: obj.DelegatedApproverID,
Department: obj.Department,
Division: obj.Division,
Email: obj.Email,
EmployeeNumber: obj.EmployeeNumber,
EndOfDay: obj.EndOfDay,
Environment: obj.Environment,
Extension: obj.Extension,
FabricAPIKey: obj.FabricAPIKey,
Fax: obj.Fax,
FirstName: obj.FirstName,
ForecastEnabled: obj.ForecastEnabled,
FullPhotoURL: obj.FullPhotoURL,
IsActive: obj.IsActive,
IsPortalEnabled: obj.IsPortalEnabled,
IsProfilePhotoActive: obj.IsProphilePhotoActive,
IsSystemControlled: obj.IsSystemControlled,
LastIP: obj.LastIP,
LastLogin: obj.LastLogin,
LastModifiedByID: obj.LastModifiedByID,
LastModifiedDate: obj.LastModifiedDate,
LastName: obj.LastName,
LoginCount: obj.LoginCount,
ManagerID: obj.ManagerID,
MobilePhone: obj.MobilePhone,
Name: obj.Name,
OutOfOfficeMessage: obj.OutOfOfficeMessage,
Phone: obj.Phone,
PortalRole: obj.PortalRole,
ProfileID: obj.ProfileID,
ReceivesAdminEmails: obj.ReceivesAdminEmails,
ReceivesAdminInfoEmails: obj.ReceivesAdminInfoEmails,
SenderEmail: obj.SenderEmail,
SenderName: obj.SenderName,
Signature: obj.Signature,
SmallPhotoURL: obj.SmallPhotoURL,
StartOfDay: obj.StartOfDay,
TaxnexusAccount: obj.TelnexusAccount,
TenantID: obj.TenantID,
TenantUsers: tenantUsers,
TimeZone: obj.TimeZone,
Title: obj.Title,
Username: obj.Username,
UserRoleID: obj.UserRoleID,
UserRoles: userRoles,
UserType: obj.UserType,
}
}
func reMarshalUserRole(s *auth_models.UserRole) *UserRole {
return &UserRole{
AccountID: s.AccountID,
Auth0RoleID: s.Auth0RoleID,
Auth0UserID: s.Auth0UserID,
CompanyName: s.CompanyName,
ContactID: s.ContactID,
RoleDescription: s.RoleDescription,
RoleID: s.RoleID,
RoleName: s.RoleName,
TelnexusAccount: s.TelnexusAccount,
UserEmail: s.UserEmail,
UserFullName: s.UserFullName,
UserID: s.UserID,
Username: s.Username,
}
}
func reMarshalTenantUser(s *auth_models.TenantUser) *TenantUser {
return &TenantUser{
AccessLevel: s.AccessLevel,
AccountID: s.AccountID,
Auth0UserID: s.Auth0UserID,
CompanyName: s.CompanyName,
ContactID: s.ContactID,
TelnexusAccount: s.TelnexusAccount,
TenantActive: s.TenantActive,
TenantID: s.TenantID,
TenantName: s.TenantName,
TenantStatus: s.TenantStatus,
TenantType: s.TenantType,
TenantVersion: s.TenantVersion,
UserEmail: s.UserEmail,
UserFullName: s.UserFullName,
UserID: s.UserID,
Username: s.Username,
}
}