diff --git a/api/src/Controllers/UserController.php b/api/src/Controllers/UserController.php index 9951a9d6e..ad1e9739e 100644 --- a/api/src/Controllers/UserController.php +++ b/api/src/Controllers/UserController.php @@ -275,13 +275,8 @@ function _update_user() $person = $this->userData->getUser($this->user->personId, $this->proposalid, $this->arg('PERSONID')); $person = $person[0]; $this->_output((array) $person); - $laboratory = null; - if ($person['LABORATORYID']) - { - $laboratory = $this->userData->getLaboratory($person['LABORATORYID'])[0]; - } - $this->userData->updateLaboratory( + $laboratoryId = $this->userData->updateLaboratory( $this->arg('PERSONID'), $this->argOrNull('LABNAME'), $this->argOrNull('ADDRESS'), @@ -290,7 +285,7 @@ function _update_user() $this->argOrNull('COUNTRY'), $person['LABORATORYID'] ); - $laboratory = $this->userData->getLaboratory($person['LABORATORYID']); + $laboratory = $this->userData->getLaboratory($laboratoryId); $this->_output((array) $laboratory[0]); } @@ -362,4 +357,4 @@ function _update_permission() ); $this->_output(array('TYPE' => $this->arg('TYPE'), 'DESCRIPTION' => $desc)); } -} \ No newline at end of file +} diff --git a/api/src/Model/Services/UserData.php b/api/src/Model/Services/UserData.php index 2a01cdbb5..0c65542db 100644 --- a/api/src/Model/Services/UserData.php +++ b/api/src/Model/Services/UserData.php @@ -340,6 +340,7 @@ function updateLaboratory($personId, $labName, $labAddress, $city, $postcode, $c ->whereIdEquals("personid", $personId) ->update("person"); } + return $laboratoryId; } function addGroupUser($personId, $gid) diff --git a/api/tests/Controllers/UserControllerTest.php b/api/tests/Controllers/UserControllerTest.php index 8c31e82b1..03dd3c6da 100644 --- a/api/tests/Controllers/UserControllerTest.php +++ b/api/tests/Controllers/UserControllerTest.php @@ -373,8 +373,8 @@ public function testUpdateUserWithValidPersonIdAndLabIdReturnsData(): void $this->dataLayerStub->expects($this->exactly(2))->method('getUser')->with(231312, null, 88)->willReturn($results); $this->dataLayerStub->expects($this->exactly(1))->method('updateUser'); - $this->dataLayerStub->expects($this->exactly(2))->method('getLaboratory')->with(666)->willReturn($labResults); - $this->dataLayerStub->expects($this->exactly(1))->method('updateLaboratory'); + $this->dataLayerStub->expects($this->exactly(1))->method('getLaboratory')->with(666)->willReturn($labResults); + $this->dataLayerStub->expects($this->exactly(1))->method('updateLaboratory')->willReturn(666); $this->userController->_update_user(); } @@ -563,4 +563,4 @@ public function testGetPermissionsWithPidSpecifiedReturnsData(): void $this->userController->_get_permissions(); $this->assertEquals(61, $response->getBody()); } -} \ No newline at end of file +}