From 43f05294c3e4ddc83f3f3b2d1ee91b7be0f012f2 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Mon, 28 Jun 2021 22:09:41 +0200 Subject: [PATCH] Add member confirmation --- app/Member/Member.php | 12 +++++-- app/Member/MemberConfirmController.php | 15 +++++++++ app/Member/MemberController.php | 2 +- app/Member/MemberResource.php | 1 + ...700_create_members_confirmed_at_column.php | 32 +++++++++++++++++++ resources/js/views/member/Form.vue | 6 +++- resources/js/views/member/Index.vue | 4 +++ routes/web.php | 2 ++ 8 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 app/Member/MemberConfirmController.php create mode 100644 database/migrations/2021_06_28_194700_create_members_confirmed_at_column.php diff --git a/app/Member/Member.php b/app/Member/Member.php index 20ddc498..e6b948f7 100644 --- a/app/Member/Member.php +++ b/app/Member/Member.php @@ -19,7 +19,7 @@ class Member extends Model use Notifiable; use HasFactory; - public $fillable = ['firstname', 'lastname', 'nickname', 'other_country', 'birthday', 'joined_at', 'send_newspaper', 'address', 'further_address', 'zip', 'location', 'main_phone', 'mobile_phone', 'work_phone', 'fax', 'email', 'email_parents', 'nami_id', 'group_id', 'letter_address', 'country_id', 'way_id', 'nationality_id', 'fee_id', 'region_id', 'gender_id', 'confession_id', 'letter_address', 'bill_kind_id', 'version', 'first_subactivity_id', 'first_activity_id']; + public $fillable = ['firstname', 'lastname', 'nickname', 'other_country', 'birthday', 'joined_at', 'send_newspaper', 'address', 'further_address', 'zip', 'location', 'main_phone', 'mobile_phone', 'work_phone', 'fax', 'email', 'email_parents', 'nami_id', 'group_id', 'letter_address', 'country_id', 'way_id', 'nationality_id', 'fee_id', 'region_id', 'gender_id', 'confession_id', 'letter_address', 'bill_kind_id', 'version', 'first_subactivity_id', 'first_activity_id', 'confirmed_at']; public $dates = ['joined_at', 'birthday']; @@ -31,6 +31,7 @@ class Member extends Model 'region_id' => 'integer', 'confession_id' => 'integer', 'nami_id' => 'integer', + 'is_confirmed' => 'boolean', ]; public function scopeSearch($q, $text) { @@ -51,6 +52,10 @@ class Member extends Model return $this->nami_id !== null; } + public function getNamiMemberships($api) { + return $api->group($this->group->nami_id)->member($this->nami_id)->memberships()->toArray(); + } + //---------------------------------- Relations ---------------------------------- public function country() { @@ -121,8 +126,9 @@ class Member extends Model }); } - public function getNamiMemberships($api) { - return $api->group($this->group->nami_id)->member($this->nami_id)->memberships()->toArray(); + // ---------------------------------- Scopes ----------------------------------- + public function scopeWithIsConfirmed($q) { + $q->selectSub('DATEDIFF(NOW(), IFNULL(confirmed_at, DATE_SUB(NOW(), INTERVAL 3 YEAR))) < 712', 'is_confirmed'); } } diff --git a/app/Member/MemberConfirmController.php b/app/Member/MemberConfirmController.php new file mode 100644 index 00000000..daa9c6f2 --- /dev/null +++ b/app/Member/MemberConfirmController.php @@ -0,0 +1,15 @@ +update(['confirmed_at' => now()]); + + return redirect()->route('member.index'); + } +} diff --git a/app/Member/MemberController.php b/app/Member/MemberController.php index 35ca0b04..8c79064b 100644 --- a/app/Member/MemberController.php +++ b/app/Member/MemberController.php @@ -22,7 +22,7 @@ class MemberController extends Controller session()->put('title', 'Mitglieder'); return \Inertia::render('member/Index', [ - 'data' => MemberResource::collection(Member::search($request->query('search', null))->with('billKind')->paginate(15)), + 'data' => MemberResource::collection(Member::select('*')->search($request->query('search', null))->with('billKind')->withIsConfirmed()->paginate(15)), 'toolbar' => [ ['href' => route('member.create'), 'label' => 'Mitglied anlegen', 'color' => 'primary', 'icon' => 'plus'] ], ]); } diff --git a/app/Member/MemberResource.php b/app/Member/MemberResource.php index 1e2681f9..813fa392 100644 --- a/app/Member/MemberResource.php +++ b/app/Member/MemberResource.php @@ -44,6 +44,7 @@ class MemberResource extends JsonResource 'bill_kind_id' => $this->bill_kind_id, 'bill_kind_name' => optional($this->billKind)->name, 'has_nami' => $this->nami_id !== null, + 'is_confirmed' => $this->is_confirmed, ]; } } diff --git a/database/migrations/2021_06_28_194700_create_members_confirmed_at_column.php b/database/migrations/2021_06_28_194700_create_members_confirmed_at_column.php new file mode 100644 index 00000000..63005deb --- /dev/null +++ b/database/migrations/2021_06_28_194700_create_members_confirmed_at_column.php @@ -0,0 +1,32 @@ +datetime('confirmed_at')->nullable()->after('version'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('members', function (Blueprint $table) { + $table->dropColumn('confirmed_at'); + }); + } +} diff --git a/resources/js/views/member/Form.vue b/resources/js/views/member/Form.vue index 0b6d99b5..f5a3e6b4 100644 --- a/resources/js/views/member/Form.vue +++ b/resources/js/views/member/Form.vue @@ -6,7 +6,8 @@
- + +
@@ -85,6 +86,9 @@ export default { }, methods: { + confirm() { + this.$inertia.post(`/member/${this.inner.id}/confirm`); + }, openMenu(index) { this.active = index; }, diff --git a/resources/js/views/member/Index.vue b/resources/js/views/member/Index.vue index e974d592..ac9c2541 100644 --- a/resources/js/views/member/Index.vue +++ b/resources/js/views/member/Index.vue @@ -9,6 +9,7 @@
Ort
Mittendrin
Nami
+
Check
Rechnung
Geburtstag
Eintritt
@@ -26,6 +27,9 @@
+
+ +
Kein
diff --git a/routes/web.php b/routes/web.php index 5daf3947..7094fdd2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,7 @@ 'auth:web'], function () { Route::get('/', HomeController::class)->name('home'); Route::resource('initialize', InitializeController::class); Route::resource('member', MemberController::class); + Route::post('/member/{member}/confirm', MemberConfirmController::class); });