mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 00:02:15 +01:00
Migrated endpoints from user to member; Renamed membership to member
This commit is contained in:
@@ -5,15 +5,15 @@ declare(strict_types=1);
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Models\Membership;
|
||||
use App\Models\Member;
|
||||
use App\Models\Organization;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Membership>
|
||||
* @extends Factory<Member>
|
||||
*/
|
||||
class MembershipFactory extends Factory
|
||||
class MemberFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
@@ -24,11 +24,20 @@ class MembershipFactory extends Factory
|
||||
{
|
||||
return [
|
||||
'role' => Role::Employee,
|
||||
'organization_id' => OrganizationFactory::class,
|
||||
'user_id' => UserFactory::class,
|
||||
'organization_id' => Organization::factory(),
|
||||
'user_id' => User::factory(),
|
||||
];
|
||||
}
|
||||
|
||||
public function role(Role $role): static
|
||||
{
|
||||
return $this->state(function (array $attributes) use ($role): array {
|
||||
return [
|
||||
'role' => $role->value,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function forOrganization(Organization $organization): static
|
||||
{
|
||||
return $this->state(function (array $attributes) use ($organization): array {
|
||||
@@ -5,10 +5,10 @@ declare(strict_types=1);
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Member;
|
||||
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;
|
||||
|
||||
@@ -61,12 +61,12 @@ class ProjectFactory extends Factory
|
||||
});
|
||||
}
|
||||
|
||||
public function addMember(User $user, array $attributes = []): self
|
||||
public function addMember(Member $member, array $attributes = []): self
|
||||
{
|
||||
return $this->afterCreating(function (Project $project) use ($user, $attributes): void {
|
||||
return $this->afterCreating(function (Project $project) use ($member, $attributes): void {
|
||||
ProjectMember::factory()
|
||||
->forProject($project)
|
||||
->forUser($user)
|
||||
->forMember($member)
|
||||
->create($attributes);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Member;
|
||||
use App\Models\Project;
|
||||
use App\Models\ProjectMember;
|
||||
use App\Models\User;
|
||||
@@ -25,9 +26,13 @@ class ProjectMemberFactory extends Factory
|
||||
'billable_rate' => $this->faker->numberBetween(10, 10000) * 100,
|
||||
'project_id' => Project::factory(),
|
||||
'user_id' => User::factory(),
|
||||
'member_id' => Member::factory(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use forMember instead
|
||||
*/
|
||||
public function forUser(User $user): self
|
||||
{
|
||||
return $this->state(function (array $attributes) use ($user): array {
|
||||
@@ -37,6 +42,16 @@ class ProjectMemberFactory extends Factory
|
||||
});
|
||||
}
|
||||
|
||||
public function forMember(Member $member): self
|
||||
{
|
||||
return $this->state(function (array $attributes) use ($member): array {
|
||||
return [
|
||||
'member_id' => $member->getKey(),
|
||||
'user_id' => $member->user_id, // Legacy
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function forProject(Project $project): self
|
||||
{
|
||||
return $this->state(function (array $attributes) use ($project): array {
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Member;
|
||||
use App\Models\Organization;
|
||||
use App\Models\Project;
|
||||
use App\Models\Tag;
|
||||
@@ -34,6 +35,7 @@ class TimeEntryFactory extends Factory
|
||||
'billable' => $this->faker->boolean(),
|
||||
'tags' => [],
|
||||
'user_id' => User::factory(),
|
||||
'member_id' => Member::factory(),
|
||||
'task_id' => null,
|
||||
'project_id' => null,
|
||||
'organization_id' => Organization::factory(),
|
||||
@@ -86,6 +88,9 @@ class TimeEntryFactory extends Factory
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use forMember instead
|
||||
*/
|
||||
public function forUser(User $user): self
|
||||
{
|
||||
return $this->state(function (array $attributes) use ($user) {
|
||||
@@ -95,6 +100,17 @@ class TimeEntryFactory extends Factory
|
||||
});
|
||||
}
|
||||
|
||||
public function forMember(Member $member): static
|
||||
{
|
||||
return $this->state(function (array $attributes) use ($member): array {
|
||||
return [
|
||||
'member_id' => $member->getKey(),
|
||||
'user_id' => $member->user_id,
|
||||
'organization_id' => $member->organization_id,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function forOrganization(Organization $organization): self
|
||||
{
|
||||
return $this->state(function (array $attributes) use ($organization) {
|
||||
|
||||
Reference in New Issue
Block a user