mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-15 11:42:15 +01:00
Added member and invitation endpoints
This commit is contained in:
68
database/factories/MembershipFactory.php
Normal file
68
database/factories/MembershipFactory.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Models\Membership;
|
||||
use App\Models\Organization;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Membership>
|
||||
*/
|
||||
class MembershipFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'role' => Role::Employee,
|
||||
'organization_id' => OrganizationFactory::class,
|
||||
'user_id' => UserFactory::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function forOrganization(Organization $organization): static
|
||||
{
|
||||
return $this->state(function (array $attributes) use ($organization): array {
|
||||
return [
|
||||
'organization_id' => $organization->getKey(),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function forUser(User $user): static
|
||||
{
|
||||
return $this->state(function (array $attributes) use ($user): array {
|
||||
return [
|
||||
'user_id' => $user->getKey(),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
return [
|
||||
'email_verified_at' => null,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function attachToOrganization(Organization $organization, array $pivot = []): static
|
||||
{
|
||||
return $this->afterCreating(function (User $user) use ($organization, $pivot) {
|
||||
$user->organizations()->attach($organization, $pivot);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -81,15 +81,17 @@ class UserFactory extends Factory
|
||||
*/
|
||||
public function withPersonalOrganization(?callable $callback = null): static
|
||||
{
|
||||
return $this->has(
|
||||
Organization::factory()
|
||||
->state(fn (array $attributes, User $user) => [
|
||||
return $this->afterCreating(function (User $user) use ($callback): void {
|
||||
$organization = Organization::factory()
|
||||
->state(fn (array $attributes) => [
|
||||
'name' => $user->name.'\'s Organization',
|
||||
'user_id' => $user->id,
|
||||
'personal_team' => true,
|
||||
])
|
||||
->when(is_callable($callback), $callback),
|
||||
'ownedTeams'
|
||||
);
|
||||
->when(is_callable($callback), $callback)
|
||||
->create();
|
||||
|
||||
$organization->users()->attach($user, ['role' => 'owner']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ return new class extends Migration
|
||||
->onDelete('restrict')
|
||||
->onUpdate('cascade');
|
||||
$table->timestamps();
|
||||
$table->unique(['project_id', 'user_id']);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Database\Seeders;
|
||||
|
||||
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use App\Enums\Role;
|
||||
use App\Models\Client;
|
||||
use App\Models\Organization;
|
||||
use App\Models\Project;
|
||||
@@ -24,40 +25,43 @@ class DatabaseSeeder extends Seeder
|
||||
{
|
||||
$this->deleteAll();
|
||||
$userAcmeOwner = User::factory()->create([
|
||||
'name' => 'ACME Admin',
|
||||
'name' => 'Acme Owner',
|
||||
'email' => 'owner@acme.test',
|
||||
]);
|
||||
$organizationAcme = Organization::factory()->withOwner($userAcmeOwner)->create([
|
||||
'name' => 'ACME Corp',
|
||||
]);
|
||||
$userAcmeManager = User::factory()->withPersonalOrganization()->create([
|
||||
'name' => 'Test User',
|
||||
'name' => 'Acme Manager',
|
||||
'email' => 'test@example.com',
|
||||
]);
|
||||
$userAcmeAdmin = User::factory()->withPersonalOrganization()->create([
|
||||
'name' => 'ACME Admin',
|
||||
'name' => 'Acme Admin',
|
||||
'email' => 'admin@acme.test',
|
||||
]);
|
||||
$userAcmeEmployee = User::factory()->withPersonalOrganization()->create([
|
||||
'name' => 'Max Mustermann',
|
||||
'name' => 'Acme Employee',
|
||||
'email' => 'max.mustermann@acme.test',
|
||||
]);
|
||||
$userAcmePlaceholder = User::factory()->placeholder()->create([
|
||||
'name' => 'Old Employee',
|
||||
'name' => 'Acme Placeholder',
|
||||
'email' => 'old.employee@acme.test',
|
||||
'password' => null,
|
||||
]);
|
||||
$userAcmeOwner->organizations()->attach($organizationAcme, [
|
||||
'role' => Role::Owner->value,
|
||||
]);
|
||||
$userAcmeManager->organizations()->attach($organizationAcme, [
|
||||
'role' => 'manager',
|
||||
'role' => Role::Manager->value,
|
||||
]);
|
||||
$userAcmeAdmin->organizations()->attach($organizationAcme, [
|
||||
'role' => 'admin',
|
||||
'role' => Role::Admin->value,
|
||||
]);
|
||||
$userAcmeEmployee->organizations()->attach($organizationAcme, [
|
||||
'role' => 'employee',
|
||||
'role' => Role::Employee->value,
|
||||
]);
|
||||
$userAcmePlaceholder->organizations()->attach($organizationAcme, [
|
||||
'role' => 'employee',
|
||||
'role' => Role::Placeholder->value,
|
||||
]);
|
||||
|
||||
$timeEntriesAcmeAdmin = TimeEntry::factory()
|
||||
|
||||
Reference in New Issue
Block a user