Passport/pkg/services/accounts.go

39 lines
970 B
Go
Raw Normal View History

2024-01-06 17:56:32 +00:00
package services
import (
"fmt"
"code.smartsheep.studio/hydrogen/passport/pkg/database"
"code.smartsheep.studio/hydrogen/passport/pkg/models"
)
2024-01-07 07:52:23 +00:00
func GetAccount(id uint) (models.Account, error) {
var account models.Account
if err := database.C.Where(models.Account{
BaseModel: models.BaseModel{ID: id},
}).First(&account).Error; err != nil {
return account, err
}
return account, nil
}
2024-01-06 17:56:32 +00:00
func LookupAccount(id string) (models.Account, error) {
var account models.Account
if err := database.C.Where(models.Account{Name: id}).First(&account).Error; err == nil {
return account, nil
}
var contact models.AccountContact
if err := database.C.Where(models.AccountContact{Content: id}).First(&contact).Error; err == nil {
if err := database.C.
Where(models.Account{
BaseModel: models.BaseModel{ID: contact.AccountID},
2024-01-27 16:05:19 +00:00
}).First(&account).Error; err == nil {
2024-01-06 17:56:32 +00:00
return account, err
}
}
return account, fmt.Errorf("account was not found")
}