feat: tambah sistem poin anggota (kehadiran +10, artikel +5)
- Model MemberPoint + migration - PostObserver: +5 poin saat artikel dipublish - ActivityObserver: +10 poin saat peserta hadir di kegiatan - MemberPointResource: tampil di grup Organisasi - MemberPointSeeder + update ActivitySeeder dengan pivot status kehadiran - Update PermissionSeeder: anggota bisa lihat poin
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\MemberPoint;
|
||||
use App\Models\Post;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class MemberPointSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
// Poin kehadiran dari kegiatan yang sudah executed
|
||||
Activity::whereNotNull('executed_at')->each(function ($activity) {
|
||||
$activity->participants()->wherePivot('status', 'hadir')->each(function ($user) use ($activity) {
|
||||
MemberPoint::firstOrCreate(
|
||||
['user_id' => $user->id, 'source_type' => 'activity', 'source_id' => $activity->id],
|
||||
['points' => 10, 'reason' => "Hadir di kegiatan: {$activity->title}"]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// Poin dari artikel yang sudah published
|
||||
Post::where('status', 'published')->each(function ($post) {
|
||||
MemberPoint::firstOrCreate(
|
||||
['user_id' => $post->user_id, 'source_type' => 'post', 'source_id' => $post->id],
|
||||
['points' => 5, 'reason' => "Artikel dipublikasi: {$post->title}"]
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user