diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index 2a261ab34b4d..8a7a7275d509 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -12,9 +12,13 @@ namespace App\Http\Controllers; use App\Http\Requests\Company\CreateCompanyRequest; +use App\Http\Requests\Company\ShowCompanyRequest; use App\Http\Requests\SignupRequest; use App\Jobs\Company\CreateCompany; use App\Jobs\RegisterNewAccount; +use App\Models\Company; +use App\Transformers\CompanyTransformer; +use App\Utils\Traits\MakesHash; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -27,6 +31,11 @@ use Illuminate\Support\Facades\Hash; class CompanyController extends BaseController { use DispatchesJobs; + use MakesHash; + + protected $entity_type = Company::class; + + protected $entity_transformer = CompanyTransformer::class; /** * CompanyController constructor. @@ -68,10 +77,9 @@ class CompanyController extends BaseController public function store(CreateCompanyRequest $request) { - CreateCompany::dispatchNow($request); + $company = CreateCompany::dispatchNow($request, auth()->user()->company()->account); - //todo redirect to localization setup workflow - return redirect()->route('dashboard.index'); + return $this->itemResponse($company); } @@ -81,7 +89,7 @@ class CompanyController extends BaseController * @param int $id * @return \Illuminate\Http\Response */ - public function show($id) + public function show(ShowCompanyRequest $request, Company $company) { // } diff --git a/app/Http/Requests/Company/CreateCompanyRequest.php b/app/Http/Requests/Company/CreateCompanyRequest.php new file mode 100644 index 000000000000..08131c85b864 --- /dev/null +++ b/app/Http/Requests/Company/CreateCompanyRequest.php @@ -0,0 +1,41 @@ +user()->can('create', Company::class); + + } + + public function rules() + { + + return [ + 'name' => 'required' + ]; + + } + +} \ No newline at end of file diff --git a/app/Http/Requests/Company/DestroyCompanyRequest b/app/Http/Requests/Company/DestroyCompanyRequest new file mode 100644 index 000000000000..a67232090f98 --- /dev/null +++ b/app/Http/Requests/Company/DestroyCompanyRequest @@ -0,0 +1,30 @@ +user()->can('edit', $this->company); + } + +} \ No newline at end of file diff --git a/app/Http/Requests/Company/EditCompanyRequest.php b/app/Http/Requests/Company/EditCompanyRequest.php new file mode 100644 index 000000000000..12bb2ce8b293 --- /dev/null +++ b/app/Http/Requests/Company/EditCompanyRequest.php @@ -0,0 +1,49 @@ +user()->can('edit', $this->company); + } + + public function rules() + { + $rules = []; + + return $rules; + } + + + public function sanitize() + { + $input = $this->all(); + + //$input['id'] = $this->encodePrimaryKey($input['id']); + + //$this->replace($input); + + return $this->all(); + } + +} \ No newline at end of file diff --git a/app/Http/Requests/Company/ShowCompanyRequest.php b/app/Http/Requests/Company/ShowCompanyRequest.php new file mode 100644 index 000000000000..6a2785ae2fc3 --- /dev/null +++ b/app/Http/Requests/Company/ShowCompanyRequest.php @@ -0,0 +1,30 @@ +user()->can('view', $this->company); + } + +} \ No newline at end of file diff --git a/app/Http/Requests/Company/StoreCompanyRequest.php b/app/Http/Requests/Company/StoreCompanyRequest.php new file mode 100644 index 000000000000..8c2a26f9bc98 --- /dev/null +++ b/app/Http/Requests/Company/StoreCompanyRequest.php @@ -0,0 +1,43 @@ +user()->can('create', Company::class); + } + + public function rules() + { + //$this->sanitize(); + + return [ + // 'client_id' => 'required', + // 'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx', + ]; + } + + +} + diff --git a/app/Http/Requests/Company/UpdateCompanyRequest.php b/app/Http/Requests/Company/UpdateCompanyRequest.php new file mode 100644 index 000000000000..edd4a4f59d72 --- /dev/null +++ b/app/Http/Requests/Company/UpdateCompanyRequest.php @@ -0,0 +1,41 @@ +user()->can('edit', $this->company); + + } + + + public function rules() + { + return [ + // 'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx', + ]; + } + +} \ No newline at end of file diff --git a/app/Jobs/Company/CreateCompany.php b/app/Jobs/Company/CreateCompany.php index 73a05812d0e1..e6653f9c0b14 100644 --- a/app/Jobs/Company/CreateCompany.php +++ b/app/Jobs/Company/CreateCompany.php @@ -33,10 +33,13 @@ class CreateCompany * @return void */ - public function __construct(array $request, $account = false) + public function __construct(array $request, $account) { + $this->request = $request; + $this->account = $account; + } /** @@ -48,7 +51,7 @@ class CreateCompany { $company = new Company(); - $company->name = $this->request['first_name'] . ' ' . $this->request['last_name']; + $company->name = $this->request['name'] ?: $this->request['first_name'] . ' ' . $this->request['last_name']; $company->account_id = $this->account->id; $company->company_key = $this->createHash(); $company->ip = request()->ip(); diff --git a/tests/Feature/AccountTest.php b/tests/Feature/AccountTest.php index 23d077bbc777..b5e275372d12 100644 --- a/tests/Feature/AccountTest.php +++ b/tests/Feature/AccountTest.php @@ -41,6 +41,7 @@ class AccountTest extends TestCase $data = [ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, + 'name' => $this->faker->company, 'email' => $this->faker->unique()->safeEmail, 'password' => 'ALongAndBrilliantPassword123', '_token' => csrf_token(), @@ -60,7 +61,8 @@ class AccountTest extends TestCase $data = [ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, - 'email' => $this->faker->unique()->safeEmail, + 'name' => $this->faker->company, + 'email' => $this->faker->unique()->safeEmail, 'password' => 'ALongAndBrilliantPassword123', 'privacy_policy' => 1, 'terms_of_service' => 1 diff --git a/tests/Feature/ClientTest.php b/tests/Feature/ClientTest.php index 7df863fa233c..93bb49360c6d 100644 --- a/tests/Feature/ClientTest.php +++ b/tests/Feature/ClientTest.php @@ -46,7 +46,8 @@ class ClientTest extends TestCase $data = [ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, - 'email' => $this->faker->unique()->safeEmail, + 'name' => $this->faker->company, + 'email' => $this->faker->unique()->safeEmail, 'password' => 'ALongAndBrilliantPassword123', '_token' => csrf_token(), 'privacy_policy' => 1, @@ -86,7 +87,8 @@ class ClientTest extends TestCase $data = [ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, - 'email' => $this->faker->unique()->safeEmail, + 'name' => $this->faker->company, + 'email' => $this->faker->unique()->safeEmail, 'password' => 'ALongAndBrilliantPassword123', '_token' => csrf_token(), 'privacy_policy' => 1, diff --git a/tests/Feature/InvoiceTest.php b/tests/Feature/InvoiceTest.php index dcf666ea62f8..c7224ee06dce 100644 --- a/tests/Feature/InvoiceTest.php +++ b/tests/Feature/InvoiceTest.php @@ -46,7 +46,8 @@ class InvoiceTest extends TestCase $data = [ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, - 'email' => $this->faker->unique()->safeEmail, + 'name' => $this->faker->company, + 'email' => $this->faker->unique()->safeEmail, 'password' => 'ALongAndBrilliantPassword123', '_token' => csrf_token(), 'privacy_policy' => 1, @@ -109,6 +110,7 @@ class InvoiceTest extends TestCase $data = [ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, + 'name' => $this->faker->company, 'email' => $this->faker->unique()->safeEmail, 'password' => 'ALongAndBrilliantPassword123', '_token' => csrf_token(), diff --git a/tests/Feature/PaymentTest.php b/tests/Feature/PaymentTest.php index 79a2c9949dff..c96f327ef9ef 100644 --- a/tests/Feature/PaymentTest.php +++ b/tests/Feature/PaymentTest.php @@ -46,7 +46,8 @@ class PaymentTest extends TestCase $data = [ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, - 'email' => $this->faker->unique()->safeEmail, + 'name' => $this->faker->company, + 'email' => $this->faker->unique()->safeEmail, 'password' => 'ALongAndBrilliantPassword123', '_token' => csrf_token(), 'privacy_policy' => 1, @@ -109,7 +110,8 @@ class PaymentTest extends TestCase $data = [ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, - 'email' => $this->faker->unique()->safeEmail, + 'name' => $this->faker->company, + 'email' => $this->faker->unique()->safeEmail, 'password' => 'ALongAndBrilliantPassword123', '_token' => csrf_token(), 'privacy_policy' => 1, diff --git a/tests/Feature/ProductTest.php b/tests/Feature/ProductTest.php index 78b4fb99b530..278a68743f1e 100644 --- a/tests/Feature/ProductTest.php +++ b/tests/Feature/ProductTest.php @@ -44,7 +44,8 @@ class ProductTest extends TestCase $data = [ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, - 'email' => $this->faker->unique()->safeEmail, + 'name' => $this->faker->company, + 'email' => $this->faker->unique()->safeEmail, 'password' => 'ALongAndBrilliantPassword123', '_token' => csrf_token(), 'privacy_policy' => 1, diff --git a/tests/Feature/QuoteTest.php b/tests/Feature/QuoteTest.php index d8e87ae18005..30bac20efc5f 100644 --- a/tests/Feature/QuoteTest.php +++ b/tests/Feature/QuoteTest.php @@ -46,7 +46,8 @@ class QuoteTest extends TestCase $data = [ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, - 'email' => $this->faker->unique()->safeEmail, + 'name' => $this->faker->company, + 'email' => $this->faker->unique()->safeEmail, 'password' => 'ALongAndBrilliantPassword123', '_token' => csrf_token(), 'privacy_policy' => 1, @@ -109,7 +110,8 @@ class QuoteTest extends TestCase $data = [ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, - 'email' => $this->faker->unique()->safeEmail, + 'name' => $this->faker->company, + 'email' => $this->faker->unique()->safeEmail, 'password' => 'ALongAndBrilliantPassword123', '_token' => csrf_token(), 'privacy_policy' => 1, diff --git a/tests/Feature/RecurringInvoiceTest.php b/tests/Feature/RecurringInvoiceTest.php index b2ebed4983ac..74ab4eab3eda 100644 --- a/tests/Feature/RecurringInvoiceTest.php +++ b/tests/Feature/RecurringInvoiceTest.php @@ -46,7 +46,8 @@ class RecurringInvoiceTest extends TestCase $data = [ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, - 'email' => $this->faker->unique()->safeEmail, + 'name' => $this->faker->company, + 'email' => $this->faker->unique()->safeEmail, 'password' => 'ALongAndBrilliantPassword123', '_token' => csrf_token(), 'privacy_policy' => 1, @@ -109,7 +110,8 @@ class RecurringInvoiceTest extends TestCase $data = [ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, - 'email' => $this->faker->unique()->safeEmail, + 'name' => $this->faker->company, + 'email' => $this->faker->unique()->safeEmail, 'password' => 'ALongAndBrilliantPassword123', '_token' => csrf_token(), 'privacy_policy' => 1, diff --git a/tests/Feature/RecurringQuoteTest.php b/tests/Feature/RecurringQuoteTest.php index c9436c92cbbd..1594f5d3dd53 100644 --- a/tests/Feature/RecurringQuoteTest.php +++ b/tests/Feature/RecurringQuoteTest.php @@ -46,7 +46,8 @@ class RecurringQuoteTest extends TestCase $data = [ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, - 'email' => $this->faker->unique()->safeEmail, + 'name' => $this->faker->company, + 'email' => $this->faker->unique()->safeEmail, 'password' => 'ALongAndBrilliantPassword123', '_token' => csrf_token(), 'privacy_policy' => 1, @@ -109,7 +110,8 @@ class RecurringQuoteTest extends TestCase $data = [ 'first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, - 'email' => $this->faker->unique()->safeEmail, + 'name' => $this->faker->company, + 'email' => $this->faker->unique()->safeEmail, 'password' => 'ALongAndBrilliantPassword123', '_token' => csrf_token(), 'privacy_policy' => 1, diff --git a/tests/Feature/UserTest.php b/tests/Feature/UserTest.php new file mode 100644 index 000000000000..3893c75c768c --- /dev/null +++ b/tests/Feature/UserTest.php @@ -0,0 +1,81 @@ +faker = \Faker\Factory::create(); + + Model::reguard(); + + } + + public function testUserList() + { + + $data = [ + 'first_name' => $this->faker->firstName, + 'last_name' => $this->faker->lastName, + 'name' => $this->faker->company, + 'email' => $this->faker->unique()->safeEmail, + 'password' => 'ALongAndBrilliantPassword123', + '_token' => csrf_token(), + 'privacy_policy' => 1, + 'terms_of_service' => 1 + ]; + + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + ])->post('/api/v1/signup', $data); + + + $response->assertStatus(200); + + $acc = $response->json(); + + + $account = Account::find($this->decodePrimaryKey($acc['data']['id'])); + + $token = $account->default_company->tokens->first()->token; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $token, + ])->get('/api/v1/users'); + + $response->assertStatus(200); + + } + + +} \ No newline at end of file