Refactoring set using account
This commit is contained in:
@@ -14,6 +14,7 @@ func init() {
|
||||
bus.AddHandler("sql", AddCollaborator)
|
||||
bus.AddHandler("sql", GetOtherAccounts)
|
||||
bus.AddHandler("sql", CreateAccount)
|
||||
bus.AddHandler("sql", SetUsingAccount)
|
||||
}
|
||||
|
||||
func CreateAccount(cmd *m.CreateAccountCommand) error {
|
||||
@@ -33,6 +34,17 @@ func CreateAccount(cmd *m.CreateAccountCommand) error {
|
||||
})
|
||||
}
|
||||
|
||||
func SetUsingAccount(cmd *m.SetUsingAccountCommand) error {
|
||||
return inTransaction(func(sess *xorm.Session) error {
|
||||
account := m.Account{}
|
||||
sess.Id(cmd.AccountId).Get(&account)
|
||||
|
||||
account.UsingAccountId = cmd.UsingAccountId
|
||||
_, err := sess.Id(account.Id).Update(&account)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func GetAccountInfo(query *m.GetAccountInfoQuery) error {
|
||||
var account m.Account
|
||||
has, err := x.Id(query.Id).Get(&account)
|
||||
|
||||
@@ -61,6 +61,12 @@ func TestAccountDataAccess(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
So(query.Result[0].Email, ShouldEqual, "ac1@test.com")
|
||||
})
|
||||
|
||||
Convey("Can set using account", func() {
|
||||
cmd := m.SetUsingAccountCommand{AccountId: ac2.Id, UsingAccountId: ac1.Id}
|
||||
err := SetUsingAccount(&cmd)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user