fix: member point firstOrCreate, posts table dedup

This commit is contained in:
2026-05-11 18:56:59 +00:00
parent f89bedb0fd
commit c56ecb941c
2 changed files with 13 additions and 15 deletions
@@ -69,21 +69,19 @@ class ParticipantsRelationManager extends RelationManager
EditAction::make() EditAction::make()
->after(function (EditAction $action, $record, array $data) { ->after(function (EditAction $action, $record, array $data) {
$activity = $this->getOwnerRecord(); $activity = $this->getOwnerRecord();
$existing = MemberPoint::where('user_id', $record->id) $key = [
->where('source_type', \App\Models\Activity::class)
->where('source_id', $activity->id)
->first();
if (($data['status'] ?? 'hadir') === 'hadir' && ! $existing) {
MemberPoint::create([
'user_id' => $record->id, 'user_id' => $record->id,
'points' => 10,
'reason' => "Hadir di kegiatan: {$activity->title}",
'source_type' => \App\Models\Activity::class, 'source_type' => \App\Models\Activity::class,
'source_id' => $activity->id, 'source_id' => $activity->id,
];
if (($data['status'] ?? 'hadir') === 'hadir') {
MemberPoint::firstOrCreate($key, [
'points' => 10,
'reason' => "Hadir di kegiatan: {$activity->title}",
]); ]);
} elseif (($data['status'] ?? 'hadir') !== 'hadir' && $existing) { } else {
$existing->delete(); MemberPoint::where($key)->delete();
} }
}), }),
DetachAction::make() DetachAction::make()
@@ -17,8 +17,8 @@ class PostsTable
{ {
public static function configure(Table $table): Table public static function configure(Table $table): Table
{ {
$canReview = auth()->user()?->can('Publish:Post'); $canReview = auth()->user()?->can('Publish:Post') ?? false;
$canPublish = auth()->user()?->can('Publish:Post'); $canPublish = $canReview;
return $table return $table
->columns([ ->columns([