Add support for returning transforming activity logs on the front-end
This commit is contained in:
parent
e15985ea39
commit
a5521ecb79
9 changed files with 162 additions and 6 deletions
37
app/Transformers/Api/Client/ActivityLogTransformer.php
Normal file
37
app/Transformers/Api/Client/ActivityLogTransformer.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Transformers\Api\Client;
|
||||
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Models\ActivityLog;
|
||||
|
||||
class ActivityLogTransformer extends BaseClientTransformer
|
||||
{
|
||||
protected array $availableIncludes = ['actor'];
|
||||
|
||||
public function getResourceName(): string
|
||||
{
|
||||
return ActivityLog::RESOURCE_NAME;
|
||||
}
|
||||
|
||||
public function transform(ActivityLog $model): array
|
||||
{
|
||||
return [
|
||||
'batch' => $model->batch,
|
||||
'event' => $model->event,
|
||||
'ip' => $model->ip,
|
||||
'description' => $model->description,
|
||||
'properties' => $model->properties,
|
||||
'timestamp' => $model->timestamp->toIso8601String(),
|
||||
];
|
||||
}
|
||||
|
||||
public function includeActor(ActivityLog $model)
|
||||
{
|
||||
if (!$model->actor instanceof User) {
|
||||
return $this->null();
|
||||
}
|
||||
|
||||
return $this->item($model->actor, $this->makeTransformer(UserTransformer::class), User::RESOURCE_NAME);
|
||||
}
|
||||
}
|
Reference in a new issue