add tests batch 20
This commit is contained in:
@@ -20,7 +20,8 @@ class AccountEventService
|
||||
public function __construct(
|
||||
private EmailService $emailService,
|
||||
private UserNotificationDispatchService $notifier
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
public function newAccountAdded(array $userData): array
|
||||
{
|
||||
@@ -28,7 +29,7 @@ class AccountEventService
|
||||
$message = $this->renderEmail('emails/welcome_user', ['user' => $userData], $subject);
|
||||
|
||||
$sent = false;
|
||||
if (! empty($userData['email'])) {
|
||||
if (!empty($userData['email'])) {
|
||||
$sent = $this->emailService->send(
|
||||
(string) $userData['email'],
|
||||
$subject,
|
||||
@@ -40,7 +41,7 @@ class AccountEventService
|
||||
$supportMessage = $this->renderEmail('emails/support_new_account', ['user' => $userData], $subject);
|
||||
$this->emailService->send(
|
||||
'support@alrahmaisgl.org',
|
||||
'New Account Created: '.trim((string) ($userData['firstname'] ?? '').' '.(string) ($userData['lastname'] ?? '')),
|
||||
'New Account Created: ' . trim((string) ($userData['firstname'] ?? '') . ' ' . (string) ($userData['lastname'] ?? '')),
|
||||
$supportMessage,
|
||||
'notifications'
|
||||
);
|
||||
@@ -52,14 +53,13 @@ class AccountEventService
|
||||
|
||||
public function studentRegistered(array $data): array
|
||||
{
|
||||
if (empty($data['parents']) || ! is_array($data['parents'])) {
|
||||
if (empty($data['parents']) || !is_array($data['parents'])) {
|
||||
Log::warning('StudentRegistered: missing parent data');
|
||||
|
||||
return ['ok' => false, 'message' => 'Missing parent data.'];
|
||||
}
|
||||
|
||||
$studentFullName = trim((string) ($data['firstname'] ?? '').' '.(string) ($data['lastname'] ?? ''));
|
||||
if (! empty($data['parents']['user_id'])) {
|
||||
$studentFullName = trim((string) ($data['firstname'] ?? '') . ' ' . (string) ($data['lastname'] ?? ''));
|
||||
if (!empty($data['parents']['user_id'])) {
|
||||
$title = 'Your child has been registered';
|
||||
$msg = "{$studentFullName} has been successfully registered to Al Rahma Sunday School.";
|
||||
$this->notifier->notifyUser((int) $data['parents']['user_id'], $title, $msg, ['in_app', 'email'], 'registration', 'parent');
|
||||
@@ -100,21 +100,18 @@ class AccountEventService
|
||||
public function userRegistered(array $user): array
|
||||
{
|
||||
$this->notifier->notifyUser((int) ($user['id'] ?? 0), 'Welcome!', 'Thanks for registering with our school system.', ['in_app', 'email'], 'notifications', 'parent');
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
public function userProfileUpdated(array $user): array
|
||||
{
|
||||
$this->notifier->notifyUser((int) ($user['id'] ?? 0), 'Profile Updated', 'Your profile information was successfully updated.', ['in_app'], 'notifications', 'parent');
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
public function userDeactivated(array $user): array
|
||||
{
|
||||
$this->notifier->notifyUser((int) ($user['id'] ?? 0), 'Account Deactivated', 'Your account has been deactivated by the administrator.', ['in_app', 'email'], 'notifications', 'parent');
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
@@ -123,7 +120,6 @@ class AccountEventService
|
||||
foreach ((array) ($data['students'] ?? []) as $student) {
|
||||
$this->notifier->notifyUser((int) ($student['id'] ?? 0), 'New Score Available', 'A new score has been posted.', ['in_app', 'email'], 'registration', 'student');
|
||||
}
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
@@ -140,24 +136,21 @@ class AccountEventService
|
||||
|
||||
public function studentMarkedAbsent(array $record): array
|
||||
{
|
||||
$msg = (string) ($record['student_name'] ?? 'Student').' was absent on '.(string) ($record['date'] ?? '');
|
||||
$msg = (string) ($record['student_name'] ?? 'Student') . ' was absent on ' . (string) ($record['date'] ?? '');
|
||||
$this->notifier->notifyUser((int) ($record['parent_id'] ?? 0), 'Absence Notification', $msg, ['in_app', 'email'], 'registration', 'parent');
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
public function studentMarkedLate(array $record): array
|
||||
{
|
||||
$msg = (string) ($record['student_name'] ?? 'Student').' was late on '.(string) ($record['date'] ?? '');
|
||||
$msg = (string) ($record['student_name'] ?? 'Student') . ' was late on ' . (string) ($record['date'] ?? '');
|
||||
$this->notifier->notifyUser((int) ($record['parent_id'] ?? 0), 'Late Notification', $msg, ['in_app', 'email'], 'registration', 'parent');
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
public function paymentMissed(array $user): array
|
||||
{
|
||||
$this->notifier->notifyUser((int) ($user['id'] ?? 0), 'Payment Missed', 'You have missed a scheduled payment. Please settle your balance.', ['in_app', 'email'], 'payment', 'parent');
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
@@ -166,15 +159,13 @@ class AccountEventService
|
||||
foreach ((array) ($data['students'] ?? []) as $student) {
|
||||
$this->notifier->notifyUser((int) ($student['id'] ?? 0), 'Schedule Update', 'Your class schedule has been updated.', ['in_app'], 'notifications', 'student');
|
||||
}
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
public function newMessageReceived(array $data): array
|
||||
{
|
||||
$msg = 'You have a new message from '.(string) ($data['sender_name'] ?? '');
|
||||
$msg = 'You have a new message from ' . (string) ($data['sender_name'] ?? '');
|
||||
$this->notifier->notifyUser((int) ($data['recipient_id'] ?? 0), 'New Message Received', $msg, ['in_app'], 'notifications', 'parent');
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
@@ -189,7 +180,6 @@ class AccountEventService
|
||||
foreach ($users as $user) {
|
||||
$this->notifier->notifyUser((int) ($user['id'] ?? 0), (string) ($data['title'] ?? ''), (string) ($data['message'] ?? ''), ['in_app'], 'notifications', $targetGroup);
|
||||
}
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
@@ -215,10 +205,10 @@ class AccountEventService
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($userData, $userId): void {
|
||||
$familyCode = 'FAM-'.$userId;
|
||||
$familyCode = 'FAM-' . $userId;
|
||||
$family = Family::query()->where('family_code', $familyCode)->first();
|
||||
if (! $family) {
|
||||
$householdName = trim('Family of '.((string) ($userData['firstname'] ?? '').' '.(string) ($userData['lastname'] ?? '')));
|
||||
if (!$family) {
|
||||
$householdName = trim('Family of ' . ((string) ($userData['firstname'] ?? '') . ' ' . (string) ($userData['lastname'] ?? '')));
|
||||
$family = Family::query()->create([
|
||||
'family_code' => $familyCode,
|
||||
'household_name' => $householdName,
|
||||
@@ -262,12 +252,12 @@ class AccountEventService
|
||||
{
|
||||
try {
|
||||
$currentYear = (string) Configuration::getConfigValueByKey('school_year');
|
||||
if (! preg_match('/^(\d{4})-(\d{4})$/', $currentYear, $m)) {
|
||||
if (!preg_match('/^(\d{4})-(\d{4})$/', $currentYear, $m)) {
|
||||
return;
|
||||
}
|
||||
$y1 = (int) $m[1];
|
||||
$y2 = (int) $m[2];
|
||||
$nextYear = ($y1 + 1).'-'.($y2 + 1);
|
||||
$nextYear = ($y1 + 1) . '-' . ($y2 + 1);
|
||||
|
||||
$rows = DB::table('students as s')
|
||||
->select('s.id as student_id', 'sc.class_section_id', 'fall.semester_score as fall_score', 'spring.semester_score as spring_score')
|
||||
@@ -319,7 +309,7 @@ class AccountEventService
|
||||
]);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Promotion queue build failed: '.$e->getMessage());
|
||||
Log::error('Promotion queue build failed: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,6 +317,6 @@ class AccountEventService
|
||||
{
|
||||
Log::debug('Skipping Blade email template', ['view' => $viewName]);
|
||||
|
||||
return '<p>'.e($fallbackTitle).'</p>';
|
||||
return '<p>' . e($fallbackTitle) . '</p>';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user