Bulk credit requests

This commit is contained in:
David Bomba 2023-01-22 15:19:49 +11:00
parent 7bd5a73d70
commit c502177470
6 changed files with 88 additions and 6 deletions

View File

@ -11,11 +11,11 @@
namespace App\Http\Controllers;
use App\Exceptions\ModelNotFoundException;
use App\Http\Requests\CompanyUser\UpdateCompanyUserRequest;
use App\Models\CompanyUser;
use App\Models\User;
use App\Transformers\CompanyUserTransformer;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\Response;
class CompanyUserController extends BaseController

View File

@ -17,6 +17,7 @@ use App\Factory\CloneCreditFactory;
use App\Factory\CreditFactory;
use App\Filters\CreditFilters;
use App\Http\Requests\Credit\ActionCreditRequest;
use App\Http\Requests\Credit\BulkCreditRequest;
use App\Http\Requests\Credit\CreateCreditRequest;
use App\Http\Requests\Credit\DestroyCreditRequest;
use App\Http\Requests\Credit\EditCreditRequest;
@ -494,11 +495,11 @@ class CreditController extends BaseController
* ),
* )
*/
public function bulk()
public function bulk(BulkCreditRequest $request)
{
$action = request()->input('action');
$action = $request->input('action');
$ids = request()->input('ids');
$ids = $request->input('ids');
if(Ninja::isHosted() && (stripos($action, 'email') !== false) && !auth()->user()->company()->account->account_sms_verified)
return response(['message' => 'Please verify your account to send emails.'], 400);

View File

@ -33,10 +33,10 @@ class BulkCompanyGatewayRequest extends Request
public function rules()
{
return [
'ids' => 'required|bail|array',
'action' => 'in:archive,restore,delete'
'action' => 'required|bail|in:archive,restore,delete'
];
}

View File

@ -0,0 +1,40 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Requests\Credit;
use Illuminate\Foundation\Http\FormRequest;
class BulkCreditRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'ids' => 'required|bail|array',
'action' => 'required|bail|in:archive,restore,delete,email,bulk_download,bulk_print,mark_paid,clone_to_credit,history,mark_sent,download,send_email'
];
}
}

View File

@ -4926,6 +4926,8 @@ $LANG = array(
'import_completed' => 'Import completed',
'client_statement_body' => 'Your statement from :start_date to :end_date is attached.',
'email_queued' => 'Email queued',
'clone_to_recurring_invoice' => 'Clone to Recurring Invoice',
);

View File

@ -40,6 +40,45 @@ class CreditTest extends TestCase
$this->makeTestData();
}
public function testBulkActions()
{
$data = [
'action' => 'archive',
'ids' => [$this->credit->hashed_id]
];
$response = $this->withHeaders([
'X-API-TOKEN' => $this->token,
])->post('/api/v1/credits/bulk', $data)
->assertStatus(200);
$data = [
'ids' => [$this->credit->hashed_id],
'action' => 'restore'
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/credits/bulk', $data)
->assertStatus(200);
$data = [
'ids' => [$this->credit->hashed_id],
'action' => 'delete'
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/credits/bulk', $data)
->assertStatus(200);
}
public function testCreditGetClientStatus()
{
$response = $this->withHeaders([