mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Refactor bulk actions
This commit is contained in:
parent
706625e83f
commit
f496949008
@ -7,6 +7,7 @@ use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Http\Exceptions\ThrottleRequestsException;
|
||||
use Symfony\Component\Debug\Exception\FatalThrowableError;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
@ -61,7 +62,11 @@ class Handler extends ExceptionHandler
|
||||
}
|
||||
else if($exception instanceof ThrottleRequestsException)
|
||||
{
|
||||
return response()->json(['message'=>'Too many requests'],429);
|
||||
return response()->json(['message'=>'Too many requests'],429);
|
||||
}
|
||||
else if($exception instanceof FatalThrowableError)
|
||||
{
|
||||
return response()->json(['message'=>'Fatal error', 500]);
|
||||
}
|
||||
|
||||
return parent::render($request, $exception);
|
||||
|
@ -19,6 +19,7 @@ use App\Models\ClientContact;
|
||||
use App\Models\Country;
|
||||
use App\Models\Currency;
|
||||
use App\Models\Size;
|
||||
use App\Repositories\BaseRepository;
|
||||
use App\Repositories\ClientRepository;
|
||||
use App\Transformers\ClientTransformer;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
@ -41,17 +42,17 @@ class ClientController extends BaseController
|
||||
/**
|
||||
* @var ClientRepository
|
||||
*/
|
||||
protected $clientRepo;
|
||||
protected $client_repo;
|
||||
|
||||
/**
|
||||
* ClientController constructor.
|
||||
* @param ClientRepository $clientRepo
|
||||
*/
|
||||
public function __construct(ClientRepository $clientRepo)
|
||||
public function __construct(ClientRepository $client_repo)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->clientRepo = $clientRepo;
|
||||
$this->client_repo = $client_repo;
|
||||
|
||||
}
|
||||
|
||||
@ -101,7 +102,7 @@ class ClientController extends BaseController
|
||||
*/
|
||||
public function update(UpdateClientRequest $request, Client $client)
|
||||
{
|
||||
$client = $this->clientRepo->save($request, $client);
|
||||
$client = $this->client_repo->save($request, $client);
|
||||
|
||||
return $this->itemResponse($client);
|
||||
|
||||
@ -129,7 +130,7 @@ class ClientController extends BaseController
|
||||
public function store(StoreClientRequest $request)
|
||||
{
|
||||
|
||||
$client = $this->clientRepo->save($request, ClientFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
$client = $this->client_repo->save($request, ClientFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
|
||||
$client->load('contacts', 'primary_contact');
|
||||
|
||||
@ -168,12 +169,11 @@ class ClientController extends BaseController
|
||||
$clients->each(function ($client, $key) use($action){
|
||||
|
||||
if(auth()->user()->can('edit', $client))
|
||||
ActionEntity::dispatchNow($client, $action);
|
||||
$this->client_repo->{$action}($invoice);
|
||||
|
||||
});
|
||||
|
||||
//todo need to return the updated dataset
|
||||
return response()->json([], 200);
|
||||
return $this->listResponse(Client::withTrashed()->whereIn('id', $ids));
|
||||
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,9 @@ use App\Http\Requests\Invoice\EditInvoiceRequest;
|
||||
use App\Http\Requests\Invoice\ShowInvoiceRequest;
|
||||
use App\Http\Requests\Invoice\StoreInvoiceRequest;
|
||||
use App\Http\Requests\Invoice\UpdateInvoiceRequest;
|
||||
use App\Jobs\Entity\ActionEntity;
|
||||
use App\Models\Invoice;
|
||||
use App\Repositories\BaseRepository;
|
||||
use App\Repositories\InvoiceRepository;
|
||||
use App\Transformers\InvoiceTransformer;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
@ -38,6 +40,8 @@ class InvoiceController extends BaseController
|
||||
*/
|
||||
protected $invoice_repo;
|
||||
|
||||
protected $base_repo;
|
||||
|
||||
/**
|
||||
* InvoiceController constructor.
|
||||
*
|
||||
@ -165,6 +169,32 @@ class InvoiceController extends BaseController
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform bulk actions on the list view
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function bulk()
|
||||
{
|
||||
|
||||
$action = request()->input('action');
|
||||
|
||||
$ids = request()->input('ids');
|
||||
|
||||
$invoices = Invoice::withTrashed()->find($ids);
|
||||
|
||||
$invoices->each(function ($invoice, $key) use($action){
|
||||
|
||||
if(auth()->user()->can('edit', $invoice))
|
||||
$this->invoice_repo->{$action}($invoice);
|
||||
|
||||
});
|
||||
|
||||
//todo need to return the updated dataset
|
||||
return $this->listResponse(Invoice::withTrashed()->whereIn('id', $ids));
|
||||
|
||||
}
|
||||
|
||||
public function action(ActionInvoiceRequest $request, Invoice $invoice, $action)
|
||||
{
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user