feat: filter payment tags in profile view

This commit introduces a filter for payment tags in the association profile view. This filter ensures that only the payments with the current public key are shown. Minor adjustments are also made in the JSON_THROW_ON_ERROR and the comparison of year and amount in the currentYearIsPaid method.
This commit is contained in:
fsociety
2024-09-30 14:52:52 +02:00
parent e0a34d9376
commit 1d0c816192

View File

@@ -98,7 +98,10 @@ $searchPaymentEvent = function () {
'pubkey' => $event->event->pubkey,
'tags' => $event->event->tags,
'created_at' => $event->event->created_at,
])->toArray();
])
->filter(fn($payment) => collect($payment['tags'])->firstWhere('0', 'p')[1] === $this->currentPubkey)
->values()
->toArray();
$this->yearsPaid = collect($this->payments)->map(fn($payment)
=> [
@@ -108,13 +111,13 @@ $searchPaymentEvent = function () {
collect($payment['tags'])->firstWhere('0', 'description')[1],
true,
512,
JSON_THROW_ON_ERROR
)['tags']
JSON_THROW_ON_ERROR,
)['tags'],
)->firstWhere('0', 'amount')[1] / 1000,
]);
$this->currentYearIsPaid = collect($this->yearsPaid)->contains(
fn($yearPaid) => $yearPaid['year'] == date('Y') && $yearPaid['amount'] == $this->amountToPay
fn($yearPaid) => $yearPaid['year'] == date('Y') && $yearPaid['amount'] == $this->amountToPay,
);
$this->paid = true;