fix teacher and parent routes

This commit is contained in:
root
2026-04-24 02:12:01 -04:00
parent 5128c74892
commit 7216cb2885
36 changed files with 1575 additions and 49 deletions
@@ -100,6 +100,61 @@ class StudentController extends BaseApiController
]);
}
public function scoreCardSelectable(Request $request): JsonResponse
{
$data = array_merge($request->query->all(), $request->all(), $request->json()->all());
$validator = Validator::make($data, [
'q' => ['nullable', 'string', 'max:255'],
'limit' => ['nullable', 'integer', 'min:1', 'max:1000'],
]);
if ($validator->fails()) {
return response()->json([
'message' => 'Validation failed.',
'errors' => $validator->errors(),
], 422);
}
$payload = $validator->validated();
$query = trim((string) ($payload['q'] ?? ''));
$limit = (int) ($payload['limit'] ?? ($query !== '' ? 50 : 1000));
$studentsQuery = Student::query()
->select('id', 'school_id', 'firstname', 'lastname', 'is_active')
->where('is_active', 1);
if ($query !== '') {
$studentsQuery->where(function ($builder) use ($query) {
$builder->where('firstname', 'like', '%' . $query . '%')
->orWhere('lastname', 'like', '%' . $query . '%')
->orWhere('school_id', 'like', '%' . $query . '%');
});
}
$students = $studentsQuery
->orderBy('lastname')
->orderBy('firstname')
->limit($limit)
->get()
->map(fn (Student $student) => [
'id' => (int) $student->id,
'student_id' => (int) $student->id,
'school_id' => (string) ($student->school_id ?? ''),
'firstname' => (string) ($student->firstname ?? ''),
'lastname' => (string) ($student->lastname ?? ''),
'name' => trim(((string) ($student->firstname ?? '')) . ' ' . ((string) ($student->lastname ?? ''))),
'is_active' => (int) ($student->is_active ?? 0),
])
->values()
->all();
return response()->json([
'ok' => true,
'students' => $students,
'selectable' => $students,
]);
}
public function show(int $studentId): JsonResponse
{
$student = Student::query()->find($studentId);