update rate history module

This commit is contained in:
edmondlang
2023-02-12 10:40:50 +08:00
parent 3a7ac7efb8
commit a423ec43cd
3 changed files with 16 additions and 3 deletions
@@ -64,14 +64,15 @@ class ListCurrencyRateHistoryLogic extends AbstractControllerLogic
$rate_filter['currency_id'] = $filterArray->currency_id;
$rate_filter['service_id'] = $filterArray->service_id;
$currency_rate = $this->fetchesRate->execute(
$currency_rate_ids = $this->fetchesRate->execute(
[
'currency_id' => $filterArray->currency_id,
'service_id' => $filterArray->service_id,
]
)->first();
)->pluck('id')->toArray();
$query = CurrencyRateLog::where('currency_rate_id', $currency_rate->id)->get();
// todo: add in date filters
$query = CurrencyRateLog::whereIn('currency_rate_id', $currency_rate_ids)->get();
return $this->collectionResponse(CurrencyRateLogResource::collection($query));
}
@@ -14,10 +14,13 @@ class CurrencyRateLogResource extends JsonResource
*/
public function toArray($request)
{
$currencyRate = $this->currencyRate;
return [
'currency_rate_id' => $this->currency_rate_id,
'rate' => $this->selling,
'created_at' => $this->created_at->format('d-m-Y'),
'payment_method_type' => $currencyRate->payment_method_type,
];
}
}
+9
View File
@@ -1,10 +1,19 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class CurrencyRateLog extends AbstractModel
{
protected $table = 'currency_rate_logs';
/**
* @return BelongsTo
*/
public function currencyRate(): BelongsTo
{
return $this->BelongsTo(CurrencyRate::class, 'currency_rate_id', 'id');
}
}