Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
refactor: clean up unnecessary table fields
Browse files Browse the repository at this point in the history
Signed-off-by: Fery Wardiyanto <[email protected]>
  • Loading branch information
feryardiant committed Mar 27, 2024
1 parent a7fc82a commit 46bbb5e
Show file tree
Hide file tree
Showing 23 changed files with 88 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public function up(): void
$table->string('alias', 50)->nullable();
$table->string('email')->unique()->nullable();
$table->string('phone', 20)->nullable();
$table->unsignedSmallInteger('tax_status')->nullable();
$table->string('tax_id', 16)->nullable();
$table->string('summary', 200)->nullable();

$table->timestamps();
Expand Down Expand Up @@ -54,10 +52,6 @@ public function up(): void
$table->date('birth_date')->nullable();
$table->char('birth_place_code', 4)->nullable();
$table->char('gender', 1);
$table->string('education', 3)->nullable();
$table->unsignedTinyInteger('religion')->nullable();
$table->unsignedSmallInteger('tax_status')->nullable();
$table->string('tax_id', 16)->nullable();
$table->string('summary', 200)->nullable();

$table->timestamps();
Expand Down
9 changes: 1 addition & 8 deletions src/Database/Factories/PersonnelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

use Creasi\Base\Database\Models\Business;
use Creasi\Base\Database\Models\Personnel;
use Creasi\Base\Enums\Education;
use Creasi\Base\Enums\EmploymentStatus;
use Creasi\Base\Enums\Gender;
use Creasi\Base\Enums\Religion;
use Creasi\Base\Enums\StakeholderStatus;
use Creasi\Base\Enums\StakeholderType;
use Creasi\Base\Enums\TaxStatus;
use Creasi\Nusa\Models\Regency;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Builder;
Expand Down Expand Up @@ -45,13 +42,9 @@ public function definition(): array
'email' => $this->faker->safeEmail(),
'phone' => '08'.$this->faker->numerify('##########'),
'gender' => $gender,
'nik' => $nik = $this->faker->nik(null, $birthDate = $this->faker->dateTime()),
'nik' => $this->faker->nik($gender->toFaker(), $birthDate = $this->faker->dateTime()),
'birth_date' => $birthDate->format('Y-m-d'),
'birth_place_code' => $birthPlace->code,
'education' => $this->faker->randomElement(Education::cases()),
'religion' => $this->faker->randomElement(Religion::cases()),
'tax_status' => $this->faker->randomElement(TaxStatus::cases()),
'tax_id' => $nik,
'summary' => $this->faker->sentence(4),
];
}
Expand Down
5 changes: 1 addition & 4 deletions src/Database/Models/Business.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
namespace Creasi\Base\Database\Models;

use Creasi\Base\Database\Models\Concerns\AsCompany;
use Creasi\Base\Database\Models\Concerns\WithTaxInfo;
use Creasi\Base\Database\Models\Contracts\Company;
use Creasi\Base\Database\Models\Contracts\HasTaxInfo;

