refactor getAccountWithAuthorizationClaims to return account id

Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
bcmmbaga
2024-09-20 14:07:44 +03:00
parent 9631cb4fb3
commit 4d9bb7ea35
5 changed files with 96 additions and 48 deletions

View File

@@ -1033,3 +1033,18 @@ func (s *SqlStore) withTx(tx *gorm.DB) Store {
db: tx,
}
}
// GetAccountDomainAndCategory retrieves the Domain and DomainCategory fields for an account based on the given accountID.
func (s *SqlStore) GetAccountDomainAndCategory(ctx context.Context, accountID string) (string, string, error) {
var account Account
result := s.db.WithContext(ctx).Model(&Account{}).Select("domain", "domain_category").
Where(idQueryCondition, accountID).First(&account)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return "", "", status.Errorf(status.NotFound, "account not found")
}
return "", "", status.Errorf(status.Internal, "failed to retrieve account fields")
}
return account.Domain, account.DomainCategory, nil
}