Documents for tasks

This commit is contained in:
David Bomba 2020-10-12 08:36:59 +11:00
parent 4c08187bf1
commit f1c5f37189
2 changed files with 24 additions and 0 deletions

View File

@ -11,6 +11,7 @@
namespace App\Transformers;
use App\Models\Document;
use App\Models\Task;
use App\Utils\Traits\MakesHash;
@ -22,14 +23,23 @@ class TaskTransformer extends EntityTransformer
use MakesHash;
protected $defaultIncludes = [
'documents'
];
/**
* @var array
*/
protected $availableIncludes = [
'documents'
];
public function includeDocuments(Vendor $vendor)
{
$transformer = new DocumentTransformer($this->serializer);
return $this->includeCollection($task->documents, $transformer, Document::class);
}
public function transform(Task $task)
{
return [

View File

@ -140,4 +140,18 @@ class DocumentsApiTest extends TestCase
}
// public function testTaskDocuments()
// {
// $response = $this->withHeaders([
// 'X-API-SECRET' => config('ninja.api_secret'),
// 'X-API-TOKEN' => $this->token,
// ])->get('/api/v1/tasks');
// $response->assertStatus(200);
// $arr = $response->json();
// $this->assertArrayHasKey('documents', $arr['data'][0]);
// }
}