fix: member point firstOrCreate, posts table dedup
This commit is contained in:
+11
-13
@@ -69,21 +69,19 @@ class ParticipantsRelationManager extends RelationManager
|
||||
EditAction::make()
|
||||
->after(function (EditAction $action, $record, array $data) {
|
||||
$activity = $this->getOwnerRecord();
|
||||
$existing = MemberPoint::where('user_id', $record->id)
|
||||
->where('source_type', \App\Models\Activity::class)
|
||||
->where('source_id', $activity->id)
|
||||
->first();
|
||||
$key = [
|
||||
'user_id' => $record->id,
|
||||
'source_type' => \App\Models\Activity::class,
|
||||
'source_id' => $activity->id,
|
||||
];
|
||||
|
||||
if (($data['status'] ?? 'hadir') === 'hadir' && ! $existing) {
|
||||
MemberPoint::create([
|
||||
'user_id' => $record->id,
|
||||
'points' => 10,
|
||||
'reason' => "Hadir di kegiatan: {$activity->title}",
|
||||
'source_type' => \App\Models\Activity::class,
|
||||
'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) {
|
||||
$existing->delete();
|
||||
} else {
|
||||
MemberPoint::where($key)->delete();
|
||||
}
|
||||
}),
|
||||
DetachAction::make()
|
||||
|
||||
Reference in New Issue
Block a user