assign membership to member
This commit is contained in:
parent
fbd397e1df
commit
5c72f4219e
|
@ -18,4 +18,8 @@ class Activity extends Model
|
|||
public function subactivities() {
|
||||
return $this->belongsToMany(Subactivity::class);
|
||||
}
|
||||
|
||||
public static function nami($id) {
|
||||
return static::firstWhere('nami_id', $id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,4 +11,8 @@ class Group extends Model
|
|||
|
||||
public $fillable = ['nami_id', 'name'];
|
||||
public $timestamps = false;
|
||||
|
||||
public static function nami($id) {
|
||||
return static::firstWhere('nami_id', $id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ use Illuminate\Queue\InteractsWithQueue;
|
|||
use Illuminate\Queue\SerializesModels;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use App\Confession;
|
||||
use App\Group;
|
||||
use App\Activity;
|
||||
|
||||
class CreateJob implements ShouldQueue
|
||||
{
|
||||
|
@ -37,7 +39,7 @@ class CreateJob implements ShouldQueue
|
|||
return false;
|
||||
}
|
||||
|
||||
$response = Nami::login($this->user->mglnr)->putMember([
|
||||
$response = $this->user->api()->putMember([
|
||||
'firstname' => $this->member->firstname,
|
||||
'lastname' => $this->member->lastname,
|
||||
'nickname' => $this->member->nickname,
|
||||
|
@ -70,5 +72,16 @@ class CreateJob implements ShouldQueue
|
|||
$version = Nami::login($this->user->mglnr)->member($this->member->group->nami_id, $response['id'])['version'];
|
||||
$this->member->update(['version' => $version, 'nami_id' => $response['id']]);
|
||||
});
|
||||
|
||||
$memberships = $this->member->getNamiMemberships($this->user->api());
|
||||
foreach ($memberships as $membership) {
|
||||
$this->member->memberships()->create([
|
||||
'activity_id' => Activity::nami($membership['activity_id'])->id,
|
||||
'group_id' => Group::nami($membership['group_id'])->id,
|
||||
'nami_id' => $membership['id'],
|
||||
'created_at' => $membership['starts_at'],
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ use App\Fee;
|
|||
use App\Group;
|
||||
use App\Activity;
|
||||
use App\Subactivity;
|
||||
use Zoomyboy\LaravelNami\NamiUser;
|
||||
|
||||
class Member extends Model
|
||||
{
|
||||
|
@ -88,7 +89,7 @@ class Member extends Model
|
|||
|
||||
public function memberships()
|
||||
{
|
||||
return $this->hasMany(App\Membership::class);
|
||||
return $this->hasMany(Membership::class);
|
||||
}
|
||||
|
||||
public function fee()
|
||||
|
@ -119,4 +120,9 @@ class Member extends Model
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function getNamiMemberships($api) {
|
||||
return $api->group($this->group->nami_id)->member($this->nami_id)->memberships()->toArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace App\Member;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Membership extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public $fillable = ['activity_id', 'group_id', 'member_id', 'nami_id', 'created_at'];
|
||||
}
|
Loading…
Reference in New Issue