Delete membership

This commit is contained in:
philipp lang 2021-08-22 23:32:23 +02:00
parent 9f5324b0d0
commit 244915432b
2 changed files with 25 additions and 5 deletions

View File

@ -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 {

View File

@ -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,
]);
}