diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 48a86b6fe078..802f5f30d4f5 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -14,7 +14,9 @@ namespace App\Http\Controllers; use App\Http\Requests\Account\CreateAccountRequest; use App\Jobs\Account\CreateAccount; use App\Models\Account; +use App\Models\CompanyUser; use App\Transformers\AccountTransformer; +use App\Transformers\CompanyUserTransformer; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; @@ -23,9 +25,9 @@ class AccountController extends BaseController { use DispatchesJobs; - protected $entity_type = Account::class; + protected $entity_type = CompanyUser::class; - protected $entity_transformer = AccountTransformer::class; + protected $entity_transformer = CompanyUserTransformer::class; public function __construct() { @@ -65,10 +67,9 @@ class AccountController extends BaseController { $account = CreateAccount::dispatchNow($request->all()); - - $account->load('company_users'); - - return $this->itemResponse($account); + + $ct = CompanyUser::whereUserId(auth()->user()->id); + return $this->listResponse($ct); } diff --git a/tests/Feature/ClientTest.php b/tests/Feature/ClientTest.php index a1f617f4f307..2c696b1973d8 100644 --- a/tests/Feature/ClientTest.php +++ b/tests/Feature/ClientTest.php @@ -65,7 +65,7 @@ class ClientTest extends TestCase $acc = $response->json(); - $account = Account::find($this->decodePrimaryKey($acc['data']['id'])); + $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id'])); $token = $account->default_company->tokens->first()->token; @@ -102,7 +102,7 @@ class ClientTest extends TestCase $acc = $response->json(); - $account = Account::find($this->decodePrimaryKey($acc['data']['id'])); + $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id'])); $company_token = $account->default_company->tokens()->first(); diff --git a/tests/Feature/CompanyTest.php b/tests/Feature/CompanyTest.php index 61fff26b0a92..60ba596d2d3f 100644 --- a/tests/Feature/CompanyTest.php +++ b/tests/Feature/CompanyTest.php @@ -65,7 +65,7 @@ class CompanyTest extends TestCase $acc = $response->json(); - $account = Account::find($this->decodePrimaryKey($acc['data']['id'])); + $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id'])); $token = $account->default_company->tokens->first()->token; diff --git a/tests/Feature/InvoiceTest.php b/tests/Feature/InvoiceTest.php index 0e76ba48f7de..77cbbb9145c8 100644 --- a/tests/Feature/InvoiceTest.php +++ b/tests/Feature/InvoiceTest.php @@ -61,7 +61,7 @@ class InvoiceTest extends TestCase $acc = $response->json(); - $account = Account::find($this->decodePrimaryKey($acc['data']['id'])); + $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id'])); $company_token = $account->default_company->tokens()->first(); $token = $company_token->token; @@ -125,7 +125,7 @@ class InvoiceTest extends TestCase $acc = $response->json(); - $account = Account::find($this->decodePrimaryKey($acc['data']['id'])); + $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id'])); $company_token = $account->default_company->tokens()->first(); $token = $company_token->token; diff --git a/tests/Feature/PaymentTest.php b/tests/Feature/PaymentTest.php index 3fcca2686d68..9aba1fa49b10 100644 --- a/tests/Feature/PaymentTest.php +++ b/tests/Feature/PaymentTest.php @@ -62,7 +62,7 @@ class PaymentTest extends TestCase $acc = $response->json(); - $account = Account::find($this->decodePrimaryKey($acc['data']['id'])); + $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id'])); $company_token = $account->default_company->tokens()->first(); $token = $company_token->token; @@ -126,7 +126,7 @@ class PaymentTest extends TestCase $acc = $response->json(); - $account = Account::find($this->decodePrimaryKey($acc['data']['id'])); + $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id'])); $company_token = $account->default_company->tokens()->first(); $token = $company_token->token; diff --git a/tests/Feature/ProductTest.php b/tests/Feature/ProductTest.php index 278a68743f1e..a49da7354226 100644 --- a/tests/Feature/ProductTest.php +++ b/tests/Feature/ProductTest.php @@ -62,7 +62,7 @@ class ProductTest extends TestCase $acc = $response->json(); - $account = Account::find($this->decodePrimaryKey($acc['data']['id'])); + $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id'])); $token = $account->default_company->tokens->first()->token; diff --git a/tests/Feature/QuoteTest.php b/tests/Feature/QuoteTest.php index ca6e0b5b276e..beed087dcbe6 100644 --- a/tests/Feature/QuoteTest.php +++ b/tests/Feature/QuoteTest.php @@ -61,7 +61,7 @@ class QuoteTest extends TestCase $acc = $response->json(); - $account = Account::find($this->decodePrimaryKey($acc['data']['id'])); + $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id'])); $company_token = $account->default_company->tokens()->first(); $token = $company_token->token; @@ -125,7 +125,7 @@ class QuoteTest extends TestCase $acc = $response->json(); - $account = Account::find($this->decodePrimaryKey($acc['data']['id'])); + $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id'])); $company_token = $account->default_company->tokens()->first(); $token = $company_token->token; diff --git a/tests/Feature/RecurringInvoiceTest.php b/tests/Feature/RecurringInvoiceTest.php index 0fec010c8a53..be5276f3b712 100644 --- a/tests/Feature/RecurringInvoiceTest.php +++ b/tests/Feature/RecurringInvoiceTest.php @@ -46,8 +46,8 @@ class RecurringInvoiceTest extends TestCase $data = [ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, - 'name' => $this->faker->company, - 'email' => $this->faker->unique()->safeEmail, + 'name' => $this->faker->company, + 'email' => $this->faker->unique()->safeEmail, 'password' => 'ALongAndBrilliantPassword123', '_token' => csrf_token(), 'privacy_policy' => 1, @@ -61,7 +61,7 @@ class RecurringInvoiceTest extends TestCase $acc = $response->json(); - $account = Account::find($this->decodePrimaryKey($acc['data']['id'])); + $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id'])); $company_token = $account->default_company->tokens()->first(); $token = $company_token->token; @@ -124,7 +124,7 @@ class RecurringInvoiceTest extends TestCase ])->post('/api/v1/signup', $data); $acc = $response->json(); - $account = Account::find($this->decodePrimaryKey($acc['data']['id'])); + $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id'])); $company_token = $account->default_company->tokens()->first(); $token = $company_token->token; diff --git a/tests/Feature/RecurringQuoteTest.php b/tests/Feature/RecurringQuoteTest.php index eed41bdb3cc7..a3b8e0efc288 100644 --- a/tests/Feature/RecurringQuoteTest.php +++ b/tests/Feature/RecurringQuoteTest.php @@ -61,7 +61,7 @@ class RecurringQuoteTest extends TestCase $acc = $response->json(); - $account = Account::find($this->decodePrimaryKey($acc['data']['id'])); + $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id'])); $company_token = $account->default_company->tokens()->first(); $token = $company_token->token; @@ -125,7 +125,7 @@ class RecurringQuoteTest extends TestCase $acc = $response->json(); - $account = Account::find($this->decodePrimaryKey($acc['data']['id'])); + $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id'])); $company_token = $account->default_company->tokens()->first(); $token = $company_token->token; diff --git a/tests/Feature/UserTest.php b/tests/Feature/UserTest.php index db69e58a2028..763131e2209d 100644 --- a/tests/Feature/UserTest.php +++ b/tests/Feature/UserTest.php @@ -64,7 +64,7 @@ class UserTest extends TestCase $acc = $response->json(); - $account = Account::find($this->decodePrimaryKey($acc['data']['id'])); + $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id'])); $token = $account->default_company->tokens->first()->token;