fixes
This commit is contained in:
@@ -37,7 +37,7 @@ func (s MobilityAccountService) Login(ctx context.Context, username, password, n
|
||||
}
|
||||
|
||||
account := resp.Account.ToStorageType()
|
||||
return toAccountModel(account), nil
|
||||
return s.ToAccountModel(account), nil
|
||||
}
|
||||
|
||||
func (s MobilityAccountService) UpdateAccountData(ctx context.Context, id string, data map[string]any) error {
|
||||
@@ -78,7 +78,7 @@ func (s MobilityAccountService) GetAccountUsername(ctx context.Context, username
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return toAccountModel(resp.Account.ToStorageType()), nil
|
||||
return s.ToAccountModel(resp.Account.ToStorageType()), nil
|
||||
}
|
||||
|
||||
func (s MobilityAccountService) Register(ctx context.Context, username string, password string, email string, phone_number string, data map[string]any, namespace string) (*models.Account, error) {
|
||||
@@ -108,7 +108,7 @@ func (s MobilityAccountService) Register(ctx context.Context, username string, p
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return toAccountModel(resp.Account.ToStorageType()), nil
|
||||
return s.ToAccountModel(resp.Account.ToStorageType()), nil
|
||||
}
|
||||
func (s MobilityAccountService) UpdatePhoneNumber(ctx context.Context, accountid string, phone_number string, verified bool, verification_code string) error {
|
||||
_, err := s.Client.UpdatePhoneNumber(
|
||||
@@ -128,13 +128,45 @@ func (s MobilityAccountService) UpdatePhoneNumber(ctx context.Context, accountid
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s MobilityAccountService) UpdateAccountBirthDate(ctx context.Context, username string, namespace string, birthdate string) error {
|
||||
resp, err := s.Client.GetAccountUsername(ctx, &mobilityaccounts.GetAccountUsernameRequest{
|
||||
Username: username,
|
||||
Namespace: namespace,
|
||||
})
|
||||
func (s MobilityAccountService) SetAccountType(ctx context.Context, id string, accountType string) error {
|
||||
account, err := s.Client.GetAccount(ctx, &mobilityaccounts.GetAccountRequest{
|
||||
Id: resp.Account.Id,
|
||||
Id: id,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data := make(map[string]interface{})
|
||||
data["type"] = accountType
|
||||
dataStruct := &structpb.Struct{
|
||||
Fields: make(map[string]*structpb.Value),
|
||||
}
|
||||
|
||||
for key, value := range data {
|
||||
stringValue, ok := value.(string)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
dataStruct.Fields[key] = &structpb.Value{
|
||||
Kind: &structpb.Value_StringValue{
|
||||
StringValue: stringValue,
|
||||
},
|
||||
}
|
||||
}
|
||||
account.Account.Data = dataStruct
|
||||
_, err = s.Client.UpdateData(ctx, &mobilityaccounts.UpdateDataRequest{
|
||||
Account: account.Account,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (s MobilityAccountService) UpdateAccountBirthDate(ctx context.Context, id string, namespace string, birthdate string) error {
|
||||
account, err := s.Client.GetAccount(ctx, &mobilityaccounts.GetAccountRequest{
|
||||
Id: id,
|
||||
})
|
||||
data := make(map[string]interface{})
|
||||
data["birthdate"] = birthdate
|
||||
@@ -165,18 +197,23 @@ func (s MobilityAccountService) UpdateAccountBirthDate(ctx context.Context, user
|
||||
return nil
|
||||
}
|
||||
|
||||
func toAccountModel(account ma.Account) *models.Account {
|
||||
func (s MobilityAccountService) ToAccountModel(account ma.Account) *models.Account {
|
||||
first_name := account.Data["first_name"].(string)
|
||||
last_name := account.Data["last_name"].(string)
|
||||
birth_date, ok := account.Data["birthdate"].(string)
|
||||
if !ok {
|
||||
birth_date = ""
|
||||
}
|
||||
accountType, ok := account.Data["type"].(string)
|
||||
if !ok {
|
||||
accountType = ""
|
||||
}
|
||||
return &models.Account{
|
||||
ID: account.ID,
|
||||
FirstName: first_name,
|
||||
LastName: last_name,
|
||||
BirthDate: birth_date,
|
||||
Type: accountType,
|
||||
LocalCredentials: models.LocalCredentials{
|
||||
Email: account.Authentication.Local.Email,
|
||||
EmailVerified: account.Authentication.Local.EmailValidation.Validated,
|
||||
|
||||
Reference in New Issue
Block a user