Add member meta to InvoiceResource
This commit is contained in:
parent
5a87d3e7f6
commit
ebeb9bc0b0
|
@ -6,6 +6,7 @@ use App\Invoice\BillKind;
|
|||
use App\Invoice\Enums\InvoiceStatus;
|
||||
use App\Invoice\Models\Invoice;
|
||||
use App\Lib\HasMeta;
|
||||
use App\Member\Member;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
|
@ -45,6 +46,7 @@ class InvoiceResource extends JsonResource
|
|||
],
|
||||
'vias' => BillKind::forSelect(),
|
||||
'statuses' => InvoiceStatus::forSelect(),
|
||||
'members' => Member::forSelect(),
|
||||
'default' => [
|
||||
'to' => [
|
||||
'name' => '',
|
||||
|
@ -60,6 +62,7 @@ class InvoiceResource extends JsonResource
|
|||
'default_position' => [
|
||||
'price' => 0,
|
||||
'description' => '',
|
||||
'member_id' => null,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
|
|
@ -494,6 +494,14 @@ class Member extends Model implements Geolocatable
|
|||
])->implode(' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array{id: int, name: string}>
|
||||
*/
|
||||
public static function forSelect(): array
|
||||
{
|
||||
return static::select(['id', 'firstname', 'lastname'])->get()->map(fn ($member) => ['id' => $member->id, 'name' => $member->fullname])->toArray();
|
||||
}
|
||||
|
||||
// -------------------------------- Geolocation --------------------------------
|
||||
// *****************************************************************************
|
||||
public function fillCoordinate(Coordinate $coordinate): void
|
||||
|
|
|
@ -17,6 +17,7 @@ class InvoiceIndexActionTest extends TestCase
|
|||
public function testItDisplaysInvoices(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$member = Member::factory()->defaults()->create(['firstname' => 'Aaaa', 'lastname' => 'Aaab']);
|
||||
Invoice::factory()
|
||||
->has(InvoicePosition::factory()->price(1100), 'positions')
|
||||
->has(InvoicePosition::factory()->price(2200), 'positions')
|
||||
|
@ -36,6 +37,7 @@ class InvoiceIndexActionTest extends TestCase
|
|||
->assertInertiaPath('data.meta.links.store', route('invoice.store'))
|
||||
->assertInertiaPath('data.meta.vias.0', ['id' => 'E-Mail', 'name' => 'E-Mail'])
|
||||
->assertInertiaPath('data.meta.statuses.0', ['id' => 'Neu', 'name' => 'Neu'])
|
||||
->assertInertiaPath('data.meta.members.0', ['id' => $member->id, 'name' => 'Aaaa Aaab'])
|
||||
->assertInertiaPath('data.meta.default', [
|
||||
'to' => [
|
||||
'name' => '',
|
||||
|
|
Loading…
Reference in New Issue