refactor: remove unused Carbon imports from Attendance and Employee models; update ProfileService to use UserProfile directly; clean up imports in various service files for improved clarity
This commit is contained in:
parent
ba3f7ef9f9
commit
a3ff10d6e1
@ -5,7 +5,6 @@
|
||||
use App\Models\Concerns\HasModuleMedia;
|
||||
use App\Models\Concerns\InteractsWithActivityLog;
|
||||
use App\Support\Media\MediaPresenter;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Attributes\Appends;
|
||||
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
|
||||
use App\Enums\EmploymentStatus;
|
||||
use App\Models\Concerns\InteractsWithActivityLog;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Attributes\Appends;
|
||||
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
namespace App\Services\Account;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\UserProfile;
|
||||
use App\Services\Concerns\RunsInTransaction;
|
||||
use App\Services\Concerns\SyncsPhotos;
|
||||
use App\Services\Media\MediaService;
|
||||
@ -25,7 +26,7 @@ function () use ($user, $validated): void {
|
||||
'username' => $validated['username'],
|
||||
]);
|
||||
|
||||
/** @var \App\Models\UserProfile $profile */
|
||||
/** @var UserProfile $profile */
|
||||
$profile = $user->profile()->updateOrCreate(
|
||||
['user_id' => $user->id],
|
||||
[
|
||||
|
||||
@ -14,8 +14,6 @@
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class EmployeeService
|
||||
{
|
||||
|
||||
@ -22,7 +22,6 @@
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class CuttingService
|
||||
|
||||
@ -23,7 +23,6 @@
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class OrderService
|
||||
|
||||
@ -19,7 +19,6 @@
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class PurchaseService
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
use App\Services\Concerns\SyncsPhotos;
|
||||
use App\Services\Media\MediaService;
|
||||
use App\Support\Media\MediaPresenter;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
|
||||
class HomepageSettingService
|
||||
{
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
use App\Services\Media\MediaService;
|
||||
use App\Settings\SystemSettings;
|
||||
use App\Support\Media\MediaPresenter;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class SystemService
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
|
||||
use App\Models\Cutting;
|
||||
use App\Models\CuttingMaterialCombination;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
use App\Models\UserProfile;
|
||||
use Database\Seeders\RolePermissionSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
@ -176,7 +177,7 @@ function validProfilePayload(): array
|
||||
$user = createUserWithProfile();
|
||||
|
||||
$disk = config('filesystems.default') === 's3' ? 's3' : config('filesystems.default', 'public');
|
||||
$imageContent = \Illuminate\Http\UploadedFile::fake()->image('avatar.jpg')->get();
|
||||
$imageContent = UploadedFile::fake()->image('avatar.jpg')->get();
|
||||
Storage::disk($disk)->put('fake-s3-key.jpg', $imageContent);
|
||||
|
||||
$payload = validProfilePayload();
|
||||
@ -192,14 +193,14 @@ function validProfilePayload(): array
|
||||
test('updating profile can upload new photo and delete existing photo', function () {
|
||||
$user = createUserWithProfile();
|
||||
|
||||
$imageContent = \Illuminate\Http\UploadedFile::fake()->image('initial.jpg')->get();
|
||||
$imageContent = UploadedFile::fake()->image('initial.jpg')->get();
|
||||
Storage::disk('public')->put('initial.jpg', $imageContent);
|
||||
$user->profile->addMediaFromDisk('initial.jpg', 'public')->toMediaCollection('profile_photo');
|
||||
expect($user->profile->fresh()->getMedia('profile_photo')->count())->toBe(1);
|
||||
$mediaId = $user->profile->fresh()->getFirstMedia('profile_photo')->id;
|
||||
|
||||
$disk = config('filesystems.default') === 's3' ? 's3' : config('filesystems.default', 'public');
|
||||
$imageContent2 = \Illuminate\Http\UploadedFile::fake()->image('updated.jpg')->get();
|
||||
$imageContent2 = UploadedFile::fake()->image('updated.jpg')->get();
|
||||
Storage::disk($disk)->put('updated.jpg', $imageContent2);
|
||||
|
||||
$payload = validProfilePayload();
|
||||
@ -217,7 +218,7 @@ function validProfilePayload(): array
|
||||
test('removing profile photo without uploading new one results in no photo', function () {
|
||||
$user = createUserWithProfile();
|
||||
|
||||
$imageContent = \Illuminate\Http\UploadedFile::fake()->image('initial.jpg')->get();
|
||||
$imageContent = UploadedFile::fake()->image('initial.jpg')->get();
|
||||
Storage::disk('public')->put('initial.jpg', $imageContent);
|
||||
$user->profile->addMediaFromDisk('initial.jpg', 'public')->toMediaCollection('profile_photo');
|
||||
$mediaId = $user->profile->fresh()->getFirstMedia('profile_photo')->id;
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
use App\Models\UserProfile;
|
||||
use Database\Seeders\RolePermissionSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
@ -356,7 +357,7 @@ function validEmployeePayload(): array
|
||||
$user = createEmployeeUserWithPermission(PermissionEnum::EMPLOYEES_VIEW, PermissionEnum::EMPLOYEES_CREATE);
|
||||
|
||||
$disk = config('filesystems.default') === 's3' ? 's3' : config('filesystems.default', 'public');
|
||||
$imageContent = \Illuminate\Http\UploadedFile::fake()->image('avatar.jpg')->get();
|
||||
$imageContent = UploadedFile::fake()->image('avatar.jpg')->get();
|
||||
Storage::disk($disk)->put('fake-s3-key.jpg', $imageContent);
|
||||
|
||||
$payload = validEmployeePayload();
|
||||
@ -458,14 +459,14 @@ function validEmployeePayload(): array
|
||||
|
||||
$employee = createEmployeeWithProfile();
|
||||
|
||||
$imageContent = \Illuminate\Http\UploadedFile::fake()->image('initial.jpg')->get();
|
||||
$imageContent = UploadedFile::fake()->image('initial.jpg')->get();
|
||||
Storage::disk('public')->put('initial.jpg', $imageContent);
|
||||
$employee->profile->addMediaFromDisk('initial.jpg', 'public')->toMediaCollection('profile_photo');
|
||||
expect($employee->profile->fresh()->getMedia('profile_photo')->count())->toBe(1);
|
||||
$mediaId = $employee->profile->fresh()->getFirstMedia('profile_photo')->id;
|
||||
|
||||
$disk = config('filesystems.default') === 's3' ? 's3' : config('filesystems.default', 'public');
|
||||
$imageContent2 = \Illuminate\Http\UploadedFile::fake()->image('updated.jpg')->get();
|
||||
$imageContent2 = UploadedFile::fake()->image('updated.jpg')->get();
|
||||
Storage::disk($disk)->put('updated.jpg', $imageContent2);
|
||||
$payload = validEmployeePayload();
|
||||
$payload['email'] = $employee->email;
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
use App\Models\Category;
|
||||
use App\Models\OwnerVerificationRequest;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductPrice;
|
||||
use App\Models\ProductVariant;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\RolePermissionSeeder;
|
||||
@ -74,7 +75,7 @@ function createProductVerifierUser(): User
|
||||
function variantWithImage(string $name = 'All Size', int $stock = 10): array
|
||||
{
|
||||
$disk = config('filesystems.default') === 's3' ? 's3' : config('filesystems.default', 'public');
|
||||
$key = 'products/'.Str::uuid().".jpg";
|
||||
$key = 'products/'.Str::uuid().'.jpg';
|
||||
$imageContent = UploadedFile::fake()->image("{$name}.jpg", 100, 100)->get();
|
||||
Storage::disk($disk)->put($key, $imageContent);
|
||||
|
||||
@ -920,7 +921,7 @@ function variantUpdateData(int $id, string $name = 'Updated Variant', int $stock
|
||||
$product = Product::factory()->create();
|
||||
$variant = ProductVariant::factory()->create(['product_id' => $product->id]);
|
||||
|
||||
\App\Models\ProductPrice::factory()->count(3)->create(['variant_id' => $variant->id]);
|
||||
ProductPrice::factory()->count(3)->create(['variant_id' => $variant->id]);
|
||||
|
||||
expect($variant->fresh()->prices)->toHaveCount(3);
|
||||
});
|
||||
@ -936,7 +937,7 @@ function variantUpdateData(int $id, string $name = 'Updated Variant', int $stock
|
||||
test('price has price cast to integer', function () {
|
||||
$product = Product::factory()->create();
|
||||
$variant = ProductVariant::factory()->create(['product_id' => $product->id]);
|
||||
$price = \App\Models\ProductPrice::factory()->create(['variant_id' => $variant->id, 'price' => 150000]);
|
||||
$price = ProductPrice::factory()->create(['variant_id' => $variant->id, 'price' => 150000]);
|
||||
|
||||
expect($price->price)->toBeInt();
|
||||
expect($price->price)->toBe(150000);
|
||||
@ -945,7 +946,7 @@ function variantUpdateData(int $id, string $name = 'Updated Variant', int $stock
|
||||
test('price has formatted price accessor', function () {
|
||||
$product = Product::factory()->create();
|
||||
$variant = ProductVariant::factory()->create(['product_id' => $product->id]);
|
||||
$price = \App\Models\ProductPrice::factory()->create(['variant_id' => $variant->id, 'price' => 1500000]);
|
||||
$price = ProductPrice::factory()->create(['variant_id' => $variant->id, 'price' => 1500000]);
|
||||
|
||||
expect($price->price_formatted)->toBe('Rp 1.500.000');
|
||||
});
|
||||
@ -953,7 +954,7 @@ function variantUpdateData(int $id, string $name = 'Updated Variant', int $stock
|
||||
test('price has price_input accessor', function () {
|
||||
$product = Product::factory()->create();
|
||||
$variant = ProductVariant::factory()->create(['product_id' => $product->id]);
|
||||
$price = \App\Models\ProductPrice::factory()->create(['variant_id' => $variant->id, 'price' => 200000]);
|
||||
$price = ProductPrice::factory()->create(['variant_id' => $variant->id, 'price' => 200000]);
|
||||
|
||||
expect($price->price_input)->toBe('200000');
|
||||
});
|
||||
@ -961,7 +962,7 @@ function variantUpdateData(int $id, string $name = 'Updated Variant', int $stock
|
||||
test('price belongs to variant', function () {
|
||||
$product = Product::factory()->create();
|
||||
$variant = ProductVariant::factory()->create(['product_id' => $product->id]);
|
||||
$price = \App\Models\ProductPrice::factory()->create(['variant_id' => $variant->id]);
|
||||
$price = ProductPrice::factory()->create(['variant_id' => $variant->id]);
|
||||
|
||||
expect($price->variant)->not->toBeNull();
|
||||
expect($price->variant->id)->toBe($variant->id);
|
||||
|
||||
@ -56,7 +56,7 @@ function createRawMaterialWithPrices(): RawMaterial
|
||||
function priceWithImage(string $variant = 'Default', int $price = 50000, float $stock = 10): array
|
||||
{
|
||||
$disk = config('filesystems.default') === 's3' ? 's3' : config('filesystems.default', 'public');
|
||||
$key = 'raw-materials/'.Str::uuid().".jpg";
|
||||
$key = 'raw-materials/'.Str::uuid().'.jpg';
|
||||
$imageContent = UploadedFile::fake()->image("{$variant}.jpg", 100, 100)->get();
|
||||
Storage::disk($disk)->put($key, $imageContent);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user