mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-08-07 10:01:47 -04:00
Working on the API
This commit is contained in:
parent
26ec972819
commit
ebd63f1805
@ -10,10 +10,6 @@ class AccountTokenTransformer extends TransformerAbstract
|
|||||||
public function transform(AccountToken $account_token)
|
public function transform(AccountToken $account_token)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => (int) $account_token->id,
|
|
||||||
'account_id' =>(int) $account_token->account_id,
|
|
||||||
'user_id' => (int) $account_token->user_id,
|
|
||||||
'public_id' => (int) $account_token->public_id,
|
|
||||||
'name' => $account_token->name,
|
'name' => $account_token->name,
|
||||||
'token' => $account_token->token
|
'token' => $account_token->token
|
||||||
];
|
];
|
||||||
|
@ -9,21 +9,17 @@ class AccountTransformer extends TransformerAbstract
|
|||||||
{
|
{
|
||||||
protected $defaultIncludes = [
|
protected $defaultIncludes = [
|
||||||
'users',
|
'users',
|
||||||
'account_tokens'
|
'clients',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function includeAccountTokens($account)
|
|
||||||
{
|
|
||||||
$account_token = AccountToken::whereAccountId($account->id)->whereName('ios_api_token')->first();
|
|
||||||
|
|
||||||
return $this->Item($account_token, new AccountTokenTransformer);
|
|
||||||
|
|
||||||
}
|
|
||||||
public function includeUsers($account)
|
public function includeUsers($account)
|
||||||
{
|
{
|
||||||
$users = $account->users;
|
return $this->collection($account->users, new UserTransformer);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->collection($users, new UserTransformer);
|
public function includeClients($account)
|
||||||
|
{
|
||||||
|
return $this->collection($account->clients, new ClientTransformer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function transform(Account $account)
|
public function transform(Account $account)
|
||||||
|
34
app/Ninja/Transformers/ClientTransformer.php
Normal file
34
app/Ninja/Transformers/ClientTransformer.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php namespace App\Ninja\Transformers;
|
||||||
|
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Models\Contact;
|
||||||
|
use League\Fractal;
|
||||||
|
use League\Fractal\TransformerAbstract;
|
||||||
|
|
||||||
|
class ClientTransformer extends TransformerAbstract
|
||||||
|
{
|
||||||
|
protected $defaultIncludes = [
|
||||||
|
'contacts',
|
||||||
|
'invoices',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function includeContacts($client)
|
||||||
|
{
|
||||||
|
return $this->collection($client->contacts, new ContactTransformer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function includeInvoices($client)
|
||||||
|
{
|
||||||
|
return $this->collection($client->invoices, new InvoiceTransformer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function transform(Client $client)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => (int) $client->public_id,
|
||||||
|
'name' => $client->name,
|
||||||
|
'balance' => (float) $client->balance,
|
||||||
|
'paid_to_date' => (float) $client->paid_to_date,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
18
app/Ninja/Transformers/ContactTransformer.php
Normal file
18
app/Ninja/Transformers/ContactTransformer.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php namespace App\Ninja\Transformers;
|
||||||
|
|
||||||
|
use App\Models\Contact;
|
||||||
|
use League\Fractal;
|
||||||
|
use League\Fractal\TransformerAbstract;
|
||||||
|
|
||||||
|
class ContactTransformer extends TransformerAbstract
|
||||||
|
{
|
||||||
|
public function transform(Contact $contact)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => (int) $contact->public_id,
|
||||||
|
'first_name' => $contact->first_name,
|
||||||
|
'last_name' => $contact->last_name,
|
||||||
|
'email' => $contact->email,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
16
app/Ninja/Transformers/InvoiceItemTransformer.php
Normal file
16
app/Ninja/Transformers/InvoiceItemTransformer.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php namespace App\Ninja\Transformers;
|
||||||
|
|
||||||
|
use App\Models\InvoiceItem;
|
||||||
|
use League\Fractal;
|
||||||
|
use League\Fractal\TransformerAbstract;
|
||||||
|
|
||||||
|
class InvoiceItemTransformer extends TransformerAbstract
|
||||||
|
{
|
||||||
|
public function transform(InvoiceItem $item)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => (int) $item->public_id,
|
||||||
|
'product_key' => $item->product_key,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
27
app/Ninja/Transformers/InvoiceTransformer.php
Normal file
27
app/Ninja/Transformers/InvoiceTransformer.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php namespace App\Ninja\Transformers;
|
||||||
|
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use League\Fractal;
|
||||||
|
use League\Fractal\TransformerAbstract;
|
||||||
|
|
||||||
|
class InvoiceTransformer extends TransformerAbstract
|
||||||
|
{
|
||||||
|
protected $defaultIncludes = [
|
||||||
|
'invoice_items',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function includeInvoiceItems($invoice)
|
||||||
|
{
|
||||||
|
return $this->collection($invoice->invoice_items, new InvoiceItemTransformer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function transform(Invoice $invoice)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => (int) $invoice->public_id,
|
||||||
|
'invoice_number' => $invoice->invoice_number,
|
||||||
|
'amount' => (float) $invoice->amount,
|
||||||
|
'balance' => (float) $invoice->balance,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
34
app/Ninja/Transformers/UserAccountTransformer.php
Normal file
34
app/Ninja/Transformers/UserAccountTransformer.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php namespace App\Ninja\Transformers;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use League\Fractal;
|
||||||
|
use League\Fractal\TransformerAbstract;
|
||||||
|
|
||||||
|
class UserAccountTransformer extends TransformerAbstract
|
||||||
|
{
|
||||||
|
protected $defaultIncludes = [
|
||||||
|
'account_tokens'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function includeAccountTokens($user)
|
||||||
|
{
|
||||||
|
$tokens = $user->account->account_tokens->filter(function($token) use ($user) {
|
||||||
|
return $token->user_id === $user->id;
|
||||||
|
});
|
||||||
|
|
||||||
|
return $this->collection($tokens, new AccountTokenTransformer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function transform(User $user)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'account_key' => $user->account->account_key,
|
||||||
|
'name' => $user->account->name,
|
||||||
|
'user' => [
|
||||||
|
'first_name' => $user->first_name,
|
||||||
|
'last_name' => $user->last_name,
|
||||||
|
'email' => $user->email,
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user