[server] Bugfix: Updatee device-data action t use DB structure

This commit is contained in:
Starbeamrainbowlabs 2019-02-20 17:39:45 +00:00
parent 69a581094a
commit 519e85b66a
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
3 changed files with 7 additions and 5 deletions

View File

@ -69,7 +69,9 @@ class DeviceData implements IAction {
return false; return false;
} }
if(!$this->type_repo->is_valid_type($_GET["reading-type"])) { $reading_type_id = $this->type_repo->get_id($_GET["reading-type"]);
if($reading_type_id == null) {
$this->sender->send_error_plain( $this->sender->send_error_plain(
400, "Error: That reading type is invalid.", [ 400, "Error: That reading type is invalid.", [
[ "x-time-taken", PerfFormatter::format_perf_data($start_time, $start_handle, null) ] [ "x-time-taken", PerfFormatter::format_perf_data($start_time, $start_handle, null) ]
@ -81,7 +83,7 @@ class DeviceData implements IAction {
// 2: Pull data from database // 2: Pull data from database
$data = $this->measurement_repo->get_readings_by_device( $data = $this->measurement_repo->get_readings_by_device(
intval($_GET["device-id"]), intval($_GET["device-id"]),
$_GET["reading-type"], $reading_type_id,
new \DateTime($_GET["start"]), new \DateTime($_GET["start"]),
new \DateTime($_GET["end"]), new \DateTime($_GET["end"]),
!empty($_GET["average-seconds"]) ? intval($_GET["average-seconds"]) : 1 !empty($_GET["average-seconds"]) ? intval($_GET["average-seconds"]) : 1

View File

@ -13,9 +13,9 @@ interface IMeasurementTypeRepository {
/** /**
* Get the id associated with the given short description. * Get the id associated with the given short description.
* @param string $short_descr The short description to convert. * @param string $short_descr The short description to convert.
* @return int The id associated with the specified short description. * @return int|null The id associated with the specified short description.
*/ */
public function get_id(string $short_descr) : int; public function get_id(string $short_descr);
/** /**
* Gets the friendly name for the specified type name. * Gets the friendly name for the specified type name.

View File

@ -41,7 +41,7 @@ class MariaDBMeasurementTypeRepository implements IMeasurementTypeRepository {
)->fetchColumn()); )->fetchColumn());
} }
public function get_id(string $short_descr) : int { public function get_id(string $short_descr) {
$s = $this->get_static; $s = $this->get_static;
$result = $this->database->query( $result = $this->database->query(