Allow admin to delete a default bank

This commit is contained in:
Dillon Ngo
2025-08-15 00:16:24 +08:00
parent 712c4e5bbe
commit db078502d9
2 changed files with 31 additions and 10 deletions
@@ -8,9 +8,10 @@ use App\Classes\Modules\Banks\Services\FetchesBank;
use App\Classes\Modules\Banks\Standards\Rules\CanDeleteBank;
use App\Classes\Modules\Banks\Services\DeletesBank;
use App\Classes\Modules\Banks\Services\CreatesBankLog;
use App\Http\Resources\BankResource;
use App\Classes\ValueObjects\Constants\RoleTypes;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class DeleteBankLogic extends AbstractControllerLogic
{
@@ -66,20 +67,30 @@ class DeleteBankLogic extends AbstractControllerLogic
*/
public function logic(Request $request) : JsonResponse
{
$this->canDeleteBank->passes();
$bank = $this->fetchesBank->execute(['id' => $request->route('id')]);
$proceed = false;
if($bank->default){
throw new RequestValidationException('You can\'t delete bank account when it set to default');
$isAuthorized = in_array(Auth::user()->type, RoleTypes::ADMIN_ROLES);
if($isAuthorized) {
$banks = $bank->company->banks()->where('default', 1)->get();
if(count($banks) > 1) {
//User should be able to delete themselves, but sometimes there are more than 1 bank set as default (different type, why??!), we need to allow admin to do the delete
$proceed = true;
}
else{
$proceed = false;
}
}
if(!$proceed){
throw new RequestValidationException('You can\'t delete bank account when it set to default');
}
}
$bank = $this->deletesBank->execute($bank);
// $bankLog = $this->createsBankLog->execute($bank);
// $bankLog = $this->createsBankLog->execute($bank);
return $this->response([]);
}
}
}
@@ -51,6 +51,13 @@
</div>
</div>
</div>
<div class="col-auto m-l-10 d-flex align-items-centert requestModal" data-type="deleteBankModal">
<div data-toggle="tooltip" title="" data-placement="bottom" class="row link align-items-center justify-content-center" data-original-title="Edit">
<div class="btn btn-xs btn-outline-danger b-rad-none m-r-5 requestModalol">
<i class="fa fa-times"></i>
</div>
</div>
</div>
</div>
</div>
</div>
@@ -58,6 +65,9 @@
<modal-component class="animate__animated animate__fast animate__fadeIn" styleType="fill-in" type="editBankModal">
<edit-bank-form-component :data="item" :section="section" :company_id="company_id"></edit-bank-form-component>
</modal-component>
<modal-component class="animate__animated animate__fast animate__fadeIn" styleType="fill-in" type="deleteBankModal">
<delete-bank-account-form-component :data="item" :section="section" class="text-center"></delete-bank-account-form-component>
</modal-component>
</div>
</template>
@@ -75,4 +85,4 @@
},
mixins: [componentHandler]
}
</script>
</script>