1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Modifying JSON structure for API

This commit is contained in:
David Bomba 2015-11-15 21:43:32 +11:00
parent 3ce55d22ef
commit e3c7fa572b
7 changed files with 16 additions and 13 deletions

View File

@ -10,6 +10,7 @@ class AccountTransformer extends TransformerAbstract
protected $defaultIncludes = [
'users',
'clients',
'invoices'
];
public function includeUsers(Account $account)
@ -22,6 +23,11 @@ class AccountTransformer extends TransformerAbstract
return $this->collection($account->clients, new ClientTransformer($account));
}
public function includeInvoices(Account $account)
{
return $this->collection($account->invoices, new InvoiceTransformer($account));
}
public function transform(Account $account)
{
return [

View File

@ -41,9 +41,9 @@ class ClientTransformer extends EntityTransformer
*/
protected $defaultIncludes = [
'contacts',
'invoices',
'quotes',
// 'contacts',
// 'invoices',
// 'quotes',
];
public function includeContacts(Client $client)
@ -64,7 +64,7 @@ class ClientTransformer extends EntityTransformer
public function transform(Client $client)
{
return [
'public_id' => (int) $client->public_id,
'id' => (int) $client->public_id,
'name' => $client->name,
'balance' => (float) $client->balance,
'paid_to_date' => (float) $client->paid_to_date,

View File

@ -9,7 +9,7 @@ class ContactTransformer extends EntityTransformer
public function transform(Contact $contact)
{
return [
'public_id' => (int) $contact->public_id,
'id' => (int) $contact->public_id,
'first_name' => $contact->first_name,
'last_name' => $contact->last_name,
'email' => $contact->email,

View File

@ -9,7 +9,7 @@ class InvoiceItemTransformer extends EntityTransformer
public function transform(InvoiceItem $item)
{
return [
'public_id' => (int) $item->public_id,
'id' => (int) $item->public_id,
'product_key' => $item->product_key,
'account_key' => $this->account->account_key,
'user_id' => (int) $item->user_id,

View File

@ -20,13 +20,11 @@ class InvoiceTransformer extends EntityTransformer
* @SWG\Property(property="invoice_status_id", type="integer", example=1)
*/
protected $client;
public function __construct(Account $account, Client $client)
public function __construct(Account $account)
{
parent::__construct($account);
$this->client = $client;
}
protected $defaultIncludes = [
@ -42,10 +40,9 @@ class InvoiceTransformer extends EntityTransformer
{
return [
'id' => (int) $invoice->public_id,
'invoice_number' => $invoice->invoice_number,
'amount' => (float) $invoice->amount,
'balance' => (float) $invoice->balance,
'client_id' => (int) $this->client->public_id,
'client_id' => (int) $invoice->client->public_id,
'invoice_status_id' => (int) $invoice->invoice_status_id,
'updated_at' => $invoice->updated_at,
'deleted_at' => $invoice->deleted_at,

View File

@ -17,7 +17,7 @@ class QuoteTransformer extends EntityTransformer
public function transform(Invoice $invoice)
{
return [
'public_id' => (int) $invoice->public_id,
'id' => (int) $invoice->public_id,
'quote_number' => $invoice->invoice_number,
'amount' => (float) $invoice->amount,
];

View File

@ -9,7 +9,7 @@ class UserTransformer extends EntityTransformer
public function transform(User $user)
{
return [
'public_id' => (int) ($user->public_id + 1),
'id' => (int) ($user->public_id + 1),
'first_name' => $user->first_name,
'last_name' => $user->last_name,
'email' => $user->email,