fix tests
This commit is contained in:
@@ -15,7 +15,6 @@ 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;
|
||||
@@ -82,10 +81,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)));
|
||||
@@ -149,7 +148,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);
|
||||
}
|
||||
|
||||
@@ -263,7 +262,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);
|
||||
}
|
||||
|
||||
@@ -380,7 +379,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);
|
||||
}
|
||||
|
||||
@@ -522,8 +521,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()
|
||||
@@ -554,8 +553,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();
|
||||
@@ -585,8 +584,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()
|
||||
@@ -611,12 +610,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);
|
||||
@@ -632,7 +631,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);
|
||||
}
|
||||
|
||||
@@ -640,7 +639,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);
|
||||
}
|
||||
|
||||
@@ -659,7 +658,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);
|
||||
}
|
||||
|
||||
@@ -702,7 +701,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);
|
||||
}
|
||||
|
||||
@@ -724,7 +723,7 @@ class StudentController extends BaseApiController
|
||||
}
|
||||
|
||||
$contact = EmergencyContact::query()->find($contactId);
|
||||
if (!$contact) {
|
||||
if (! $contact) {
|
||||
return response()->json(['ok' => false, 'message' => 'Contact not found.'], 404);
|
||||
}
|
||||
|
||||
@@ -755,7 +754,7 @@ class StudentController extends BaseApiController
|
||||
}
|
||||
|
||||
$student = Student::query()->find($studentId);
|
||||
if (!$student) {
|
||||
if (! $student) {
|
||||
return response()->json(['ok' => false, 'message' => 'Student not found.'], 404);
|
||||
}
|
||||
|
||||
@@ -778,14 +777,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,
|
||||
@@ -800,7 +799,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,
|
||||
@@ -815,13 +814,14 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user