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:
@@ -212,6 +212,7 @@ class ParentAuthController extends Controller
|
|||||||
'link_id' => $link->id,
|
'link_id' => $link->id,
|
||||||
'link_status' => $link->status,
|
'link_status' => $link->status,
|
||||||
'relation' => $link->relation,
|
'relation' => $link->relation,
|
||||||
|
'rejection_reason' => $link->rejection_reason,
|
||||||
'student' => [
|
'student' => [
|
||||||
'id' => $student->id,
|
'id' => $student->id,
|
||||||
'nisn' => $student->nisn,
|
'nisn' => $student->nisn,
|
||||||
|
|||||||
@@ -518,11 +518,11 @@ class ParentStudentController extends Controller
|
|||||||
], 422);
|
], 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
$exists = ParentStudent::where('user_id', $user->id)
|
$existing = ParentStudent::where('user_id', $user->id)
|
||||||
->where('student_id', $student->id)
|
->where('student_id', $student->id)
|
||||||
->exists();
|
->first();
|
||||||
|
|
||||||
if ($exists) {
|
if ($existing && $existing->status !== 'rejected') {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'Siswa ini sudah tertaut ke akun Anda.',
|
'message' => 'Siswa ini sudah tertaut ke akun Anda.',
|
||||||
'errors' => ['nisn' => ['Sudah tertaut.']],
|
'errors' => ['nisn' => ['Sudah tertaut.']],
|
||||||
@@ -536,6 +536,17 @@ class ParentStudentController extends Controller
|
|||||||
$user->update(['phone' => trim($validated['parent_phone'])]);
|
$user->update(['phone' => trim($validated['parent_phone'])]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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([
|
$link = ParentStudent::create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'student_id' => $student->id,
|
'student_id' => $student->id,
|
||||||
@@ -543,6 +554,7 @@ class ParentStudentController extends Controller
|
|||||||
'status' => $autoVerified ? 'active' : 'pending',
|
'status' => $autoVerified ? 'active' : 'pending',
|
||||||
'verified_at' => $autoVerified ? now() : null,
|
'verified_at' => $autoVerified ? now() : null,
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => $autoVerified
|
'message' => $autoVerified
|
||||||
|
|||||||
Reference in New Issue
Block a user