Skip to content

Commit

Permalink
Add create claim completed (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
enjinabner authored Aug 21, 2023
1 parent 693c717 commit 44ff7be
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Events/CreateBeamClaimsCompleted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Enjin\Platform\Beam\Events;

use Enjin\Platform\Beam\Channels\PlatformBeamChannel;
use Enjin\Platform\Channels\PlatformAppChannel;
use Enjin\Platform\Events\PlatformBroadcastEvent;
use Illuminate\Broadcasting\Channel;
use Illuminate\Support\Arr;

class CreateBeamClaimsCompleted extends PlatformBroadcastEvent
{
/**
* Creates a new event instance.
*/
public function __construct(array $data)
{
parent::__construct();

$this->broadcastData = $data;

$this->broadcastChannels = [
new Channel('beam;' . Arr::get($data, 'code')),
new PlatformAppChannel(),
new PlatformBeamChannel(),
];
}
}
11 changes: 11 additions & 0 deletions src/Jobs/CreateBeamClaims.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Enjin\Platform\Beam\Jobs;

use Enjin\Platform\Beam\Events\CreateBeamClaimsCompleted;
use Enjin\Platform\Beam\Models\Beam;
use Enjin\Platform\Beam\Models\BeamClaim;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
Expand Down Expand Up @@ -32,6 +34,15 @@ public function handle(): void
if ($this->chunk) {
$timestamp = ['created_at' => $now = now(), 'updated_at' => $now];
BeamClaim::insert($this->chunk->map(fn ($claim) => array_merge($claim, $timestamp))->toArray());

$this->chunk
->pluck('beam_id', 'beam_id')
->each(
fn ($beamId) => event(
new CreateBeamClaimsCompleted(Beam::select('id', 'code')->find($beamId)->toArray())
)
);

unset($this->chunk);
}
}
Expand Down

0 comments on commit 44ff7be

Please sign in to comment.