Added documents to the expense transformer

This commit is contained in:
Hillel Coren 2017-07-03 21:42:00 +03:00
parent 80ad0a18d4
commit 7a4c46c771
2 changed files with 15 additions and 2 deletions

View File

@ -11,8 +11,9 @@ class DocumentTransformer extends EntityTransformer
{
/**
* @SWG\Property(property="id", type="integer", example=1, readOnly=true)
* @SWG\Property(property="name", type="string", example="Test")
* @SWG\Property(property="type", type="string", example="CSV")
* @SWG\Property(property="name", type="string", example="sample.png")
* @SWG\Property(property="type", type="string", example="png")
* @SWG\Property(property="path", type="string", example="abc/sample.png")
* @SWG\Property(property="invoice_id", type="integer", example=1)
* @SWG\Property(property="updated_at", type="integer", example=1451160233, readOnly=true)
* @SWG\Property(property="archived_at", type="integer", example=1451160233, readOnly=true)
@ -23,6 +24,7 @@ class DocumentTransformer extends EntityTransformer
'id' => (int) $document->public_id,
'name' => $document->name,
'type' => $document->type,
'path' => $document->path,
'invoice_id' => isset($document->invoice->public_id) ? (int) $document->invoice->public_id : null,
'expense_id' => isset($document->expense->public_id) ? (int) $document->expense->public_id : null,
'updated_at' => $this->getTimestamp($document->updated_at),

View File

@ -34,6 +34,10 @@ class ExpenseTransformer extends EntityTransformer
* @SWG\Property(property="vendor_id", type="integer", example=1)
*/
protected $availableIncludes = [
'documents',
];
public function __construct($account = null, $serializer = null, $client = null)
{
parent::__construct($account, $serializer);
@ -41,6 +45,13 @@ class ExpenseTransformer extends EntityTransformer
$this->client = $client;
}
public function includeDocuments(Expense $expense)
{
$transformer = new DocumentTransformer($this->account, $this->serializer);
return $this->includeCollection($expense->documents, $transformer, ENTITY_DOCUMENT);
}
public function transform(Expense $expense)
{
return array_merge($this->getDefaults($expense), [