Add has promise
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
945e65f49e
commit
cf5445a0e3
|
@ -16,7 +16,7 @@ class Membership extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
public $fillable = ['subactivity_id', 'activity_id', 'group_id', 'member_id', 'nami_id', 'from'];
|
||||
public $fillable = ['subactivity_id', 'activity_id', 'group_id', 'member_id', 'nami_id', 'from', 'promised_at'];
|
||||
|
||||
public function activity(): BelongsTo
|
||||
{
|
||||
|
|
|
@ -7,6 +7,7 @@ use App\Member\Member;
|
|||
use App\Member\Membership;
|
||||
use App\Setting\NamiSettings;
|
||||
use App\Subactivity;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\In;
|
||||
|
@ -20,7 +21,7 @@ class MembershipStoreAction
|
|||
{
|
||||
use AsAction;
|
||||
|
||||
public function handle(Member $member, Activity $activity, ?Subactivity $subactivity, NamiSettings $settings): Membership
|
||||
public function handle(Member $member, Activity $activity, ?Subactivity $subactivity, ?Carbon $promisedAt, NamiSettings $settings): Membership
|
||||
{
|
||||
$from = now()->startOfDay();
|
||||
|
||||
|
@ -38,6 +39,7 @@ class MembershipStoreAction
|
|||
$membership = $member->memberships()->create([
|
||||
'activity_id' => $activity->id,
|
||||
'subactivity_id' => $subactivity ? $subactivity->id : null,
|
||||
'promised_at' => $promisedAt,
|
||||
...['nami_id' => $namiId, 'group_id' => $member->group->id, 'from' => $from],
|
||||
]);
|
||||
|
||||
|
@ -56,6 +58,7 @@ class MembershipStoreAction
|
|||
return [
|
||||
'activity_id' => ['bail', 'required', 'exists:activities,id'],
|
||||
'subactivity_id' => $subactivityRule,
|
||||
'promised_at' => ['nullable', 'date'],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -76,6 +79,7 @@ class MembershipStoreAction
|
|||
$member,
|
||||
Activity::find($request->activity_id),
|
||||
$request->subactivity_id ? Subactivity::find($request->subactivity_id) : null,
|
||||
$request->promised_at ? Carbon::parse($request->promised_at) : null,
|
||||
$settings,
|
||||
);
|
||||
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace App\Membership\Actions;
|
||||
|
||||
use App\Activity;
|
||||
use App\Member\Member;
|
||||
use App\Member\Membership;
|
||||
use App\Subactivity;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\In;
|
||||
use Lorisleiva\Actions\ActionRequest;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
|
||||
class MembershipUpdateAction
|
||||
{
|
||||
use AsAction;
|
||||
|
||||
public function handle(Membership $membership, Activity $activity, ?Subactivity $subactivity, ?Carbon $promisedAt): Membership
|
||||
{
|
||||
$from = now()->startOfDay();
|
||||
|
||||
$membership->update([
|
||||
'activity_id' => $activity->id,
|
||||
'subactivity_id' => $subactivity ? $subactivity->id : null,
|
||||
'promised_at' => $promisedAt,
|
||||
]);
|
||||
|
||||
return $membership;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, string|In>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$subactivityRule = request()->activity_id ? ['nullable', Rule::exists('activity_subactivity', 'subactivity_id')->where('activity_id', request()->activity_id)] : ['nullable'];
|
||||
|
||||
return [
|
||||
'activity_id' => ['bail', 'required', 'exists:activities,id'],
|
||||
'subactivity_id' => $subactivityRule,
|
||||
'promised_at' => ['nullable', 'date'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function getValidationAttributes(): array
|
||||
{
|
||||
return [
|
||||
'activity_id' => 'Tätigkeit',
|
||||
'subactivity_id' => 'Untertätigkeit',
|
||||
];
|
||||
}
|
||||
|
||||
public function asController(Member $member, Membership $membership, ActionRequest $request): RedirectResponse
|
||||
{
|
||||
$this->handle(
|
||||
$membership,
|
||||
Activity::find($request->activity_id),
|
||||
$request->subactivity_id ? Subactivity::find($request->subactivity_id) : null,
|
||||
$request->promised_at ? Carbon::parse($request->promised_at) : null,
|
||||
);
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ class MembershipResource extends JsonResource
|
|||
'subactivity_id' => $this->subactivity_id,
|
||||
'subactivity_name' => $this->subactivity?->name,
|
||||
'human_date' => $this->created_at->format('d.m.Y'),
|
||||
'promised_at' => $this->promised_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use App\Activity;
|
|||
use App\Group;
|
||||
use App\Member\Membership;
|
||||
use App\Subactivity;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
|
@ -25,6 +26,7 @@ class MembershipFactory extends Factory
|
|||
return [
|
||||
'group_id' => Group::factory()->createOne()->id,
|
||||
'from' => now()->subMonths(3),
|
||||
'promised_at' => null,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -43,4 +45,11 @@ class MembershipFactory extends Factory
|
|||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public function promise(Carbon $value): self
|
||||
{
|
||||
return $this->state([
|
||||
'promised_at' => $value->format('Y-m-d'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class() extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('memberships', function (Blueprint $table) {
|
||||
$table->date('promised_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
}
|
||||
};
|
|
@ -17,6 +17,7 @@
|
|||
:options="activities"
|
||||
v-model="single.activity_id"
|
||||
label="Tätigkeit"
|
||||
size="sm"
|
||||
required
|
||||
></f-select>
|
||||
<f-select
|
||||
|
@ -26,7 +27,23 @@
|
|||
id="subactivity_id"
|
||||
v-model="single.subactivity_id"
|
||||
label="Untertätigkeit"
|
||||
size="sm"
|
||||
></f-select>
|
||||
<f-switch
|
||||
id="has_promise"
|
||||
:items="single.promised_at !== null"
|
||||
@input="single.promised_at = $event ? '2000-02-02' : null"
|
||||
size="sm"
|
||||
label="Hat Versprechen"
|
||||
></f-switch>
|
||||
<f-text
|
||||
v-show="single.promised_at !== null"
|
||||
type="date"
|
||||
id="promised_at"
|
||||
v-model="single.promised_at"
|
||||
label="Versprechensdatum"
|
||||
size="sm"
|
||||
></f-text>
|
||||
<button type="submit" class="btn btn-primary">Absenden</button>
|
||||
</form>
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ use App\Member\Controllers\MemberResyncController;
|
|||
use App\Member\MemberController;
|
||||
use App\Membership\Actions\MembershipDestroyAction;
|
||||
use App\Membership\Actions\MembershipStoreAction;
|
||||
use App\Membership\Actions\MembershipUpdateAction;
|
||||
use App\Payment\AllpaymentController;
|
||||
use App\Payment\PaymentController;
|
||||
use App\Payment\SendpaymentController;
|
||||
|
@ -36,6 +37,7 @@ Route::group(['middleware' => 'auth:web'], function (): void {
|
|||
Route::get('/sendpayment', [SendpaymentController::class, 'create'])->name('sendpayment.create');
|
||||
Route::get('/sendpayment/pdf', [SendpaymentController::class, 'send'])->name('sendpayment.pdf');
|
||||
Route::post('/member/{member}/membership', MembershipStoreAction::class)->name('membership.store');
|
||||
Route::patch('/member/{member}/membership/{membership}', MembershipUpdateAction::class)->name('membership.store');
|
||||
Route::delete('/member/{member}/membership/{membership}', MembershipDestroyAction::class)->name('membership.destroy');
|
||||
Route::resource('member.course', CourseController::class);
|
||||
Route::get('/member/{member}/efz', ShowEfzDocumentAction::class)->name('efz');
|
||||
|
|
|
@ -33,7 +33,7 @@ class ShowTest extends TestCase
|
|||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
$member = Member::factory()
|
||||
->defaults()
|
||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Jungpfadfinder', 88)->state(['created_at' => '2022-11-19 05:00:00']))
|
||||
->has(Membership::factory()->promise(now())->in('€ LeiterIn', 5, 'Jungpfadfinder', 88)->state(['created_at' => '2022-11-19 05:00:00']))
|
||||
->has(Payment::factory()->notPaid()->nr('2019')->subscription('Free', 1050))
|
||||
->for(Gender::factory()->name('Männlich'))
|
||||
->for(Region::factory()->name('NRW'))
|
||||
|
@ -108,6 +108,7 @@ class ShowTest extends TestCase
|
|||
'subactivity_name' => 'Jungpfadfinder',
|
||||
'id' => $member->memberships->first()->id,
|
||||
'human_date' => '19.11.2022',
|
||||
'promised_at' => now()->format('Y-m-d'),
|
||||
], $response, 'data.memberships.0');
|
||||
$this->assertInertiaHas([
|
||||
'organizer' => 'DPSG',
|
||||
|
|
|
@ -42,7 +42,7 @@ class StoreTest extends TestCase
|
|||
|
||||
$response = $this->from('/member')->post(
|
||||
"/member/{$member->id}/membership",
|
||||
MembershipRequestFactory::new()->in($activity, $activity->subactivities->first())->create()
|
||||
MembershipRequestFactory::new()->promise(now())->in($activity, $activity->subactivities->first())->create()
|
||||
);
|
||||
|
||||
$response->assertRedirect('/member');
|
||||
|
@ -52,6 +52,7 @@ class StoreTest extends TestCase
|
|||
'activity_id' => $activity->id,
|
||||
'subactivity_id' => $activity->subactivities->first()->id,
|
||||
'nami_id' => 133,
|
||||
'promised_at' => now()->format('Y-m-d'),
|
||||
]);
|
||||
app(MembershipFake::class)->assertCreated(6, [
|
||||
'untergliederungId' => 4,
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Membership;
|
||||
|
||||
use App\Activity;
|
||||
use App\Group;
|
||||
use App\Member\Member;
|
||||
use App\Member\Membership;
|
||||
use App\Subactivity;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\RequestFactories\MembershipRequestFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UpdateTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Carbon::setTestNow(Carbon::parse('2022-02-03 03:00:00'));
|
||||
$this->login()->loginNami();
|
||||
}
|
||||
|
||||
public function testItCreatesAMembership(): void
|
||||
{
|
||||
$this->withoutExceptionHandling();
|
||||
$activity = Activity::factory()->hasAttached(Subactivity::factory())->create();
|
||||
$member = Member::factory()
|
||||
->defaults()
|
||||
->has(Membership::factory()->for($activity)->for($activity->subactivities->first()))
|
||||
->for(Group::factory()->inNami(1400))
|
||||
->inNami(6)
|
||||
->create();
|
||||
$membership = $member->memberships->first();
|
||||
|
||||
$response = $this->from('/member')->patch(
|
||||
"/member/{$member->id}/membership/{$membership->id}",
|
||||
MembershipRequestFactory::new()->promise(now())->in($membership->activity, $membership->subactivity)->create()
|
||||
);
|
||||
|
||||
$response->assertRedirect('/member');
|
||||
$this->assertDatabaseHas('memberships', [
|
||||
'member_id' => $member->id,
|
||||
'activity_id' => $activity->id,
|
||||
'subactivity_id' => $activity->subactivities->first()->id,
|
||||
'promised_at' => now()->format('Y-m-d'),
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -4,13 +4,16 @@ namespace Tests\RequestFactories;
|
|||
|
||||
use App\Activity;
|
||||
use App\Subactivity;
|
||||
use Carbon\Carbon;
|
||||
use Worksome\RequestFactories\RequestFactory;
|
||||
|
||||
class MembershipRequestFactory extends RequestFactory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
'has_promise' => null,
|
||||
];
|
||||
}
|
||||
|
||||
public function in(Activity $activity, ?Subactivity $subactivity = null): self
|
||||
|
@ -44,4 +47,11 @@ class MembershipRequestFactory extends RequestFactory
|
|||
'subactivity_id' => Subactivity::factory()->create()->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function promise(Carbon $value): self
|
||||
{
|
||||
return $this->state([
|
||||
'promised_at' => $value->format('Y-m-d'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue