Некоторые проверки не удались
CI / test (push) Successful in 2m5s
Docker / Build and publish worker image (push) Failing after 31s
57 строки
1.1 KiB
Go
57 строки
1.1 KiB
Go
package factories
|
|
|
|
import (
|
|
"github.com/icrowley/fake"
|
|
|
|
"rocketgit.ru/rsmon/worker/app/models"
|
|
)
|
|
|
|
// ContactFactory provides functionality.
|
|
func ContactFactory(account *models.Account, user *models.User) models.Contact {
|
|
contact := models.Contact{
|
|
Name: fake.Company(),
|
|
}
|
|
if account == nil {
|
|
c := AccountFactory()
|
|
account = &c
|
|
}
|
|
contact.Account = account
|
|
contact.AccountID = &account.ID
|
|
|
|
if user == nil {
|
|
c := UserFactory()
|
|
user = &c
|
|
}
|
|
contact.User = user
|
|
contact.UserID = &user.ID
|
|
|
|
return contact
|
|
}
|
|
|
|
// PersistedContact provides functionality.
|
|
func PersistedContact(account *models.Account, user *models.User) models.Contact {
|
|
contact := ContactFactory(account, user)
|
|
|
|
if contact.Account.ID == 0 {
|
|
err := models.DB().Save(&contact.Account).Error
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
contact.AccountID = &contact.Account.ID
|
|
}
|
|
|
|
if contact.User.ID == 0 {
|
|
err := models.DB().Save(&contact.User).Error
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
contact.UserID = &contact.User.ID
|
|
}
|
|
|
|
err := models.DB().Save(&contact).Error
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return contact
|
|
}
|