added it_get_all_invoices_from_admin, it_get_single_user_invoice_page test

This commit is contained in:
Peter Papp
2021-03-07 09:50:04 +01:00
parent da7aee2790
commit 5660fcd4dc
6 changed files with 159 additions and 112 deletions
@@ -5,9 +5,9 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Resources\InvoiceAdminCollection;
use App\Http\Resources\InvoiceResource;
use App\Invoice;
use App\Models\Invoice;
use App\Services\StripeService;
use App\Setting;
use App\Models\Setting;
use Illuminate\Http\Request;
class InvoiceController extends Controller
@@ -37,7 +37,7 @@ class InvoiceController extends Controller
*
* @param $customer
* @param $token
* @return InvoiceResource
* @return InvoiceResource|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
public function show($customer, $token)
{
+19 -18
View File
@@ -2,7 +2,7 @@
namespace App\Http\Resources;
use App\User;
use App\Models\User;
use Illuminate\Http\Resources\Json\JsonResource;
use Laravel\Cashier\Cashier;
@@ -16,7 +16,8 @@ class InvoiceAdminResource extends JsonResource
*/
public function toArray($request)
{
$user = User::where('stripe_id', $this['customer'])->first();
$user = User::where('stripe_id', $this['customer'])
->first();
return [
'data' => [
@@ -29,7 +30,7 @@ class InvoiceAdminResource extends JsonResource
'created_at_formatted' => format_date($this['created']),
'created_at' => $this['created'],
'order' => $this['number'],
'user_id' => $user ? $user->id : null,
'user_id' => $user->id ?? null,
'client' => [
'billing_address' => $this['customer_address'],
'billing_name' => $this['customer_name'],
@@ -42,24 +43,24 @@ class InvoiceAdminResource extends JsonResource
'description' => $this['lines']['data'][0]['description'],
],
'seller' => null,
]
],
$this->mergeWhen($user, function () use ($user) {
return [
'relationships' => [
'user' => [
'data' => [
'id' => (string)$user->id,
'type' => 'user',
'attributes' => [
'name' => $user->name,
'avatar' => $user->avatar,
],
$this->mergeWhen($user, function () use ($user) {
return [
'relationships' => [
'user' => [
'data' => [
'id' => $user->id,
'type' => 'user',
'attributes' => [
'name' => $user->name,
'avatar' => $user->avatar,
]
]
]
]
]
];
}),
];
}),
],
];
}
}