update controllers logic
This commit is contained in:
@@ -4,13 +4,15 @@ namespace App\Services\Frontend;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use App\Models\StudentClass;
|
||||
use App\Services\Parents\PrimaryParentUserResolver;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LandingPageParentDashboardService
|
||||
{
|
||||
public function __construct(private LandingPageContextService $context)
|
||||
{
|
||||
}
|
||||
public function __construct(
|
||||
private LandingPageContextService $context,
|
||||
private PrimaryParentUserResolver $primaryParentResolver,
|
||||
) {}
|
||||
|
||||
public function summary(int $parentUserId, string $userType): array
|
||||
{
|
||||
@@ -18,7 +20,7 @@ class LandingPageParentDashboardService
|
||||
$schoolYear = (string) ($context['school_year'] ?? '');
|
||||
$semester = (string) ($context['semester'] ?? '');
|
||||
|
||||
$parentId = $this->resolveParentId($parentUserId, $userType);
|
||||
$parentId = $this->primaryParentResolver->resolveFromCredentials($parentUserId, $userType);
|
||||
if (!$parentId) {
|
||||
return [
|
||||
'ok' => false,
|
||||
@@ -89,31 +91,6 @@ class LandingPageParentDashboardService
|
||||
];
|
||||
}
|
||||
|
||||
private function resolveParentId(int $userId, string $userType): ?int
|
||||
{
|
||||
if ($userType === 'primary') {
|
||||
return $userId;
|
||||
}
|
||||
|
||||
if ($userType === 'secondary') {
|
||||
$row = DB::table('parents')
|
||||
->select('parent_id')
|
||||
->where('secondparent_user_id', $userId)
|
||||
->first();
|
||||
return $row ? (int) $row->parent_id : null;
|
||||
}
|
||||
|
||||
if ($userType === 'tertiary') {
|
||||
$row = DB::table('authorized_users')
|
||||
->select('user_id as parent_id')
|
||||
->where('authorized_user_id', $userId)
|
||||
->first();
|
||||
return $row ? (int) $row->parent_id : null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function notificationsForParent(int $parentId): array
|
||||
{
|
||||
return DB::table('notifications')
|
||||
|
||||
Reference in New Issue
Block a user