RVRNEXT-28 add further checks before manupulating db
All checks were successful
rvr-nextgen/pipeline/pr-master This commit looks good
All checks were successful
rvr-nextgen/pipeline/pr-master This commit looks good
This commit is contained in:
parent
1f32387f63
commit
cb76cbb9b1
@ -199,7 +199,19 @@ class CommunityController implements IAuthenticationRequired
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if ($this->transactionRepository->isAnyCommon()) {
|
||||||
|
return new JsonContent([
|
||||||
|
'error' => ['errorText' => 'There are transactions with common payee!']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$user = $this->userRepository->getById(\Container::$request->post('user_id'));
|
$user = $this->userRepository->getById(\Container::$request->post('user_id'));
|
||||||
|
if ($this->communityMemberRepository->getByCommunityAndUser($community, $user) !== null) {
|
||||||
|
return new JsonContent([
|
||||||
|
'error' => ['errorText' => 'This user is already a member of this community.']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$communityMember = new CommunityMember();
|
$communityMember = new CommunityMember();
|
||||||
$communityMember->setCommunity($community);
|
$communityMember->setCommunity($community);
|
||||||
$communityMember->setUser($user);
|
$communityMember->setUser($user);
|
||||||
@ -295,6 +307,16 @@ class CommunityController implements IAuthenticationRequired
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->transactionRepository->isAnyForCurrency($currency)) {
|
||||||
|
return new JsonContent([
|
||||||
|
'error' => ['errorText' => 'There are transactions with this currency!']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->currencyExchangeRatesRepository->getAllByCurrency($currency) as $currencyExchangeRate) {
|
||||||
|
\Container::$persistentDataManager->deleteFromDb($currencyExchangeRate);
|
||||||
|
}
|
||||||
|
|
||||||
\Container::$persistentDataManager->deleteFromDb($currency);
|
\Container::$persistentDataManager->deleteFromDb($currency);
|
||||||
|
|
||||||
return new JsonContent(['success' => true]);
|
return new JsonContent(['success' => true]);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
use Container;
|
use Container;
|
||||||
use Generator;
|
use Generator;
|
||||||
use RVR\PersistentData\Model\Community;
|
use RVR\PersistentData\Model\Community;
|
||||||
|
use RVR\PersistentData\Model\Currency;
|
||||||
use RVR\PersistentData\Model\Transaction;
|
use RVR\PersistentData\Model\Transaction;
|
||||||
use RVR\PersistentData\Model\User;
|
use RVR\PersistentData\Model\User;
|
||||||
use SokoWeb\Database\Query\Select;
|
use SokoWeb\Database\Query\Select;
|
||||||
@ -36,6 +37,22 @@ class TransactionRepository
|
|||||||
return $select->count() > 0;
|
return $select->count() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isAnyCommon(): bool
|
||||||
|
{
|
||||||
|
$select = new Select(Container::$dbConnection, Transaction::getTable());
|
||||||
|
$select->where('payee_user_id', '=', null);
|
||||||
|
|
||||||
|
return $select->count() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isAnyForCurrency(Currency $currency): bool
|
||||||
|
{
|
||||||
|
$select = new Select(Container::$dbConnection, Transaction::getTable());
|
||||||
|
$select->where('currency_id', '=', $currency->getId());
|
||||||
|
|
||||||
|
return $select->count() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
public function getPagedByCommunity(Community $community, int $start, int $limit, bool $useRelations = false, array $withRelations = []): Generator
|
public function getPagedByCommunity(Community $community, int $start, int $limit, bool $useRelations = false, array $withRelations = []): Generator
|
||||||
{
|
{
|
||||||
$select = new Select(Container::$dbConnection);
|
$select = new Select(Container::$dbConnection);
|
||||||
|
Loading…
Reference in New Issue
Block a user