Skip to content

Commit b8fbdec

Browse files
authored
Merge pull request #208 from fleetbase/feat/add-user-created-new-company-event
Add an event for when user creates a new additional company
2 parents dc193b0 + 09bf377 commit b8fbdec

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fleetbase/core-api",
3-
"version": "1.6.42",
3+
"version": "1.6.43",
44
"description": "Core Framework and Resources for Fleetbase API",
55
"keywords": [
66
"fleetbase",
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Fleetbase\Events;
4+
5+
use Fleetbase\Models\Company;
6+
use Fleetbase\Models\User;
7+
use Illuminate\Broadcasting\InteractsWithSockets;
8+
use Illuminate\Foundation\Events\Dispatchable;
9+
use Illuminate\Queue\SerializesModels;
10+
11+
class UserCreatedNewCompany
12+
{
13+
use Dispatchable;
14+
use InteractsWithSockets;
15+
use SerializesModels;
16+
17+
public $user;
18+
public $company;
19+
20+
/**
21+
* Create a new event instance.
22+
*
23+
* @return void
24+
*/
25+
public function __construct(User $user, Company $company)
26+
{
27+
$this->user = $user;
28+
$this->company = $company;
29+
}
30+
}

src/Http/Controllers/Internal/v1/AuthController.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Fleetbase\Http\Controllers\Internal\v1;
44

5+
use Fleetbase\Events\UserCreatedNewCompany;
56
use Fleetbase\Exceptions\InvalidVerificationCodeException;
67
use Fleetbase\Http\Controllers\Controller;
78
use Fleetbase\Http\Requests\AdminRequest;
@@ -799,7 +800,22 @@ public function createOrganization(Request $request)
799800

800801
try {
801802
$company = Company::create($input);
802-
$company->assignUser($user, 'Administrator');
803+
804+
// Set company owner
805+
$company->setOwner($user)->save();
806+
807+
// Assign user to organization
808+
$user->assignCompany($company, 'Administrator');
809+
$user->assignSingleRole('Administrator');
810+
811+
// Company onboarding is not necessary - set correct flags
812+
$company->update([
813+
'onboarding_completed_at' => now(),
814+
'onboarding_completed_by_uuid' => $user->uuid,
815+
]);
816+
817+
// Fire event that user created a new organization
818+
event(new UserCreatedNewCompany($user, $company));
803819
} catch (\Throwable $e) {
804820
return response()->error($e->getMessage());
805821
}

0 commit comments

Comments
 (0)