mirror of
https://github.com/grocy/grocy.git
synced 2025-10-12 08:34:48 +00:00
Created API endpoints to undo battery charge cycles and chore executions (references #63)
This commit is contained in:
@@ -18,8 +18,8 @@ class BatteriesService extends BaseService
|
||||
}
|
||||
|
||||
$battery = $this->Database->batteries($batteryId);
|
||||
$batteryChargeCylcesCount = $this->Database->battery_charge_cycles()->where('battery_id', $batteryId)->count();
|
||||
$batteryLastChargedTime = $this->Database->battery_charge_cycles()->where('battery_id', $batteryId)->max('tracked_time');
|
||||
$batteryChargeCylcesCount = $this->Database->battery_charge_cycles()->where('battery_id = :1 AND undone = 0', $batteryId)->count();
|
||||
$batteryLastChargedTime = $this->Database->battery_charge_cycles()->where('battery_id = :1 AND undone = 0', $batteryId)->max('tracked_time');
|
||||
$nextChargeTime = $this->Database->batteries_current()->where('battery_id', $batteryId)->min('next_estimated_charge_time');
|
||||
|
||||
return array(
|
||||
@@ -51,4 +51,19 @@ class BatteriesService extends BaseService
|
||||
$batteryRow = $this->Database->batteries()->where('id = :1', $batteryId)->fetch();
|
||||
return $batteryRow !== null;
|
||||
}
|
||||
|
||||
public function UndoChargeCycle($chargeCycleId)
|
||||
{
|
||||
$logRow = $this->Database->battery_charge_cycles()->where('id = :1 AND undone = 0', $chargeCycleId)->fetch();
|
||||
if ($logRow == null)
|
||||
{
|
||||
throw new \Exception('Charge cycle does not exist or was already undone');
|
||||
}
|
||||
|
||||
// Update log entry
|
||||
$logRow->update(array(
|
||||
'undone' => 1,
|
||||
'undone_timestamp' => date('Y-m-d H:i:s')
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user