|
|
@ -76,36 +76,45 @@ func GetOtherAccounts(c *middleware.Context) { |
|
|
|
c.JSON(200, result) |
|
|
|
c.JSON(200, result) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func validateUsingAccount(accountId int64, otherId int64) bool { |
|
|
|
|
|
|
|
if accountId == otherId { |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
query := m.GetOtherAccountsQuery{AccountId: accountId} |
|
|
|
|
|
|
|
err := bus.Dispatch(&query) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// validate that the account id in the list
|
|
|
|
|
|
|
|
valid := false |
|
|
|
|
|
|
|
for _, other := range query.Result { |
|
|
|
|
|
|
|
if other.Id == otherId { |
|
|
|
|
|
|
|
valid = true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return valid |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func SetUsingAccount(c *middleware.Context) { |
|
|
|
func SetUsingAccount(c *middleware.Context) { |
|
|
|
// usingAccountId := c.ParamsInt64(":id")
|
|
|
|
usingAccountId := c.ParamsInt64(":id") |
|
|
|
//
|
|
|
|
|
|
|
|
// account := c.UserAccount
|
|
|
|
if !validateUsingAccount(c.UserAccount.Id, usingAccountId) { |
|
|
|
// otherAccounts, err := m.GetOtherAccountsFor(c.UserAccount.Id)
|
|
|
|
c.JsonApiErr(401, "Not a valid account", nil) |
|
|
|
//
|
|
|
|
return |
|
|
|
// if err != nil {
|
|
|
|
} |
|
|
|
// c.JSON(500, utils.DynMap{"message": err.Error()})
|
|
|
|
|
|
|
|
// return
|
|
|
|
cmd := m.SetUsingAccountCommand{ |
|
|
|
// }
|
|
|
|
AccountId: c.UserAccount.Id, |
|
|
|
//
|
|
|
|
UsingAccountId: usingAccountId, |
|
|
|
// // validate that the account id in the list
|
|
|
|
} |
|
|
|
// valid := false
|
|
|
|
|
|
|
|
// for _, other := range otherAccounts {
|
|
|
|
err := bus.Dispatch(&cmd) |
|
|
|
// if other.Id == usingAccountId {
|
|
|
|
if err != nil { |
|
|
|
// valid = true
|
|
|
|
c.JsonApiErr(500, "Failed to update account", err) |
|
|
|
// }
|
|
|
|
return |
|
|
|
// }
|
|
|
|
} |
|
|
|
//
|
|
|
|
|
|
|
|
// if !valid {
|
|
|
|
c.JsonOK("Active account changed") |
|
|
|
// c.Status(401)
|
|
|
|
|
|
|
|
// return
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// account.UsingAccountId = usingAccountId
|
|
|
|
|
|
|
|
// err = m.SaveAccount(account)
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
|
|
|
// c.JSON(500, utils.DynMap{"message": err.Error()})
|
|
|
|
|
|
|
|
// return
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// c.Status(204)
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|