Fixes for templates and bulk actions (#3112)

* change route names from camelcase to snake case

* Fixes for bulk actions

* fixes for bulk actions

* fixes for templates

* fixes for templates
This commit is contained in:
David Bomba 2019-12-02 15:18:36 +11:00 committed by GitHub
parent 25514b43cf
commit abcd2fd1bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 13 deletions

View File

@ -526,8 +526,10 @@ class InvoiceController extends BaseController
$invoices->each(function ($invoice, $key) use($action){
// $this->invoice_repo->{$action}($invoice);
if(auth()->user()->can('edit', $invoice))
$this->invoice_repo->{$action}($invoice);
$this->performAction($invoice, $action, true);
});
@ -605,9 +607,16 @@ class InvoiceController extends BaseController
public function action(ActionInvoiceRequest $request, Invoice $invoice, $action)
{
return $this->performAction($invoice, $action);
}
private function performAction(Invoice $invoice, $action, $bulk = false)
{
/*If we are using bulk actions, we don't want to return anything */
switch ($action) {
case 'clone_to_invoice':
$invoice = CloneInvoiceFactory::create($invocie, auth()->user()->id);
$invoice = CloneInvoiceFactory::create($invoice, auth()->user()->id);
return $this->itemResponse($invoice);
break;
case 'clone_to_quote':
@ -625,10 +634,14 @@ class InvoiceController extends BaseController
return $this->errorResponse(['message' => 'Invoice has no balance owing'], 400);
$invoice = MarkInvoicePaid::dispatchNow($invoice);
if(!$bulk)
return $this->itemResponse($invoice);
break;
case 'mark_sent':
$invoice->markSent();
if(!$bulk)
return $this->itemResponse($invoice);
break;
case 'download':
@ -636,13 +649,19 @@ class InvoiceController extends BaseController
break;
case 'archive':
$this->invoice_repo->archive($invoice);
if(!$bulk)
return $this->listResponse($invoice);
break;
case 'delete':
$this->invoice_repo->delete($invoice);
if(!$bulk)
return $this->listResponse($invoice);
break;
case 'email':
if(!$bulk)
return response()->json(['message'=>'email sent'],200);
break;
@ -651,5 +670,5 @@ class InvoiceController extends BaseController
break;
}
}
}

View File

@ -103,8 +103,8 @@ class TemplateController extends BaseController
if(request()->has('entity') && request()->has('entity_id')){
$class = 'App\Models\\'.ucfirst($entity);
$entity_obj = $class::find($entity_id)->company();
$class = 'App\Models\\'.ucfirst(request()->input('entity'));
$entity_obj = $class::whereId(request()->input('entity_id'))->company()->first();
}

View File

@ -537,7 +537,7 @@ class UserController extends BaseController
* Attach an existing user to a company.
*
* @OA\Post(
* path="/api/v1/users/{user}/attachToCompany",
* path="/api/v1/users/{user}/attach_to_company",
* operationId="attachUser",
* tags={"users"},
* summary="Attach an existing user to a company",
@ -586,7 +586,7 @@ class UserController extends BaseController
* Detach an existing user to a company.
*
* @OA\Delete(
* path="/api/v1/users/{user}/detachFromCompany",
* path="/api/v1/users/{user}/detach_from_company",
* operationId="detachUser",
* tags={"users"},
* summary="Detach an existing user to a company",

View File

@ -370,7 +370,6 @@ class Invoice extends BaseModel
$balance_adjustment = floatval($balance_adjustment);
\Log::error("adjusting balance from ". $this->balance. " to ". ($this->balance + $balance_adjustment));
$this->balance = $this->balance + $balance_adjustment;
if($this->balance == 0) {

View File

@ -10,7 +10,7 @@ $factory->define(App\Models\Company::class, function (Faker $faker) {
'ip' => $faker->ipv4,
'db' => config('database.default'),
'settings' => CompanySettings::defaults(),
'custom_fields' => (object) ['custom1' => '1', 'custom2' => '2', 'custom3'=>3],
'custom_fields' => (object) ['custom1' => '1', 'custom2' => '2', 'custom3'=>'3'],
// 'address1' => $faker->secondaryAddress,
// 'address2' => $faker->address,

View File

@ -70,8 +70,8 @@ Route::group(['middleware' => ['api_db','api_secret_check','token_auth'], 'prefi
// Route::resource('users', 'UserController')->middleware('password_protected'); // name = (users. index / create / show / update / destroy / edit
Route::resource('users', 'UserController'); // name = (users. index / create / show / update / destroy / edit
Route::post('users/{user}/attachToCompany', 'UserController@attach');
Route::delete('users/{user}/detachFromCompany','UserController@detach');
Route::post('users/{user}/attach_to_company', 'UserController@attach');
Route::delete('users/{user}/detach_from_company','UserController@detach');
Route::post('users/bulk', 'UserController@bulk')->name('users.bulk')->middleware('password_protected');

View File

@ -90,7 +90,7 @@ class UserTest extends TestCase
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/users/'.$this->encodePrimaryKey($user->id).'/attachToCompany?include=company_user');
])->post('/api/v1/users/'.$this->encodePrimaryKey($user->id).'/attach_to_company?include=company_user');
$response->assertStatus(200);
@ -101,7 +101,7 @@ class UserTest extends TestCase
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->delete('/api/v1/users/'.$this->encodePrimaryKey($user->id).'/detachFromCompany?include=company_user');
])->delete('/api/v1/users/'.$this->encodePrimaryKey($user->id).'/detach_from_company?include=company_user');
$response->assertStatus(200);