fix gitlab tests
This commit is contained in:
@@ -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;
|
||||
@@ -67,7 +68,7 @@ class StudentController extends BaseApiController
|
||||
$data = array_merge($request->query->all(), $request->all(), $request->json()->all());
|
||||
$validator = Validator::make($data, [
|
||||
'school_year' => ['nullable', 'string', 'max:50'],
|
||||
'parent_id' => ['nullable', 'integer', 'min:1'],
|
||||
'parent_id' => ['required', 'integer', 'min:1'],
|
||||
'parent_ids' => ['nullable', 'array'],
|
||||
'parent_ids.*' => ['integer', 'min:1'],
|
||||
]);
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -192,17 +193,17 @@ class StudentController extends BaseApiController
|
||||
'firstname' => ['required', 'string', 'max:150'],
|
||||
'lastname' => ['required', 'string', 'max:150'],
|
||||
'dob' => ['nullable', 'date'],
|
||||
'age' => ['nullable', 'integer', 'min:0'],
|
||||
'gender' => ['nullable', 'string', 'max:20'],
|
||||
'age' => ['required', 'integer', 'min:0'],
|
||||
'gender' => ['required', 'string', 'max:20'],
|
||||
'is_active' => ['nullable', 'boolean'],
|
||||
'registration_grade' => ['nullable', 'string', 'max:50'],
|
||||
'is_new' => ['nullable', 'boolean'],
|
||||
'photo_consent' => ['nullable', 'boolean'],
|
||||
'parent_id' => ['nullable', 'integer', 'min:1'],
|
||||
'photo_consent' => ['required', 'boolean'],
|
||||
'parent_id' => ['required', 'integer', 'min:1'],
|
||||
'registration_date' => ['nullable', 'date'],
|
||||
'tuition_paid' => ['nullable', 'boolean'],
|
||||
'semester' => ['nullable', 'string', 'max:50'],
|
||||
'year_of_registration' => ['nullable', 'integer', 'min:1900'],
|
||||
'year_of_registration' => ['required', 'integer', 'min:1900'],
|
||||
'school_year' => ['required', 'string', 'max:50'],
|
||||
'medical_conditions' => ['nullable', 'string'],
|
||||
'allergies' => ['nullable', 'string'],
|
||||
@@ -229,7 +230,26 @@ class StudentController extends BaseApiController
|
||||
}
|
||||
|
||||
$payload = $validator->validated();
|
||||
$student = Student::query()->create($payload);
|
||||
$studentPayload = collect($payload)->only([
|
||||
'school_id',
|
||||
'firstname',
|
||||
'lastname',
|
||||
'dob',
|
||||
'age',
|
||||
'gender',
|
||||
'is_active',
|
||||
'registration_grade',
|
||||
'is_new',
|
||||
'photo_consent',
|
||||
'parent_id',
|
||||
'registration_date',
|
||||
'tuition_paid',
|
||||
'semester',
|
||||
'year_of_registration',
|
||||
'school_year',
|
||||
])->all();
|
||||
|
||||
$student = Student::query()->create($studentPayload);
|
||||
|
||||
if (empty($student->school_id)) {
|
||||
$student->school_id = $this->generateSchoolId($student->id);
|
||||
@@ -243,7 +263,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 +380,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 +522,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 +554,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 +585,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 +611,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 +632,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 +640,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 +659,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 +702,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 +724,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 +755,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 +778,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 +800,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 +815,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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user