mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +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()
|
||||
->withTrashed()
|
||||
->with('client', 'invoice')
|
||||
->orderBy('created_at', 'desc');
|
||||
|
||||
return $this->listResponse($tasks);
|
||||
|
@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user