Add fallback for single membership
This commit is contained in:
parent
4c33b9cbbc
commit
04d5e6f03a
|
@ -12,6 +12,7 @@ use Log;
|
||||||
use Zoomyboy\LaravelNami\Backend\Backend;
|
use Zoomyboy\LaravelNami\Backend\Backend;
|
||||||
use Zoomyboy\LaravelNami\Concerns\IsNamiMember;
|
use Zoomyboy\LaravelNami\Concerns\IsNamiMember;
|
||||||
use Zoomyboy\LaravelNami\Cookies\Cookie;
|
use Zoomyboy\LaravelNami\Cookies\Cookie;
|
||||||
|
use Zoomyboy\LaravelNami\Exceptions\RightException;
|
||||||
use Zoomyboy\LaravelNami\NamiException;
|
use Zoomyboy\LaravelNami\NamiException;
|
||||||
|
|
||||||
class Api {
|
class Api {
|
||||||
|
@ -149,6 +150,10 @@ class Api {
|
||||||
|
|
||||||
Logger::http($url, $response, 'Single Membership '.$membershipId.' from '.$memberId, ['memberId' => $memberId]);
|
Logger::http($url, $response, 'Single Membership '.$membershipId.' from '.$memberId, ['memberId' => $memberId]);
|
||||||
|
|
||||||
|
if($response->json()['success'] === false && Str::startsWith($response['message'], 'Sicherheitsverletzung')) {
|
||||||
|
throw new RightException('');
|
||||||
|
}
|
||||||
|
|
||||||
return $response->json()['data'];
|
return $response->json()['data'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
|
|
||||||
namespace Zoomyboy\LaravelNami\Authentication;
|
namespace Zoomyboy\LaravelNami\Authentication;
|
||||||
|
|
||||||
use Illuminate\Contracts\Auth\Guard;
|
|
||||||
use Illuminate\Contracts\Auth\Authenticatable;
|
|
||||||
use Zoomyboy\LaravelNami\Nami;
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
use Zoomyboy\LaravelNami\NamiUser;
|
|
||||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
|
||||||
use Illuminate\Auth\SessionGuard;
|
|
||||||
use Illuminate\Auth\GuardHelpers;
|
use Illuminate\Auth\GuardHelpers;
|
||||||
|
use Illuminate\Auth\SessionGuard;
|
||||||
|
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
||||||
|
use Illuminate\Contracts\Auth\Authenticatable;
|
||||||
|
use Illuminate\Contracts\Auth\Guard;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Zoomyboy\LaravelNami\Nami;
|
||||||
|
use Zoomyboy\LaravelNami\NamiUser;
|
||||||
|
|
||||||
class NamiGuard {
|
class NamiGuard {
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zoomyboy\LaravelNami\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class RightException extends Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ namespace Zoomyboy\LaravelNami;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\LazyCollection;
|
use Illuminate\Support\LazyCollection;
|
||||||
|
use Zoomyboy\LaravelNami\Exceptions\RightException;
|
||||||
|
|
||||||
class Member extends Model {
|
class Member extends Model {
|
||||||
|
|
||||||
|
@ -140,13 +141,23 @@ class Member extends Model {
|
||||||
|
|
||||||
return LazyCollection::make(function() use ($memberships) {
|
return LazyCollection::make(function() use ($memberships) {
|
||||||
foreach ($memberships as $membership) {
|
foreach ($memberships as $membership) {
|
||||||
yield $this->membership($membership['id']);
|
$m = $this->membership($membership['id']);
|
||||||
|
|
||||||
|
if ($m === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
yield $m;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function membership($id): Membership {
|
public function membership($id): ?Membership {
|
||||||
|
try {
|
||||||
return Membership::fromNami(Nami::membership($this->id, $id));
|
return Membership::fromNami(Nami::membership($this->id, $id));
|
||||||
|
} catch (RightException $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue