Cast region to null
This commit is contained in:
parent
603b300fb0
commit
d1983dcb64
|
@ -7,11 +7,16 @@ use Spatie\LaravelData\Casts\Cast;
|
||||||
use Spatie\LaravelData\Casts\Uncastable;
|
use Spatie\LaravelData\Casts\Uncastable;
|
||||||
use Spatie\LaravelData\Support\DataProperty;
|
use Spatie\LaravelData\Support\DataProperty;
|
||||||
|
|
||||||
class GenderCast implements Cast
|
class NullValueCast implements Cast
|
||||||
{
|
{
|
||||||
|
public function __construct(
|
||||||
|
private int $id
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
public function cast(DataProperty $property, mixed $value, array $context): DateTimeInterface|Uncastable|null|int
|
public function cast(DataProperty $property, mixed $value, array $context): DateTimeInterface|Uncastable|null|int
|
||||||
{
|
{
|
||||||
if (23 === $value) {
|
if ($this->id === $value) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use Spatie\LaravelData\Attributes\MapInputName;
|
||||||
use Spatie\LaravelData\Attributes\WithCast;
|
use Spatie\LaravelData\Attributes\WithCast;
|
||||||
use Spatie\LaravelData\Data;
|
use Spatie\LaravelData\Data;
|
||||||
use Zoomyboy\LaravelNami\Casters\CarbonCast;
|
use Zoomyboy\LaravelNami\Casters\CarbonCast;
|
||||||
use Zoomyboy\LaravelNami\Casters\GenderCast;
|
use Zoomyboy\LaravelNami\Casters\NullValueCast;
|
||||||
use Zoomyboy\LaravelNami\Casters\StringCast;
|
use Zoomyboy\LaravelNami\Casters\StringCast;
|
||||||
use Zoomyboy\LaravelNami\Tests\Factories\MemberRequestFactory;
|
use Zoomyboy\LaravelNami\Tests\Factories\MemberRequestFactory;
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class Member extends Data
|
||||||
public string $email,
|
public string $email,
|
||||||
|
|
||||||
#[MapInputName('geschlechtId')]
|
#[MapInputName('geschlechtId')]
|
||||||
#[WithCast(GenderCast::class)]
|
#[WithCast(NullValueCast::class, id: 23)]
|
||||||
public ?int $genderId,
|
public ?int $genderId,
|
||||||
|
|
||||||
#[MapInputName('konfessionId')]
|
#[MapInputName('konfessionId')]
|
||||||
|
@ -78,7 +78,8 @@ class Member extends Data
|
||||||
#[MapInputName('ort')]
|
#[MapInputName('ort')]
|
||||||
public ?string $location,
|
public ?string $location,
|
||||||
|
|
||||||
public int $regionId,
|
#[WithCast(NullValueCast::class, id: 23)]
|
||||||
|
public ?int $regionId,
|
||||||
|
|
||||||
#[MapInputName('staatsangehoerigkeitId')]
|
#[MapInputName('staatsangehoerigkeitId')]
|
||||||
public int $nationalityId,
|
public int $nationalityId,
|
||||||
|
@ -132,7 +133,7 @@ class Member extends Data
|
||||||
'konfessionId' => $this->confessionId,
|
'konfessionId' => $this->confessionId,
|
||||||
'landId' => $this->countryId,
|
'landId' => $this->countryId,
|
||||||
'wiederverwendenFlag' => $this->keepdata,
|
'wiederverwendenFlag' => $this->keepdata,
|
||||||
'regionId' => $this->regionId,
|
'regionId' => $this->regionId ?: 23,
|
||||||
'staatsangehoerigkeitId' => $this->nationalityId,
|
'staatsangehoerigkeitId' => $this->nationalityId,
|
||||||
'zeitschriftenversand' => $this->sendNewspaper,
|
'zeitschriftenversand' => $this->sendNewspaper,
|
||||||
'emailVertretungsberechtigter' => $this->emailParents,
|
'emailVertretungsberechtigter' => $this->emailParents,
|
||||||
|
|
|
@ -147,12 +147,13 @@ class PutMemberTest extends TestCase
|
||||||
'foreign' => 'fff',
|
'foreign' => 'fff',
|
||||||
'kontoverbindung' => ['a' => 'b'],
|
'kontoverbindung' => ['a' => 'b'],
|
||||||
]);
|
]);
|
||||||
$response = $this->login()->putMember(Member::factory()->inNami(103, 16)->toMember(['genderId' => null]));
|
$response = $this->login()->putMember(Member::factory()->inNami(103, 16)->toMember(['genderId' => null, 'regionId' => null]));
|
||||||
|
|
||||||
$this->assertEquals(16, $response);
|
$this->assertEquals(16, $response);
|
||||||
|
|
||||||
app(MemberFake::class)->assertUpdated(103, 16, [
|
app(MemberFake::class)->assertUpdated(103, 16, [
|
||||||
'geschlechtId' => 23,
|
'geschlechtId' => 23,
|
||||||
|
'regionId' => 23,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue