diff --git a/src/Api.php b/src/Api.php index 53f2e93..3e49a20 100644 --- a/src/Api.php +++ b/src/Api.php @@ -126,14 +126,22 @@ class Api { public function putMembership(int $memberId, array $data): int { - $url = self::$url."/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/{$memberId}"; - - $response = $this->http()->post($url, $data); + if (data_get($data, 'id')) { + $url = self::$url."/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/{$memberId}/{$data['id']}"; + $response = $this->http()->put($url, $data); + } else { + $url = self::$url."/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/{$memberId}"; + $response = $this->http()->post($url, $data); + } if (data_get($response->json(), 'success') !== true) { $this->exception('Update failed', ['url' => $url, 'data' => $data], $response->json()); } - return $response->json()['data']; + if (data_get($data, 'id')) { + return $response->json()['data']['id']; + } else { + return $response->json()['data']; + } } public function membershipsOf($memberId): Collection { diff --git a/src/Member.php b/src/Member.php index c87e893..76039f6 100644 --- a/src/Member.php +++ b/src/Member.php @@ -158,7 +158,19 @@ class Member extends Model { 'gruppierungId' => $data['group_id'], 'taetigkeitId' => $data['activity_id'], 'untergliederungId' => $data['subactivity_id'], - 'aktivVon' => $data['created_at']->format('Y-m-d').'T00:00:00', + 'aktivVon' => $data['starts_at']->format('Y-m-d').'T00:00:00', + ]); + } + + public function deleteMembership(int $id): int + { + $membership = $this->membership($id); + + return Nami::putMembership($this->id, [ + 'gruppierungId' => $membership->group_id, + 'aktivVon' => $membership->starts_at.'T00:00:00', + 'aktivBis' => now()->format('Y-m-d').'T00:00:00', + 'id' => $membership->id, ]); }