Skip to content

Commit

Permalink
Add identifier code (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
enjinabner authored Aug 10, 2023
1 parent 9402c8b commit db0d928
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions lang/en/type.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'beam_claim.field.claimedAt' => 'The claim timestamp.',
'beam_claim.field.token' => 'The token chain ID.',
'beam_claim.field.code' => 'The single use code.',
'beam_claim.field.identifierCode' => 'The claim identifier code.',
'beam_qr.description' => 'A beam QR which includes the beam host and code in its payload.',
'beam_qr.field.payload' => 'A base64 encoded string containing the beam host and code.',
'beam_qr.field.url' => 'A link to the QR image.',
Expand Down
1 change: 1 addition & 0 deletions src/Events/BeamClaimPending.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function __construct(array $claim)
Arr::only($claim['beam'], ['code', 'collection_chain_id']),
Arr::only($claim, ['wallet_public_key', 'claimed_at', 'state'])
);
$this->broadcastData['identifierCode'] = Arr::get($claim, 'identifierCode');
$this->broadcastData['beamCode'] = $claim['beam']['code'];

$this->broadcastChannels = [
Expand Down
5 changes: 5 additions & 0 deletions src/GraphQL/Types/BeamClaimType.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public function fields(): array
'description' => __('enjin-platform-beam::type.beam_claim.field.code'),
'resolve' => fn ($claim) => $claim->singleUseCode,
],
'identifierCode' => [
'type' => GraphQL::type('String!'),
'description' => __('enjin-platform-beam::type.beam_claim.field.identifierCode'),
'alias' => 'code',
],
'qr' => [
'type' => GraphQL::type('BeamQr'),
'description' => __('enjin-platform-beam::type.beam.field.qr'),
Expand Down
2 changes: 2 additions & 0 deletions src/Listeners/UpdateClaimStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ public function handle(PlatformBroadcastEvent $event): void
$states = [TransactionState::ABANDONED->name, TransactionState::FINALIZED->name];
if (in_array($event->broadcastData['state'], $states)) {
$claims = BeamClaim::whereHas('batch', fn ($query) => $query->where('transaction_id', $event->broadcastData['id']))
->select('*', 'code as identifierCode')
->with('beam')
->get();

if (!$claims->isEmpty()) {
$state = TransactionState::FINALIZED->name == $event->broadcastData['state']
&& $event->broadcastData['result'] == SystemEventType::EXTRINSIC_SUCCESS->name
Expand Down
13 changes: 11 additions & 2 deletions src/Services/BatchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,17 @@ public function getNextBatchId(BeamType $type, string $collectionid): int
*/
public function getBatchesForProcessing(BeamType $type): Collection
{
return BeamClaim::select('id', 'token_chain_id', 'beam_batch_id', 'wallet_public_key', 'beam_id', 'quantity', 'collection_id', 'attributes')
->where('state', ClaimStatus::PENDING)
return BeamClaim::select(
'id',
'token_chain_id',
'beam_batch_id',
'wallet_public_key',
'beam_id',
'quantity',
'collection_id',
'attributes',
'code as identifierCode',
)->where('state', ClaimStatus::PENDING)
->with(['beam', 'collection.owner'])
->whereHas('collection')
->whereHas(
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/GraphQL/Resources/GetClaims.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ query GetClaims(
claimedAt
claimStatus
quantity
identifierCode
wallet {
account {
publicKey
Expand Down

0 comments on commit db0d928

Please sign in to comment.