Use a standardized transformer base; replace all client transformers to call that base

This commit is contained in:
Dane Everitt 2021-08-07 13:06:45 -07:00
parent 2203a4d87e
commit cf500a1a54
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
25 changed files with 255 additions and 379 deletions

View file

@ -2,11 +2,10 @@
namespace Pterodactyl\Transformers\Api\Client;
use Pterodactyl\Models\Task;
use Pterodactyl\Models\Schedule;
use Illuminate\Database\Eloquent\Model;
use Pterodactyl\Transformers\Api\Transformer;
class ScheduleTransformer extends BaseClientTransformer
class ScheduleTransformer extends Transformer
{
/**
* @var array
@ -18,20 +17,12 @@ class ScheduleTransformer extends BaseClientTransformer
*/
protected $defaultIncludes = ['tasks'];
/**
* {@inheritdoc}
*/
public function getResourceName(): string
{
return Schedule::RESOURCE_NAME;
}
/**
* Returns a transformed schedule model such that a client can view the information.
*
* @return array
*/
public function transform(Schedule $model)
public function transform(Schedule $model): array
{
return [
'id' => $model->id,
@ -46,10 +37,10 @@ class ScheduleTransformer extends BaseClientTransformer
'is_active' => $model->is_active,
'is_processing' => $model->is_processing,
'only_when_online' => $model->only_when_online,
'last_run_at' => $model->last_run_at ? $model->last_run_at->toIso8601String() : null,
'next_run_at' => $model->next_run_at ? $model->next_run_at->toIso8601String() : null,
'created_at' => $model->created_at->toIso8601String(),
'updated_at' => $model->updated_at->toIso8601String(),
'last_run_at' => self::formatTimestamp($model->last_run_at),
'next_run_at' => self::formatTimestamp($model->next_run_at),
'created_at' => self::formatTimestamp($model->created_at),
'updated_at' => self::formatTimestamp($model->updated_at),
];
}
@ -57,15 +48,9 @@ class ScheduleTransformer extends BaseClientTransformer
* Allows attaching the tasks specific to the schedule in the response.
*
* @return \League\Fractal\Resource\Collection
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
*/
public function includeTasks(Schedule $model)
{
return $this->collection(
$model->tasks,
$this->makeTransformer(TaskTransformer::class),
Task::RESOURCE_NAME
);
return $this->collection($model->tasks, new TaskTransformer());
}
}