mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 12:12:48 +01:00
Add eager loading to API tasks
This commit is contained in:
parent
04bbf1b2ae
commit
de2825750d
@ -41,6 +41,7 @@ class TaskApiController extends BaseAPIController
|
|||||||
{
|
{
|
||||||
$tasks = Task::scope()
|
$tasks = Task::scope()
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
|
->with('client', 'invoice')
|
||||||
->orderBy('created_at', 'desc');
|
->orderBy('created_at', 'desc');
|
||||||
|
|
||||||
return $this->listResponse($tasks);
|
return $this->listResponse($tasks);
|
||||||
|
@ -38,22 +38,17 @@ class TaskTransformer extends EntityTransformer
|
|||||||
|
|
||||||
public function transform(Task $task)
|
public function transform(Task $task)
|
||||||
{
|
{
|
||||||
if($task->invoice)
|
|
||||||
$invoiceId = $task->invoice->public_id;
|
|
||||||
else
|
|
||||||
$invoiceId = null;
|
|
||||||
|
|
||||||
return array_merge($this->getDefaults($task), [
|
return array_merge($this->getDefaults($task), [
|
||||||
'id' => (int) $task->public_id,
|
'id' => (int) $task->public_id,
|
||||||
'description' => $task->description,
|
'description' => $task->description,
|
||||||
'duration' => $task->getDuration(),
|
'duration' => $task->getDuration(),
|
||||||
'updated_at' => (int) $this->getTimestamp($task->updated_at),
|
'updated_at' => (int) $this->getTimestamp($task->updated_at),
|
||||||
'archived_at' => (int) $this->getTimestamp($task->deleted_at),
|
'archived_at' => (int) $this->getTimestamp($task->deleted_at),
|
||||||
'invoice_id' => $invoiceId,
|
'invoice_id' => $task->invoice ? (int) $task->invoice->public_id : false,
|
||||||
'client_id' => (int) $task->client->public_id,
|
'client_id' => $task->client ? (int) $task->client->public_id : false,
|
||||||
'is_deleted' => (bool) $task->is_deleted,
|
'is_deleted' => (bool) $task->is_deleted,
|
||||||
'time_log' => $task->time_log,
|
'time_log' => $task->time_log,
|
||||||
'is_running' => (bool) $task->is_running,
|
'is_running' => (bool) $task->is_running,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user