Added billable rates; Added project members; Added visibility to projects

This commit is contained in:
Constantin Graf
2024-03-28 18:50:04 +01:00
parent bb42b0940a
commit ba0212ea01
71 changed files with 3236 additions and 174 deletions

View File

@@ -34,4 +34,13 @@ class ClientFactory extends Factory
];
});
}
public function randomCreatedAt(): self
{
return $this->state(function (array $attributes): array {
return [
'created_at' => $this->faker->dateTimeBetween('-1 day', 'now'),
];
});
}
}

View File

@@ -22,6 +22,8 @@ class OrganizationFactory extends Factory
{
return [
'name' => $this->faker->unique()->company(),
'currency' => $this->faker->currencyCode,
'billable_rate' => $this->faker->numberBetween(50, 1000) * 100,
'user_id' => User::factory(),
'personal_team' => true,
];

View File

@@ -7,6 +7,8 @@ namespace Database\Factories;
use App\Models\Client;
use App\Models\Organization;
use App\Models\Project;
use App\Models\ProjectMember;
use App\Models\User;
use App\Service\ColorService;
use Illuminate\Database\Eloquent\Factories\Factory;
@@ -25,8 +27,10 @@ class ProjectFactory extends Factory
return [
'name' => $this->faker->company(),
'color' => app(ColorService::class)->getRandomColor(),
'organization_id' => Organization::factory(),
'billable_rate' => $this->faker->numberBetween(50, 1000) * 100,
'is_public' => false,
'client_id' => null,
'organization_id' => Organization::factory(),
];
}
@@ -39,6 +43,34 @@ class ProjectFactory extends Factory
});
}
public function isPublic(): self
{
return $this->state(function (array $attributes): array {
return [
'is_public' => true,
];
});
}
public function isPrivate(): self
{
return $this->state(function (array $attributes): array {
return [
'is_public' => false,
];
});
}
public function addMember(User $user, array $attributes = []): self
{
return $this->afterCreating(function (Project $project) use ($user, $attributes): void {
ProjectMember::factory()
->forProject($project)
->forUser($user)
->create($attributes);
});
}
public function withClient(): self
{
return $this->state(function (array $attributes): array {

View File

@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace Database\Factories;
use App\Models\Project;
use App\Models\ProjectMember;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<ProjectMember>
*/
class ProjectMemberFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'billable_rate' => $this->faker->numberBetween(50, 1000) * 100,
'project_id' => Project::factory(),
'user_id' => User::factory(),
];
}
public function forUser(User $user): self
{
return $this->state(function (array $attributes) use ($user): array {
return [
'user_id' => $user->getKey(),
];
});
}
public function forProject(Project $project): self
{
return $this->state(function (array $attributes) use ($project): array {
return [
'project_id' => $project->getKey(),
];
});
}
}

View File

@@ -34,4 +34,13 @@ class TagFactory extends Factory
];
});
}
public function randomCreatedAt(): self
{
return $this->state(function (array $attributes): array {
return [
'created_at' => $this->faker->dateTimeBetween('-1 day', 'now'),
];
});
}
}

View File

@@ -69,6 +69,13 @@ class UserFactory extends Factory
});
}
public function attachToOrganization(Organization $organization, array $pivot = []): static
{
return $this->afterCreating(function (User $user) use ($organization, $pivot) {
$user->organizations()->attach($organization, $pivot);
});
}
/**
* Indicate that the user should have a personal team.
*/

View File

@@ -18,6 +18,8 @@ return new class extends Migration
$table->foreignUuid('user_id')->index();
$table->string('name');
$table->boolean('personal_team');
$table->integer('billable_rate')->unsigned()->nullable();
$table->string('currency', 3);
$table->timestamps();
});
}

View File

@@ -18,6 +18,7 @@ return new class extends Migration
$table->foreignUuid('organization_id');
$table->foreignUuid('user_id');
$table->string('role')->nullable();
$table->integer('billable_rate')->unsigned()->nullable();
$table->timestamps();
$table->unique(['organization_id', 'user_id']);

View File

@@ -17,6 +17,8 @@ return new class extends Migration
$table->uuid('id')->primary();
$table->string('name', 255);
$table->string('color', 16);
$table->integer('billable_rate')->unsigned()->nullable();
$table->boolean('is_public')->default(false);
$table->uuid('client_id')->nullable();
$table->foreign('client_id')
->references('id')

View File

@@ -18,6 +18,7 @@ return new class extends Migration
$table->string('description', 500);
$table->dateTime('start');
$table->dateTime('end')->nullable();
$table->integer('billable_rate')->unsigned()->nullable();
$table->boolean('billable')->default(false);
$table->uuid('user_id');
$table->foreign('user_id')

View File

@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('project_members', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->integer('billable_rate')->unsigned()->nullable();
$table->uuid('project_id');
$table->foreign('project_id')
->references('id')
->on('projects')
->onDelete('restrict')
->onUpdate('cascade');
$table->uuid('user_id');
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('restrict')
->onUpdate('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('project_members');
}
};