Skip to content

Commit

Permalink
Fixed import
Browse files Browse the repository at this point in the history
  • Loading branch information
korridor committed May 21, 2024
1 parent 5a8dc60 commit 05e865e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
3 changes: 3 additions & 0 deletions app/Service/Import/Importers/ClockifyTimeEntriesImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Service\Import\Importers;

use App\Enums\Role;
use App\Models\TimeEntry;
use Exception;
use Illuminate\Support\Carbon;
Expand Down Expand Up @@ -59,6 +60,8 @@ public function importData(string $data): void
$memberId = $this->memberImportHelper->getKey([
'user_id' => $userId,
'organization_id' => $this->organization->getKey(),
], [
'role' => Role::Placeholder->value,
]);
$clientId = null;
if ($record['Client'] !== '') {
Expand Down
15 changes: 8 additions & 7 deletions app/Service/Import/Importers/DefaultImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace App\Service\Import\Importers;

use App\Enums\Role;
use App\Models\Client;
use App\Models\Member;
use App\Models\Organization;
Expand Down Expand Up @@ -69,11 +68,7 @@ public function init(Organization $organization): void
$this->userImportHelper = new ImportDatabaseHelper(User::class, ['email'], true, function (Builder $builder) {
/** @var Builder<User> $builder */
return $builder->belongsToOrganization($this->organization);
}, function (User $user) {
$user->organizations()->attach($this->organization, [
'role' => Role::Placeholder->value,
]);
}, validate: [
}, null, validate: [
'name' => [
'required',
'max:255',
Expand All @@ -86,7 +81,13 @@ public function init(Organization $organization): void
$this->memberImportHelper = new ImportDatabaseHelper(Member::class, ['user_id', 'organization_id'], true, function (Builder $builder) {
/** @var Builder<Member> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
});
}, null, validate: [
'role' => [
'required',
'string',
'in:placeholder',
],
]);
$this->projectImportHelper = new ImportDatabaseHelper(Project::class, ['name', 'organization_id'], true, function (Builder $builder) {
/** @var Builder<Project> $builder */
return $builder->where('organization_id', $this->organization->id);
Expand Down
7 changes: 5 additions & 2 deletions app/Service/Import/Importers/TogglDataImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Service\Import\Importers;

use App\Enums\Role;
use Exception;
use Spatie\TemporaryDirectory\TemporaryDirectory;
use ValueError;
Expand Down Expand Up @@ -93,10 +94,12 @@ public function importData(string $data): void
'timezone' => $workspaceUser->timezone ?? 'UTC',
'is_placeholder' => true,
], (string) $workspaceUser->uid);
$memberId = $this->memberImportHelper->getKey([
$this->memberImportHelper->getKey([
'user_id' => $userId,
'organization_id' => $this->organization->getKey(),
], [], $userId);
], [
'role' => Role::Placeholder->value,
], $userId);
}

foreach ($projects as $project) {
Expand Down
3 changes: 3 additions & 0 deletions app/Service/Import/Importers/TogglTimeEntriesImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Service\Import\Importers;

use App\Enums\Role;
use App\Models\TimeEntry;
use Exception;
use Illuminate\Support\Carbon;
Expand Down Expand Up @@ -59,6 +60,8 @@ public function importData(string $data): void
$memberId = $this->memberImportHelper->getKey([
'user_id' => $userId,
'organization_id' => $this->organization->getKey(),
], [
'role' => Role::Placeholder->value,
]);
$clientId = null;
if ($record['Client'] !== '') {
Expand Down
7 changes: 7 additions & 0 deletions tests/Unit/Service/Import/Importer/ImporterTestAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Tests\Unit\Service\Import\Importer;

use App\Enums\Role;
use App\Models\Client;
use App\Models\Member;
use App\Models\Project;
use App\Models\Tag;
use App\Models\Task;
Expand All @@ -28,6 +30,11 @@ protected function checkTestScenarioAfterImportExcludingTimeEntries(bool $detail
$this->assertSame(null, $user1->password);
$this->assertSame('Peter Tester', $user1->name);
$this->assertSame('[email protected]', $user1->email);
$members = Member::all();
$this->assertCount(1, $members);
$member1 = $members->firstWhere('user_id', $user1->getKey());
$this->assertNotNull($member1);
$this->assertSame(Role::Placeholder->value, $member1->role);
$clients = Client::all();
$this->assertCount(1, $clients);
$client1 = $clients->firstWhere('name', 'Big Company');
Expand Down

0 comments on commit 05e865e

Please sign in to comment.