1
0
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:
Hillel Coren 2016-11-16 13:12:10 +02:00
parent 04bbf1b2ae
commit de2825750d
2 changed files with 4 additions and 8 deletions

View File

@ -41,6 +41,7 @@ class TaskApiController extends BaseAPIController
{
$tasks = Task::scope()
->withTrashed()
->with('client', 'invoice')
->orderBy('created_at', 'desc');
return $this->listResponse($tasks);

View File

@ -38,22 +38,17 @@ class TaskTransformer extends EntityTransformer
public function transform(Task $task)
{
if($task->invoice)
$invoiceId = $task->invoice->public_id;
else
$invoiceId = null;
return array_merge($this->getDefaults($task), [
'id' => (int) $task->public_id,
'description' => $task->description,
'duration' => $task->getDuration(),
'updated_at' => (int) $this->getTimestamp($task->updated_at),
'archived_at' => (int) $this->getTimestamp($task->deleted_at),
'invoice_id' => $invoiceId,
'client_id' => (int) $task->client->public_id,
'invoice_id' => $task->invoice ? (int) $task->invoice->public_id : false,
'client_id' => $task->client ? (int) $task->client->public_id : false,
'is_deleted' => (bool) $task->is_deleted,
'time_log' => $task->time_log,
'is_running' => (bool) $task->is_running,
]);
}
}
}