add test batches
This commit is contained in:
@@ -10,7 +10,9 @@ use RuntimeException;
|
||||
|
||||
class StaffCommandService
|
||||
{
|
||||
public function __construct(private GlobalConfigService $configService) {}
|
||||
public function __construct(private GlobalConfigService $configService)
|
||||
{
|
||||
}
|
||||
|
||||
public function create(array $payload): Staff
|
||||
{
|
||||
@@ -19,7 +21,7 @@ class StaffCommandService
|
||||
|
||||
$roleName = (string) ($payload['role_name'] ?? '');
|
||||
$activeRole = strtolower($roleName);
|
||||
if (! empty($payload['status']) && strtolower((string) $payload['status']) === 'inactive') {
|
||||
if (!empty($payload['status']) && strtolower((string) $payload['status']) === 'inactive') {
|
||||
$activeRole = 'inactive';
|
||||
}
|
||||
|
||||
@@ -38,7 +40,7 @@ class StaffCommandService
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
if (! $staff) {
|
||||
if (!$staff) {
|
||||
throw new RuntimeException('Failed to create staff member.');
|
||||
}
|
||||
|
||||
@@ -59,13 +61,13 @@ class StaffCommandService
|
||||
if (array_key_exists('role_name', $updates)) {
|
||||
$updates['active_role'] = strtolower((string) $updates['role_name']);
|
||||
}
|
||||
if (! empty($payload['status']) && strtolower((string) $payload['status']) === 'inactive') {
|
||||
if (!empty($payload['status']) && strtolower((string) $payload['status']) === 'inactive') {
|
||||
$updates['active_role'] = 'inactive';
|
||||
}
|
||||
|
||||
$updates['updated_at'] = now();
|
||||
|
||||
if (! empty($updates)) {
|
||||
if (!empty($updates)) {
|
||||
$staff->fill($updates);
|
||||
$staff->save();
|
||||
}
|
||||
@@ -81,7 +83,7 @@ class StaffCommandService
|
||||
|
||||
private function resolveUserId(array $payload): int
|
||||
{
|
||||
if (! empty($payload['user_id'])) {
|
||||
if (!empty($payload['user_id'])) {
|
||||
return (int) $payload['user_id'];
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,14 @@ use App\Models\Staff;
|
||||
use App\Models\TeacherClass;
|
||||
use App\Models\User;
|
||||
use App\Services\System\GlobalConfigService;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class StaffQueryService
|
||||
{
|
||||
public function __construct(private GlobalConfigService $configService) {}
|
||||
public function __construct(private GlobalConfigService $configService)
|
||||
{
|
||||
}
|
||||
|
||||
public function paginate(array $filters, int $page, int $perPage): array
|
||||
{
|
||||
@@ -19,7 +22,7 @@ class StaffQueryService
|
||||
$query = Staff::query()
|
||||
->whereNotIn(DB::raw('LOWER(active_role)'), $excluded);
|
||||
|
||||
if (! empty($filters['role'])) {
|
||||
if (!empty($filters['role'])) {
|
||||
$role = strtolower(trim((string) $filters['role']));
|
||||
$query->whereRaw('LOWER(active_role) = ?', [$role]);
|
||||
}
|
||||
@@ -44,7 +47,7 @@ class StaffQueryService
|
||||
if (in_array($role, ['teacher', 'teacher_assistant'], true)) {
|
||||
$tid = (int) ($staff->user_id ?? 0);
|
||||
$labels = $assignByTeacher[$tid] ?? [];
|
||||
if (! empty($labels)) {
|
||||
if (!empty($labels)) {
|
||||
$staff->class_section = implode(', ', array_unique($labels));
|
||||
$staff->verification_issue = false;
|
||||
} else {
|
||||
@@ -98,10 +101,10 @@ class StaffQueryService
|
||||
continue;
|
||||
}
|
||||
$pos = strtolower((string) ($row->position ?? ''));
|
||||
if (! in_array($pos, ['main', 'ta'], true)) {
|
||||
if (!in_array($pos, ['main', 'ta'], true)) {
|
||||
continue;
|
||||
}
|
||||
$assignByTeacher[$tid][] = $name.' ('.$pos.')';
|
||||
$assignByTeacher[$tid][] = $name . ' (' . $pos . ')';
|
||||
}
|
||||
|
||||
return $assignByTeacher;
|
||||
|
||||
@@ -5,11 +5,9 @@ namespace App\Services\Staff;
|
||||
class StaffTimeOffLinkService
|
||||
{
|
||||
private const TOKEN_CONTEXT = 'timeoff_notify';
|
||||
|
||||
private const DEFAULT_TTL = 1209600;
|
||||
|
||||
private string $secret;
|
||||
|
||||
private int $ttl;
|
||||
|
||||
public function __construct(?string $secret = null, ?int $ttlSeconds = null)
|
||||
@@ -32,12 +30,12 @@ class StaffTimeOffLinkService
|
||||
|
||||
public function parseToken(?string $token): ?array
|
||||
{
|
||||
if (! is_string($token) || $token === '') {
|
||||
if (!is_string($token) || $token === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$payload = $this->jwtDecode($token, $this->secret);
|
||||
if (! is_array($payload)) {
|
||||
if (!is_array($payload)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -79,17 +77,17 @@ class StaffTimeOffLinkService
|
||||
$payload = json_decode($this->base64UrlDecode($payload64), true);
|
||||
$signature = $this->base64UrlDecode($signature64);
|
||||
|
||||
if (! is_array($header) || ! is_array($payload)) {
|
||||
if (!is_array($header) || !is_array($payload)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$signingInput = $header64.'.'.$payload64;
|
||||
$signingInput = $header64 . '.' . $payload64;
|
||||
if (($header['alg'] ?? '') !== 'HS256') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$expected = hash_hmac('sha256', $signingInput, $secret, true);
|
||||
if (! hash_equals($expected, $signature)) {
|
||||
if (!hash_equals($expected, $signature)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -107,7 +105,6 @@ class StaffTimeOffLinkService
|
||||
if ($padding > 0) {
|
||||
$data .= str_repeat('=', 4 - $padding);
|
||||
}
|
||||
|
||||
return base64_decode(strtr($data, '-_', '+/')) ?: '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user