Add system_logs to company gateway transformer

This commit is contained in:
David Bomba 2021-01-07 08:27:59 +11:00
parent 9bc27c05d3
commit 996355a738
3 changed files with 31 additions and 4 deletions

View File

@ -378,6 +378,11 @@ class Company extends BaseModel
return $this->hasMany(SystemLog::class)->orderBy('id', 'DESC')->take(50);
}
public function system_log_relation()
{
return $this->hasMany(SystemLog::class)->orderBy('id', 'DESC');
}
public function tokens_hashed()
{
return $this->hasMany(CompanyToken::class);

View File

@ -11,6 +11,7 @@
namespace App\Models;
use App\Models\GatewayType;
use App\PaymentDrivers\BasePaymentDriver;
use App\Utils\Number;
use Illuminate\Database\Eloquent\SoftDeletes;
@ -58,10 +59,12 @@ class CompanyGateway extends BaseModel
16 => ['card' => 'images/credit_cards/Test-Discover-Icon.png', 'text' => 'Discover'],
];
// public function getFeesAndLimitsAttribute()
// {
// return json_decode($this->attributes['fees_and_limits']);
// }
public $gateway_consts = [
'38f2c48af60c7dd69e04248cbb24c36e' => 300,
'd14dd26a37cecc30fdd65700bfb55b23' => 301,
'3758e7f7c6f4cecf0f4f348b9a00f456' => 304,
'3b6621f970ab18887c4f6dca78d3f8bb' => 305,
];
protected $touches = [];
@ -70,6 +73,15 @@ class CompanyGateway extends BaseModel
return self::class;
}
public function system_logs()
{
return $this->company
->system_log_relation
->where('type_id', $this->gateway_consts[$this->gateway->key])
->take(50);
}
public function company()
{
return $this->belongsTo(Company::class);

View File

@ -12,6 +12,8 @@
namespace App\Transformers;
use App\Models\CompanyGateway;
use App\Models\SystemLog;
use App\Transformers\SystemLogTransformer;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\SoftDeletes;
use stdClass;
@ -33,6 +35,7 @@ class CompanyGatewayTransformer extends EntityTransformer
* @var array
*/
protected $availableIncludes = [
'system_logs',
'gateway',
];
@ -81,4 +84,11 @@ class CompanyGatewayTransformer extends EntityTransformer
return $this->includeItem($company_gateway->gateway, $transformer, Gateway::class);
}
public function includeSystemLogs(CompanyGateway $company_gateway)
{
$transformer = new SystemLogTransformer($this->serializer);
return $this->includeCollection($company_gateway->system_logs(), $transformer, SystemLog::class);
}
}