Skip to content

Commit 7e02908

Browse files
committed
🚑 correction du bug sur les commentaires
1 parent 1bb1b8d commit 7e02908

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

app/Gamify/Points/ReplyCreated.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22

33
namespace App\Gamify\Points;
44

5+
use App\Models\User;
56
use QCod\Gamify\PointType;
67

78
class ReplyCreated extends PointType
89
{
910
public int $points = 2;
1011

11-
public function __construct($subject)
12+
public User $author;
13+
14+
public function __construct($subject, $author)
1215
{
1316
$this->subject = $subject;
17+
$this->author = $author;
1418
}
1519

1620
public function payee()
1721
{
18-
return $this->getSubject()->author;
22+
return $this->author;
1923
}
2024
}

app/Http/Controllers/Api/ReplyController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function store(CreateReplyRequest $request): ReplyResource
4848
$reply->to($target);
4949
$reply->save();
5050

51-
givePoint(new ReplyCreated($target), Auth::user());
51+
$author->givePoint(new ReplyCreated($target, $author));
5252

5353
// On envoie un event pour une nouvelle réponse à tous les abonnés de la discussion
5454
event(new CommentWasAdded($reply, $target));
@@ -80,6 +80,9 @@ public function delete(int $id): JsonResponse
8080
{
8181
/** @var Reply $reply */
8282
$reply = Reply::findOrFail($id);
83+
84+
undoPoint(new ReplyCreated($reply->replyAble, $reply->author));
85+
8386
$reply->delete();
8487

8588
return response()->json(['message' => 'Commentaire supprimé avec succès']);

app/Http/Livewire/Forum/CreateReply.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public function save()
4040
$reply->to($this->thread);
4141
$reply->save();
4242

43-
event(new ReplyWasCreated($reply));
43+
givePoint(new ReplyCreated($this->thread, Auth::user()));
4444

45-
givePoint(new ReplyCreated($this->thread));
45+
event(new ReplyWasCreated($reply));
4646

4747
session()->flash('status', 'Réponse ajoutée avec succès!');
4848

0 commit comments

Comments
 (0)