feat(api): sync students kini mengirim photo_url dari dokumen PAS FOTO

This commit is contained in:
novysan87
2026-08-07 08:27:44 +07:00
parent f772b5b354
commit 6614e8dfba
@@ -28,6 +28,7 @@ class StudentSyncController extends Controller
'department:id,code,name,description,is_active',
'classRoom:id,academic_year_id,department_id,name,level,is_active',
'parents:id,student_id,relation_type,name,nik,phone_number,is_alive',
'documents.documentType',
])
->orderBy('full_name')
->get([
@@ -53,6 +54,19 @@ class StudentSyncController extends Controller
'updated_at',
])
->map(function (Student $student) {
$photoDocument = $student->documents
->filter(function ($document) {
$code = strtoupper((string) ($document->documentType?->code ?? ''));
$name = strtolower((string) ($document->documentType?->name ?? ''));
return $code === 'PAS_FOTO'
|| $code === 'PAS FOTO'
|| str_contains($name, 'pas foto')
|| str_contains($name, 'pasfoto');
})
->sortByDesc('created_at')
->first();
return [
'id' => $student->id,
'student_number' => $student->student_number,
@@ -99,6 +113,7 @@ class StudentSyncController extends Controller
'phone_number' => $student->phone_number,
'email' => $student->email,
'photo_path' => $student->photo_path,
'photo_url' => $photoDocument?->file_path ? asset('storage/' . $photoDocument->file_path) : null,
'notes' => $student->notes,
'parents' => $student->parents
->where('is_alive', true)