Skip to content

Commit 145a86c

Browse files
authored
Only alter status from incidents if they aren't resolved (#232)
1 parent 0319a17 commit 145a86c

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Models/Component.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function scopeOutage(Builder $query): void
135135
*/
136136
public function latestStatus(): Attribute
137137
{
138-
return Attribute::get(fn () => $this->incidents()->latest()->first()?->pivot->component_status ?? $this->status);
138+
return Attribute::get(fn () => $this->incidents()->unresolved()->latest()->first()?->pivot->component_status ?? $this->status);
139139
}
140140

141141
/**

src/Status.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public function incidents(): object
8080
return $this->incidents ??= Incident::query()
8181
->toBase()
8282
->selectRaw('count(*) as total')
83-
->selectRaw('sum(case when ? in (incidents.status, latest_update.status) then 1 else 0 end) as resolved', [IncidentStatusEnum::fixed->value])
84-
->selectRaw('sum(case when ? not in (incidents.status, latest_update.status) then 1 else 0 end) as unresolved', [IncidentStatusEnum::fixed->value])
83+
->selectRaw('sum(case when ? in (incidents.status, coalesce(latest_update.status, ?)) then 1 else 0 end) as resolved', [IncidentStatusEnum::fixed->value, ''])
84+
->selectRaw('sum(case when ? not in (incidents.status, coalesce(latest_update.status, ?)) then 1 else 0 end) as unresolved', [IncidentStatusEnum::fixed->value, ''])
8585
->joinSub(function (Builder $query) {
8686
$query
8787
->select('iu1.updateable_id', 'iu1.status')
@@ -92,8 +92,8 @@ public function incidents(): object
9292
->from('updates')
9393
->where('updates.updateable_type', Relation::getMorphAlias(Incident::class))
9494
->groupBy('updateable_id');
95-
}, 'iu2', 'iu1.id', '=', 'iu2.max_id');
96-
}, 'latest_update', 'latest_update.updateable_id', '=', 'incidents.id')
95+
}, 'iu2', 'iu1.id', '=', 'iu2.max_id', 'left');
96+
}, 'latest_update', 'latest_update.updateable_id', '=', 'incidents.id', 'left')
9797
->first();
9898
}
9999
}

0 commit comments

Comments
 (0)