feat(parent): kirim rejection_reason ke app wali + izinkan tautkan ulang setelah ditolak (link rejected dibuka lagi jadi pending/active)

This commit is contained in:
Novy San87
2026-08-07 10:43:27 +07:00
parent 42ffd893b2
commit e20cb2d478
2 changed files with 23 additions and 10 deletions
@@ -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,
@@ -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