fix gitlab tests

This commit is contained in:
root
2026-06-09 02:32:58 -04:00
parent 20a0b6c4e5
commit 6def9993da
1489 changed files with 10449 additions and 11356 deletions
+40 -47
View File
@@ -2,8 +2,9 @@
namespace App\Models;
use Illuminate\Database\QueryException;
use App\Models\BaseModel;
use Illuminate\Support\Carbon;
use Illuminate\Database\QueryException;
class AttendanceDay extends BaseModel
{
@@ -38,20 +39,20 @@ class AttendanceDay extends BaseModel
protected $casts = [
'class_section_id' => 'integer',
'submitted_by' => 'integer',
'published_by' => 'integer',
'reopened_by' => 'integer',
'submitted_by' => 'integer',
'published_by' => 'integer',
'reopened_by' => 'integer',
// If these are DATETIME columns:
'submitted_at' => 'datetime',
'published_at' => 'datetime',
'auto_publish_at' => 'datetime',
'reopened_at' => 'datetime',
'created_at' => 'datetime',
'updated_at' => 'datetime',
'submitted_at' => 'datetime',
'published_at' => 'datetime',
'auto_publish_at' => 'datetime',
'reopened_at' => 'datetime',
'created_at' => 'datetime',
'updated_at' => 'datetime',
// If date is stored as DATE string; if it's DATETIME, change to 'datetime'
'date' => 'date',
'date' => 'date',
];
/* =========================
@@ -74,15 +75,11 @@ class AttendanceDay extends BaseModel
->whereDate('date', $date)
->where(function ($w) {
$w->where('status', 'published')
->orWhere('status', 'finalized'); // legacy
->orWhere('status', 'finalized'); // legacy
});
if ($semester !== null) {
$q->where('semester', $semester);
}
if ($schoolYear !== null) {
$q->where('school_year', $schoolYear);
}
if ($semester !== null) $q->where('semester', $semester);
if ($schoolYear !== null) $q->where('school_year', $schoolYear);
return $q->exists();
}
@@ -116,9 +113,7 @@ class AttendanceDay extends BaseModel
int $userId = 0
): self {
$row = static::findBySectionDate($classSectionId, $date, $semester, $schoolYear);
if ($row) {
return $row;
}
if ($row) return $row;
$now = now();
$normalizedDate = Carbon::parse($date)->toDateString();
@@ -126,27 +121,25 @@ class AttendanceDay extends BaseModel
try {
return static::create([
'class_section_id' => $classSectionId,
'date' => $normalizedDate,
'status' => 'draft',
'submitted_by' => null,
'submitted_at' => null,
'published_by' => null,
'published_at' => null,
'auto_publish_at' => null,
'reopened_by' => null,
'reopened_at' => null,
'reopen_reason' => null,
'semester' => $semester,
'school_year' => $schoolYear,
'created_at' => $now,
'updated_at' => $now,
'date' => $normalizedDate,
'status' => 'draft',
'submitted_by' => null,
'submitted_at' => null,
'published_by' => null,
'published_at' => null,
'auto_publish_at' => null,
'reopened_by' => null,
'reopened_at' => null,
'reopen_reason' => null,
'semester' => $semester,
'school_year' => $schoolYear,
'created_at' => $now,
'updated_at' => $now,
]);
} catch (QueryException $e) {
// Race: someone inserted same unique key.
$row = static::findBySectionDate($classSectionId, $date, $semester, $schoolYear);
if ($row) {
return $row;
}
if ($row) return $row;
throw $e;
}
}
@@ -167,10 +160,10 @@ class AttendanceDay extends BaseModel
$now = now();
$payload = [
'status' => 'submitted',
'status' => 'submitted',
'submitted_by' => $userId,
'submitted_at' => $now,
'updated_at' => $now,
'updated_at' => $now,
];
if ($autoPublishAt !== null) {
@@ -188,10 +181,10 @@ class AttendanceDay extends BaseModel
$now = now();
return static::query()->whereKey($this->id)->update([
'status' => 'published',
'status' => 'published',
'published_by' => $userId,
'published_at' => $now,
'updated_at' => $now,
'updated_at' => $now,
]) >= 0;
}
@@ -200,18 +193,18 @@ class AttendanceDay extends BaseModel
*/
public function reopen(int $userId, string $toStatus = 'draft', ?string $reason = null): bool
{
if (! in_array($toStatus, ['draft', 'submitted'], true)) {
if (!in_array($toStatus, ['draft', 'submitted'], true)) {
throw new \InvalidArgumentException('toStatus must be "draft" or "submitted".');
}
$now = now();
return static::query()->whereKey($this->id)->update([
'status' => $toStatus,
'reopened_by' => $userId,
'reopened_at' => $now,
'status' => $toStatus,
'reopened_by' => $userId,
'reopened_at' => $now,
'reopen_reason' => $reason,
'updated_at' => $now,
'updated_at' => $now,
]) >= 0;
}
}