From e20cb2d478efe808fe48a51c3a5d5a28fc3a7b8c Mon Sep 17 00:00:00 2001 From: Novy San87 Date: Fri, 7 Aug 2026 10:43:27 +0700 Subject: [PATCH] feat(parent): kirim rejection_reason ke app wali + izinkan tautkan ulang setelah ditolak (link rejected dibuka lagi jadi pending/active) --- .../Controllers/Api/ParentAuthController.php | 1 + .../Api/ParentStudentController.php | 32 +++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/Api/ParentAuthController.php b/app/Http/Controllers/Api/ParentAuthController.php index 0149394..ea688ed 100644 --- a/app/Http/Controllers/Api/ParentAuthController.php +++ b/app/Http/Controllers/Api/ParentAuthController.php @@ -212,6 +212,7 @@ class ParentAuthController extends Controller 'link_id' => $link->id, 'link_status' => $link->status, 'relation' => $link->relation, + 'rejection_reason' => $link->rejection_reason, 'student' => [ 'id' => $student->id, 'nisn' => $student->nisn, diff --git a/app/Http/Controllers/Api/ParentStudentController.php b/app/Http/Controllers/Api/ParentStudentController.php index fc47b65..03b3bcd 100644 --- a/app/Http/Controllers/Api/ParentStudentController.php +++ b/app/Http/Controllers/Api/ParentStudentController.php @@ -518,11 +518,11 @@ class ParentStudentController extends Controller ], 422); } - $exists = ParentStudent::where('user_id', $user->id) + $existing = ParentStudent::where('user_id', $user->id) ->where('student_id', $student->id) - ->exists(); + ->first(); - if ($exists) { + if ($existing && $existing->status !== 'rejected') { return response()->json([ 'message' => 'Siswa ini sudah tertaut ke akun Anda.', 'errors' => ['nisn' => ['Sudah tertaut.']], @@ -536,13 +536,25 @@ class ParentStudentController extends Controller $user->update(['phone' => trim($validated['parent_phone'])]); } - $link = ParentStudent::create([ - 'user_id' => $user->id, - 'student_id' => $student->id, - 'relation' => $validated['relation'] ?? null, - 'status' => $autoVerified ? 'active' : 'pending', - 'verified_at' => $autoVerified ? now() : null, - ]); + if ($existing) { + // Tautan sebelumnya ditolak → wali memperbaiki data → dibuka lagi. + $existing->update([ + 'relation' => $validated['relation'] ?? $existing->relation, + 'status' => $autoVerified ? 'active' : 'pending', + 'rejection_reason' => null, + 'verified_at' => $autoVerified ? now() : null, + 'verified_by' => $autoVerified ? $user->id : null, + ]); + $link = $existing; + } else { + $link = ParentStudent::create([ + 'user_id' => $user->id, + 'student_id' => $student->id, + 'relation' => $validated['relation'] ?? null, + 'status' => $autoVerified ? 'active' : 'pending', + 'verified_at' => $autoVerified ? now() : null, + ]); + } return response()->json([ 'message' => $autoVerified