update api and add more features
This commit is contained in:
@@ -74,6 +74,7 @@ class ParentRegistrationService
|
||||
}
|
||||
|
||||
$createdStudentIds = [];
|
||||
$skippedStudents = [];
|
||||
|
||||
DB::transaction(function () use (
|
||||
$parentId,
|
||||
@@ -81,17 +82,28 @@ class ParentRegistrationService
|
||||
$emergencyContacts,
|
||||
$schoolYear,
|
||||
$semester,
|
||||
&$createdStudentIds
|
||||
&$createdStudentIds,
|
||||
&$skippedStudents
|
||||
) {
|
||||
foreach ($students as $student) {
|
||||
// Duplicate check is scoped to THIS parent: one family's
|
||||
// legitimately registered child must not block another family
|
||||
// from registering a child with the same name and DOB.
|
||||
$exists = Student::query()
|
||||
->where('parent_id', $parentId)
|
||||
->where('school_year', $schoolYear)
|
||||
->where('dob', $student['dob'])
|
||||
->where('firstname', $student['firstname'])
|
||||
->where('lastname', $student['lastname'])
|
||||
->whereRaw('LOWER(TRIM(firstname)) = ?', [strtolower(trim((string) $student['firstname']))])
|
||||
->whereRaw('LOWER(TRIM(lastname)) = ?', [strtolower(trim((string) $student['lastname']))])
|
||||
->first();
|
||||
|
||||
if ($exists) {
|
||||
$skippedStudents[] = [
|
||||
'firstname' => $student['firstname'],
|
||||
'lastname' => $student['lastname'],
|
||||
'dob' => $student['dob'],
|
||||
'reason' => 'already_registered',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -153,6 +165,7 @@ class ParentRegistrationService
|
||||
|
||||
return [
|
||||
'created_student_ids' => $createdStudentIds,
|
||||
'skipped' => $skippedStudents,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user