/**
* @property-read BusinessRelative $stakeholder
*
* @method static \Creasi\Base\Database\Factories\BusinessFactory<Business> factory()
*/
class Business extends Entity implements Company, HasTaxInfo
class Business extends Entity implements Company
{
use AsCompany;
use WithTaxInfo;

protected $fillable = [];

Expand Down
2 changes: 2 additions & 0 deletions src/Database/Models/Concerns/AsEmployee.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Illuminate\Database\Eloquent\Relations\MorphToMany;

/**
* @property-read \Illuminate\Database\Eloquent\Collection<int, Company> $primaryEmployer
*
* @mixin \Creasi\Base\Database\Models\Contracts\Employee
*/
trait AsEmployee
Expand Down
1 change: 1 addition & 0 deletions src/Database/Models/Concerns/WithAvatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* @property-read null|\Creasi\Base\Database\Models\FileUpload $avatar
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Creasi\Base\Database\Models\FileUpload> $avatarFile
*
* @mixin \Creasi\Base\Database\Models\Contracts\HasFileUploads
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Models/Contracts/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* @property-read \Illuminate\Database\Eloquent\Collection<int, Employee> $employees
* @property-read \Illuminate\Database\Eloquent\Collection<int, Personnel> $individualRelatives
* @property-read \Illuminate\Database\Eloquent\Collection<int, static> $companyRelatives
* @property-read \Illuminate\Database\Eloquent\Collection<int, Company> $companyRelatives
* @property-read \Illuminate\Database\Eloquent\Collection<int, BusinessRelative> $stakeholders
*/
interface Company extends Stakeholder
Expand Down
15 changes: 2 additions & 13 deletions src/Database/Models/Personnel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@

use Creasi\Base\Database\Models\Concerns\AsEmployee;
use Creasi\Base\Database\Models\Concerns\WithCredential;
use Creasi\Base\Database\Models\Concerns\WithTaxInfo;
use Creasi\Base\Database\Models\Contracts\Employee;
use Creasi\Base\Database\Models\Contracts\HasCredential;
use Creasi\Base\Database\Models\Contracts\HasTaxInfo;
use Creasi\Base\Enums\Education;
use Creasi\Base\Enums\Gender;
use Creasi\Base\Enums\PersonnelRelativeStatus;
use Creasi\Base\Enums\Religion;
use Creasi\Nusa\Models\Concerns\WithRegency;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

Expand All @@ -21,8 +17,6 @@
* @property null|string $suffix
* @property null|\Carbon\CarbonImmutable $birth_date
* @property null|int $birth_place_code
* @property null|Education $education
* @property null|Religion $religion
* @property null|string $summary
* @property-read null|Regency $birthPlace
* @property-read ?PersonnelRelative $relative
Expand All @@ -31,32 +25,27 @@
*
* @method static \Creasi\Base\Database\Factories\PersonnelFactory<Personnel> factory()
*/
class Personnel extends Entity implements Employee, HasCredential, HasTaxInfo
class Personnel extends Entity implements Employee, HasCredential
{
use AsEmployee;
use WithCredential;
use WithRegency {
regency as birthPlace;
}
use WithTaxInfo;

protected $fillable = [
'nik',
// 'nik',
'prefix',
'suffix',
'birth_date',
'birth_place_code',
'education',
'religion',
'gender',
];

protected $casts = [
'birth_date' => 'immutable_date',
'birth_place_code' => 'int',
'education' => Education::class,
'gender' => Gender::class,
'religion' => Religion::class,
];

protected $regencyKey = 'birth_place_code';
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Requests/Auth/NewPasswordRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function fulfill()
$this->only('email', 'password', 'password_confirmation', 'token'),
function ($user) {
$user->forceFill([
'password' => $this->password,
'password' => $this->input('password'),
'remember_token' => Str::random(60),
])->save();

Expand Down
9 changes: 5 additions & 4 deletions src/Http/Requests/Company/StoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Creasi\Base\Contracts\FormRequest as FormRequestContract;
use Creasi\Base\Database\Models\Contracts\Company;
use Creasi\Base\Database\Models\Personnel;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

Expand All @@ -15,10 +16,10 @@ class StoreRequest extends FormRequest implements FormRequestContract
public function rules(): array
{
return [
'name' => ['required', 'string'],
'alias' => ['nullable', 'string', Rule::unique('businesses', 'alias')],
'email' => ['required', 'email', Rule::unique('businesses', 'email')],
'phone_number' => ['nullable', 'numeric'],
'name' => ['required', 'string', 'max:150'],
'alias' => ['nullable', 'string', 'max:50', Rule::unique(Personnel::class, 'alias')],
'email' => ['required', 'email', 'max:150', Rule::unique(Personnel::class, 'email')],
'phone' => ['nullable', 'numeric', 'max_digits:20'],
'summary' => ['nullable', 'string', 'max:200'],
];
}
Expand Down
12 changes: 8 additions & 4 deletions src/Http/Requests/Company/UpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use Creasi\Base\Contracts\FormRequest as FormRequestContract;
use Creasi\Base\Database\Models\Contracts\Company;
use Creasi\Base\Database\Models\Personnel;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateRequest extends FormRequest implements FormRequestContract
{
Expand All @@ -13,11 +15,13 @@ class UpdateRequest extends FormRequest implements FormRequestContract
*/
public function rules(): array
{
$key = $this->route('company');

return [
'name' => ['required', 'string'],
'alias' => ['nullable', 'string'],
'email' => ['required', 'email'],
'phone_number' => ['nullable', 'numeric'],
'name' => ['required', 'string', 'max:150'],
'alias' => ['nullable', 'string', 'max:50', Rule::unique(Personnel::class, 'alias')->ignore($key)],
'email' => ['required', 'email', 'max:150', Rule::unique(Personnel::class, 'email')->ignore($key)],
'phone' => ['nullable', 'numeric', 'max_digits:20'],
'summary' => ['nullable', 'string', 'max:200'],
];
}
Expand Down
9 changes: 5 additions & 4 deletions src/Http/Requests/Employee/StoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Creasi\Base\Contracts\FormRequest as FormRequestContract;
use Creasi\Base\Database\Models\Contracts\Company;
use Creasi\Base\Database\Models\Personnel;
use Creasi\Base\Enums\Gender;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
Expand All @@ -16,10 +17,10 @@ class StoreRequest extends FormRequest implements FormRequestContract
public function rules(): array
{
return [
'name' => ['required', 'string'],
'alias' => ['nullable', 'string', Rule::unique('personnels', 'alias')],
'email' => ['required', 'email', Rule::unique('personnels', 'email')],
'phone' => ['nullable', 'numeric'],
'name' => ['required', 'string', 'max:150'],
'alias' => ['nullable', 'string', 'max:50', Rule::unique(Personnel::class, 'alias')],
'email' => ['required', 'email', 'max:150', Rule::unique(Personnel::class, 'email')],
'phone' => ['nullable', 'numeric', 'max_digits:20'],
'gender' => ['required', Rule::enum(Gender::class)],
'summary' => ['nullable', 'string', 'max:200'],
];
Expand Down
12 changes: 8 additions & 4 deletions src/Http/Requests/Employee/UpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use Creasi\Base\Contracts\FormRequest as FormRequestContract;
use Creasi\Base\Database\Models\Contracts\Employee;
use Creasi\Base\Database\Models\Personnel;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateRequest extends FormRequest implements FormRequestContract
{
Expand All @@ -13,11 +15,13 @@ class UpdateRequest extends FormRequest implements FormRequestContract
*/
public function rules(): array
{
$key = $this->route('employee');

return [
'name' => ['required', 'string'],
'alias' => ['nullable', 'string'],
'email' => ['required', 'email'],
'phone' => ['nullable', 'numeric'],
'name' => ['required', 'string', 'max:150'],
'alias' => ['nullable', 'string', 'max:50', Rule::unique(Personnel::class, 'alias')->ignore($key)],
'email' => ['required', 'email', 'max:150', Rule::unique(Personnel::class, 'email')->ignore($key)],
'phone' => ['nullable', 'numeric', 'max_digits:20'],
'summary' => ['nullable', 'string', 'max:200'],
];
}
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Requests/FileUpload/StoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function fulfill(HasFileUploads $entity)
return $entity->storeFile(
$type,
$this->file('upload'),
$this->name,
$this->title,
$this->input('name'),
$this->input('title'),
);
}
}
35 changes: 12 additions & 23 deletions src/Http/Requests/ProfileRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace Creasi\Base\Http\Requests;

use Creasi\Base\Contracts\FormRequest as FormRequestContract;
use Creasi\Base\Enums\Education;
use Creasi\Base\Enums\TaxStatus;
use Creasi\Base\Database\Models\Personnel;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

Expand All @@ -15,35 +14,25 @@ class ProfileRequest extends FormRequest implements FormRequestContract
*/
public function rules(): array
{
$key = $this->user()->identity->getKey();

return [
'fullname' => ['required', 'string'],
'nickname' => ['nullable', 'string'],
'phone' => ['required', 'string'],
'name' => ['required', 'string', 'max:150'],
'alias' => ['nullable', 'string', 'max:50', Rule::unique(Personnel::class, 'alias')->ignore($key)],
'email' => ['required', 'email', 'max:150', Rule::unique(Personnel::class, 'email')->ignore($key)],
'phone' => ['nullable', 'numeric', 'max_digits:20'],
'prefix' => ['nullable', 'string', 'max:20'],
'suffix' => ['nullable', 'string', 'max:20'],
'summary' => ['nullable', 'string', 'max:200'],
'prefix' => ['nullable', 'string'],
'suffix' => ['nullable', 'string'],
'education' => ['nullable', Rule::enum(Education::class)],
'tax_status' => ['nullable', Rule::enum(TaxStatus::class)],
'tax_id' => ['nullable', 'string'],
];
}

public function fulfill()
{
/** @var \App\Models\User */
$user = $this->user();
$data = $this->validated();

$user->identity()->update([
'name' => $data['fullname'],
'alias' => $data['nickname'],
'phone' => $data['phone'],
'summary' => $data['summary'],
'prefix' => $data['prefix'],
'suffix' => $data['suffix'],
'education' => $this->enum('education', Education::class),
'tax_status' => $this->enum('tax_status', TaxStatus::class),
'tax_id' => $data['tax_id'],
]);

$user->identity()->update($this->validated());

$user->load('identity');

Expand Down
9 changes: 5 additions & 4 deletions src/Http/Requests/Stakeholder/StoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Creasi\Base\Contracts\FormRequest as FormRequestContract;
use Creasi\Base\Database\Models\Contracts\Company;
use Creasi\Base\Database\Models\Personnel;
use Creasi\Base\Enums\StakeholderType;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
Expand All @@ -16,10 +17,10 @@ class StoreRequest extends FormRequest implements FormRequestContract
public function rules(): array
{
return [
'name' => ['required', 'string'],
'alias' => ['nullable', 'string', Rule::unique('businesses', 'alias')],
'email' => ['required', 'email', Rule::unique('businesses', 'email')],
'phone_number' => ['nullable', 'numeric'],
'name' => ['required', 'string', 'max:150'],
'alias' => ['nullable', 'string', 'max:50', Rule::unique(Personnel::class, 'alias')],
'email' => ['required', 'email', 'max:150', Rule::unique(Personnel::class, 'email')],
'phone' => ['nullable', 'numeric', 'max_digits:20'],
'summary' => ['nullable', 'string', 'max:200'],
];
}
Expand Down
12 changes: 8 additions & 4 deletions src/Http/Requests/Stakeholder/UpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use Creasi\Base\Contracts\FormRequest as FormRequestContract;
use Creasi\Base\Database\Models\Contracts\Stakeholder;
use Creasi\Base\Database\Models\Personnel;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateRequest extends FormRequest implements FormRequestContract
{
Expand All @@ -13,11 +15,13 @@ class UpdateRequest extends FormRequest implements FormRequestContract
*/
public function rules(): array
{
$key = $this->route('stakeholder');

return [
'name' => ['required', 'string'],
'alias' => ['nullable', 'string'],
'email' => ['required', 'email'],
'phone_number' => ['nullable', 'numeric'],
'name' => ['required', 'string', 'max:150'],
'alias' => ['nullable', 'string', 'max:50', Rule::unique(Personnel::class, 'alias')->ignore($key)],
'email' => ['required', 'email', 'max:150', Rule::unique(Personnel::class, 'email')->ignore($key)],
'phone' => ['nullable', 'numeric', 'max_digits:20'],
'summary' => ['nullable', 'string', 'max:200'],
];
}
Expand Down
Loading

0 comments on commit 46bbb5e

Please sign in to comment.