add tests batch 20

This commit is contained in:
root
2026-06-09 01:03:53 -04:00
parent 95efb9652e
commit 6be4875c5e
1502 changed files with 13797 additions and 11313 deletions
@@ -15,6 +15,7 @@ use App\Http\Resources\Students\StudentClassSectionResource;
use App\Http\Resources\Students\StudentRemovedResource;
use App\Http\Resources\Students\StudentScoreCardRowResource;
use App\Models\AttendanceRecord;
use App\Models\ClassSection;
use App\Models\EmergencyContact;
use App\Models\Incident;
use App\Models\SemesterScore;
@@ -81,10 +82,10 @@ class StudentController extends BaseApiController
$payload = $validator->validated();
$parentIds = [];
if (! empty($payload['parent_ids'])) {
if (!empty($payload['parent_ids'])) {
$parentIds = array_values(array_unique(array_map('intval', $payload['parent_ids'])));
}
if (! empty($payload['parent_id'])) {
if (!empty($payload['parent_id'])) {
$parentIds[] = (int) $payload['parent_id'];
}
$parentIds = array_values(array_unique(array_filter($parentIds)));
@@ -148,7 +149,7 @@ class StudentController extends BaseApiController
public function show(int $studentId): JsonResponse
{
$student = Student::query()->find($studentId);
if (! $student) {
if (!$student) {
return response()->json(['ok' => false, 'message' => 'Student not found.'], 404);
}
@@ -243,7 +244,7 @@ class StudentController extends BaseApiController
if (array_key_exists('allergies', $payload)) {
$healthPayload['allergies'] = $payload['allergies'];
}
if (! empty($healthPayload)) {
if (!empty($healthPayload)) {
$this->profileService->updateStudent($student->id, $healthPayload);
}
@@ -360,7 +361,7 @@ class StudentController extends BaseApiController
public function destroy(int $studentId): JsonResponse
{
$student = Student::query()->find($studentId);
if (! $student) {
if (!$student) {
return response()->json(['ok' => false, 'message' => 'Student not found.'], 404);
}
@@ -502,8 +503,8 @@ class StudentController extends BaseApiController
$rows = AttendanceRecord::query()
->where('student_id', $studentId)
->when(! empty($payload['school_year']), fn ($q) => $q->where('school_year', $payload['school_year']))
->when(! empty($payload['semester']), fn ($q) => $q->where('semester', $payload['semester']))
->when(!empty($payload['school_year']), fn ($q) => $q->where('school_year', $payload['school_year']))
->when(!empty($payload['semester']), fn ($q) => $q->where('semester', $payload['semester']))
->orderBy('school_year', 'desc')
->orderBy('semester', 'desc')
->get()
@@ -534,8 +535,8 @@ class StudentController extends BaseApiController
$rows = Incident::query()
->where('student_id', $studentId)
->when(! empty($payload['school_year']), fn ($q) => $q->where('school_year', $payload['school_year']))
->when(! empty($payload['semester']), fn ($q) => $q->where('semester', $payload['semester']))
->when(!empty($payload['school_year']), fn ($q) => $q->where('school_year', $payload['school_year']))
->when(!empty($payload['semester']), fn ($q) => $q->where('semester', $payload['semester']))
->orderByDesc('incident_datetime')
->get()
->toArray();
@@ -565,8 +566,8 @@ class StudentController extends BaseApiController
$rows = SemesterScore::query()
->where('student_id', $studentId)
->when(! empty($payload['school_year']), fn ($q) => $q->where('school_year', $payload['school_year']))
->when(! empty($payload['semester']), fn ($q) => $q->where('semester', $payload['semester']))
->when(!empty($payload['school_year']), fn ($q) => $q->where('school_year', $payload['school_year']))
->when(!empty($payload['semester']), fn ($q) => $q->where('semester', $payload['semester']))
->orderBy('school_year', 'desc')
->orderBy('semester', 'desc')
->get()
@@ -591,12 +592,12 @@ class StudentController extends BaseApiController
public function parents(int $studentId): JsonResponse
{
$student = Student::query()->find($studentId);
if (! $student) {
if (!$student) {
return response()->json(['ok' => false, 'message' => 'Student not found.'], 404);
}
$parent = null;
if (! empty($student->parent_id)) {
if (!empty($student->parent_id)) {
$parent = User::query()
->select(['id', 'firstname', 'lastname', 'email', 'cellphone'])
->find((int) $student->parent_id);
@@ -612,7 +613,7 @@ class StudentController extends BaseApiController
public function emergencyContacts(int $studentId): JsonResponse
{
$student = Student::query()->find($studentId);
if (! $student) {
if (!$student) {
return response()->json(['ok' => false, 'message' => 'Student not found.'], 404);
}
@@ -620,7 +621,7 @@ class StudentController extends BaseApiController
if (Schema::hasColumn('emergency_contacts', 'student_id')) {
$query->where('student_id', $studentId);
}
if (! empty($student->parent_id)) {
if (!empty($student->parent_id)) {
$query->orWhere('parent_id', $student->parent_id);
}
@@ -639,7 +640,7 @@ class StudentController extends BaseApiController
public function addEmergencyContact(Request $request, int $studentId): JsonResponse
{
$student = Student::query()->find($studentId);
if (! $student) {
if (!$student) {
return response()->json(['ok' => false, 'message' => 'Student not found.'], 404);
}
@@ -682,7 +683,7 @@ class StudentController extends BaseApiController
public function updateEmergencyContact(Request $request, int $studentId, int $contactId): JsonResponse
{
$student = Student::query()->find($studentId);
if (! $student) {
if (!$student) {
return response()->json(['ok' => false, 'message' => 'Student not found.'], 404);
}
@@ -704,7 +705,7 @@ class StudentController extends BaseApiController
}
$contact = EmergencyContact::query()->find($contactId);
if (! $contact) {
if (!$contact) {
return response()->json(['ok' => false, 'message' => 'Contact not found.'], 404);
}
@@ -735,7 +736,7 @@ class StudentController extends BaseApiController
}
$student = Student::query()->find($studentId);
if (! $student) {
if (!$student) {
return response()->json(['ok' => false, 'message' => 'Student not found.'], 404);
}
@@ -758,14 +759,14 @@ class StudentController extends BaseApiController
}
$student = Student::query()->find($studentId);
if (! $student) {
if (!$student) {
return response()->json(['ok' => false, 'message' => 'Student not found.'], 404);
}
$file = $request->file('photo');
$ext = $file->getClientOriginalExtension() ?: 'jpg';
$path = "student-photos/{$studentId}.".strtolower($ext);
Storage::disk('public')->putFileAs('student-photos', $file, "{$studentId}.".strtolower($ext));
$path = "student-photos/{$studentId}." . strtolower($ext);
Storage::disk('public')->putFileAs('student-photos', $file, "{$studentId}." . strtolower($ext));
return response()->json([
'ok' => true,
@@ -780,7 +781,7 @@ class StudentController extends BaseApiController
$disk = Storage::disk('public');
foreach ($candidates as $ext) {
$path = $base.'.'.$ext;
$path = $base . '.' . $ext;
if ($disk->exists($path)) {
return response()->json([
'ok' => true,
@@ -795,14 +796,13 @@ class StudentController extends BaseApiController
private function generateSchoolId(int $studentId): string
{
$year = (int) date('y');
return 'STU'.$year.str_pad((string) $studentId, 4, '0', STR_PAD_LEFT);
return 'STU' . $year . str_pad((string) $studentId, 4, '0', STR_PAD_LEFT);
}
public function scoreCard(int $studentId): JsonResponse
{
$result = $this->scoreCardService->scoreCard($studentId);
if (! $result['ok']) {
if (!$result['ok']) {
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Not found.'], 404);
}