feat: Add verification review migration, display details in partner resource, and introduce a latest review relationship.
This commit is contained in:
parent
f0609bf077
commit
7766c9c9ac
@ -2,9 +2,13 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Enums\DecisionAdmin;
|
||||||
use App\Enums\MediaClassification;
|
use App\Enums\MediaClassification;
|
||||||
use App\Enums\MediaType;
|
use App\Enums\MediaType;
|
||||||
|
use App\Enums\RoleEnum;
|
||||||
use App\Enums\VerificationStatus;
|
use App\Enums\VerificationStatus;
|
||||||
|
use App\Models\User;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
@ -43,15 +47,13 @@ public function handle()
|
|||||||
|
|
||||||
$this->withProgressBar($legacyCompanies, function ($legacy) use ($legacyConn) {
|
$this->withProgressBar($legacyCompanies, function ($legacy) use ($legacyConn) {
|
||||||
// Find user in NEW database. Legcy enhancer is the user_id.
|
// Find user in NEW database. Legcy enhancer is the user_id.
|
||||||
$user = DB::table('users')->where('id', $legacy->enhancer)->first();
|
$newUser = DB::table('users')->where('id', $legacy->enhancer)->first();
|
||||||
|
$legacyUser = $legacyConn->table('users')->where('id', $legacy->enhancer)->first();
|
||||||
|
|
||||||
// If not found by ID, try by email (sometimes IDs change during user migration if not careful)
|
// If not found by ID, try by email (sometimes IDs change during user migration if not careful)
|
||||||
if (! $user) {
|
if (! $newUser) {
|
||||||
$user = DB::table('users')->where('email', $legacy->email)->first();
|
$newUser = DB::table('users')->where('email', $legacy->email)->first();
|
||||||
}
|
|
||||||
|
|
||||||
if (! $user) {
|
|
||||||
// If user still not found, we skip this company for now as it's orphaned
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +61,7 @@ public function handle()
|
|||||||
DB::table('companies')->updateOrInsert(
|
DB::table('companies')->updateOrInsert(
|
||||||
['id' => $legacy->id],
|
['id' => $legacy->id],
|
||||||
[
|
[
|
||||||
'user_id' => $user->id,
|
'user_id' => $newUser->id,
|
||||||
'name' => $legacy->name,
|
'name' => $legacy->name,
|
||||||
'email' => $legacy->email,
|
'email' => $legacy->email,
|
||||||
'phone_number' => $legacy->phone_number,
|
'phone_number' => $legacy->phone_number,
|
||||||
@ -80,18 +82,34 @@ public function handle()
|
|||||||
);
|
);
|
||||||
|
|
||||||
// 2. Migrate Verification Request
|
// 2. Migrate Verification Request
|
||||||
$status = $this->mapVerificationStatus($legacy->status_edit);
|
$status = $this->mapVerificationStatus($legacyUser->status);
|
||||||
DB::table('verification_requests')->updateOrInsert(
|
DB::table('verification_requests')->updateOrInsert(
|
||||||
['company_id' => $legacy->id],
|
['company_id' => $legacy->id],
|
||||||
[
|
[
|
||||||
'submitted_by' => $user->id,
|
'submitted_by' => $newUser->id,
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
'created_at' => $legacy->created_at ?? now(),
|
'created_at' => $legacy->created_at ?? now(),
|
||||||
'updated_at' => $legacy->updated_at ?? now(),
|
'updated_at' => $legacy->updated_at ?? now(),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
// 3. Migrate Partner Media (from legacy 'media' table matching company ID)
|
// 3. Migrate Verification Review
|
||||||
|
$decision = $this->mapDecision($legacyUser->status);
|
||||||
|
$verificationRequest = DB::table('verification_requests')->where('company_id', $legacy->id)->first();
|
||||||
|
if ($decision !== DecisionAdmin::NEED_REVISION->value) {
|
||||||
|
DB::table('verification_reviews')->updateOrInsert(
|
||||||
|
['verification_request_id' => $verificationRequest->id],
|
||||||
|
[
|
||||||
|
'reviewer_id' => User::role(RoleEnum::ADMINISTRATOR)->first()->id,
|
||||||
|
'decision' => $decision,
|
||||||
|
'note' => $legacy->reject_message,
|
||||||
|
'created_at' => Carbon::parse($legacy->validation_date)->setTime(23, 0, 0),
|
||||||
|
'updated_at' => $legacy->updated_at ?? now(),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Migrate Partner Media (from legacy 'media' table matching company ID)
|
||||||
$legacyMediaList = $legacyConn->table('media')->where('company', $legacy->id)->get();
|
$legacyMediaList = $legacyConn->table('media')->where('company', $legacy->id)->get();
|
||||||
foreach ($legacyMediaList as $legacyMedia) {
|
foreach ($legacyMediaList as $legacyMedia) {
|
||||||
DB::table('partner_media')->updateOrInsert(
|
DB::table('partner_media')->updateOrInsert(
|
||||||
@ -120,12 +138,22 @@ public function handle()
|
|||||||
private function mapVerificationStatus($legacyStatus): int
|
private function mapVerificationStatus($legacyStatus): int
|
||||||
{
|
{
|
||||||
return match ((string) $legacyStatus) {
|
return match ((string) $legacyStatus) {
|
||||||
'1', '3' => VerificationStatus::APPROVED->value,
|
'0' => VerificationStatus::PENDING->value,
|
||||||
|
'1' => VerificationStatus::APPROVED->value,
|
||||||
'2' => VerificationStatus::REJECTED->value,
|
'2' => VerificationStatus::REJECTED->value,
|
||||||
default => VerificationStatus::PENDING->value,
|
default => VerificationStatus::PENDING->value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function mapDecision($legacyStatus): int
|
||||||
|
{
|
||||||
|
return match ((string) $legacyStatus) {
|
||||||
|
'1' => DecisionAdmin::APPROVED->value,
|
||||||
|
'2' => DecisionAdmin::REJECTED->value,
|
||||||
|
default => DecisionAdmin::NEED_REVISION->value,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private function mapMediaType($legacyType): int
|
private function mapMediaType($legacyType): int
|
||||||
{
|
{
|
||||||
return match (strtolower($legacyType ?? '')) {
|
return match (strtolower($legacyType ?? '')) {
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\Manage\Partners;
|
namespace App\Filament\Resources\Manage\Partners;
|
||||||
|
|
||||||
|
use App\Enums\DecisionAdmin;
|
||||||
use App\Enums\MediaClassification;
|
use App\Enums\MediaClassification;
|
||||||
use App\Enums\MediaType;
|
use App\Enums\MediaType;
|
||||||
use App\Enums\RoleEnum;
|
use App\Enums\RoleEnum;
|
||||||
@ -93,13 +94,22 @@ public static function infolist(Schema $schema): Schema
|
|||||||
TextEntry::make('company.director_name')
|
TextEntry::make('company.director_name')
|
||||||
->label('Nama Direktur'),
|
->label('Nama Direktur'),
|
||||||
|
|
||||||
TextEntry::make('company.validated_at')
|
TextEntry::make('company.verificationRequest.created_at')
|
||||||
->label('Tanggal Validasi')
|
->label('Tanggal Pengajuan Verifikasi')
|
||||||
->dateTime('d F Y H:i'),
|
->dateTime('d F Y H:i'),
|
||||||
|
|
||||||
TextEntry::make('company.rejection_reason')
|
TextEntry::make('company.verificationRequest.latestReview.decision')
|
||||||
|
->label('Status Verifikasi')
|
||||||
|
->badge(),
|
||||||
|
|
||||||
|
TextEntry::make('company.verificationRequest.latestReview.created_at')
|
||||||
|
->label('Tanggal Verifikasi')
|
||||||
|
->dateTime('d F Y H:i')
|
||||||
|
->visible(fn (User $record): ?string => $record->company?->verificationRequest?->latestReview),
|
||||||
|
|
||||||
|
TextEntry::make('company.verificationRequest.latestReview.note')
|
||||||
->label('Alasan Penolakan')
|
->label('Alasan Penolakan')
|
||||||
->visible(fn (User $record): ?string => $record->company?->rejection_reason),
|
->visible(fn (User $record): ?string => $record->company?->verificationRequest?->latestReview?->decision === DecisionAdmin::REJECTED),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
Grid::make(3)
|
Grid::make(3)
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Swindon\FilamentHashids\Traits\HasHashid;
|
use Swindon\FilamentHashids\Traits\HasHashid;
|
||||||
|
|
||||||
@ -64,4 +65,9 @@ public function reviews(): HasMany
|
|||||||
{
|
{
|
||||||
return $this->hasMany(VerificationReview::class);
|
return $this->hasMany(VerificationReview::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function latestReview(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(VerificationReview::class)->latestOfMany();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user