Skip to content

Commit

Permalink
Fix status of schedules
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrooksuk committed Oct 16, 2024
1 parent af55fe4 commit 15ee7ed
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
5 changes: 2 additions & 3 deletions database/factories/ScheduleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Cachet\Database\Factories;

use Cachet\Enums\ScheduleStatusEnum;
use Cachet\Models\Schedule;
use Illuminate\Database\Eloquent\Factories\Factory;

Expand Down Expand Up @@ -39,15 +38,15 @@ public function inProgress(): self
{
return $this->state([
'scheduled_at' => now()->subMinutes(30),
'completed_at' => now()->addDays(14),
'completed_at' => null,
]);
}

public function inTheFuture(): self
{
return $this->state([
'scheduled_at' => now()->addDays(30),
'completed_at' => now()->addDays(180),
'completed_at' => null,
]);
}

Expand Down
16 changes: 8 additions & 8 deletions src/Models/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public function status(): Attribute
return Attribute::get(function () {
$now = Carbon::now();

return match(true) {
return match (true) {
$this->scheduled_at->gte($now) => ScheduleStatusEnum::upcoming,
$this->completed_at->gte($now) || $this->completed_at === null => ScheduleStatusEnum::in_progress,
$this->completed_at === null => ScheduleStatusEnum::in_progress,
default => ScheduleStatusEnum::complete,
};
});
Expand Down Expand Up @@ -68,8 +68,8 @@ public function formattedMessage(): string
*/
public function scopeIncomplete(Builder $query): Builder
{
return $query->whereDate('completed_at', '>=', Carbon::now())
->orWhereNull('completed_at');
return $query->whereDate('scheduled_at', '>=', Carbon::now())
->whereNull('completed_at');
}

/**
Expand All @@ -78,10 +78,10 @@ public function scopeIncomplete(Builder $query): Builder
public function scopeInProgress(Builder $query): Builder
{
return $query->whereDate('scheduled_at', '<=', Carbon::now())
->where(function (Builder $query) {
$query->whereDate('completed_at', '>=', Carbon::now())
->orWhereNull('completed_at');
});
->where(function (Builder $query) {
$query->whereDate('completed_at', '>=', Carbon::now())
->orWhereNull('completed_at');
});
}

/**
Expand Down
3 changes: 1 addition & 2 deletions tests/Feature/Api/ScheduleTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use Cachet\Enums\ScheduleStatusEnum;
use Cachet\Models\Component;
use Cachet\Models\Schedule;

Expand Down Expand Up @@ -199,7 +198,7 @@

$response = putJson('/status/api/schedules/'.$schedule->id, [
'name' => 'Updated Scheduled Maintenance',
'message' => 'Something went wrong.'
'message' => 'Something went wrong.',
]);

$response->assertOk();
Expand Down

0 comments on commit 15ee7ed

Please sign in to comment.