changed order of conditional

This commit is contained in:
EntireTwix 2021-06-19 14:28:48 -07:00
parent 31e08aeb97
commit a08d53bf34

View file

@ -117,18 +117,11 @@ int_fast8_t Bank::SendFunds(const std::string &a_name, const std::string &b_name
{ {
Transaction temp; Transaction temp;
//if B does exist //if B does exist
if (users.modify_if(b_name, [&a_name, &b_name, &temp, amount](User &b) { if (!users.modify_if(b_name, [&a_name, &b_name, &temp, amount](User &b) {
temp = Transaction(a_name, b_name, amount); temp = Transaction(a_name, b_name, amount);
b.balance += amount; b.balance += amount;
b.log.AddTrans(std::forward<Transaction>(temp)); b.log.AddTrans(std::forward<Transaction>(temp));
})) }))
{
users.modify_if(a_name, [&temp](User &a) {
a.log.AddTrans(std::move(temp));
});
return true;
}
else
{ {
//attempt to refund if A exist //attempt to refund if A exist
users.modify_if(a_name, [amount](User &a) { users.modify_if(a_name, [amount](User &a) {
@ -136,6 +129,13 @@ int_fast8_t Bank::SendFunds(const std::string &a_name, const std::string &b_name
}); });
return ErrorResponse::UserNotFound; //because had to refund transaction return ErrorResponse::UserNotFound; //because had to refund transaction
} }
else
{
users.modify_if(a_name, [&temp](User &a) {
a.log.AddTrans(std::move(temp));
});
return true;
}
} }
else else
{ {