2023-02-08 00:14:59 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Member\Actions;
|
|
|
|
|
|
|
|
use App\Member\Member;
|
2023-02-23 00:38:17 +01:00
|
|
|
use App\Nami\Api\FullMemberAction;
|
2023-02-08 00:14:59 +01:00
|
|
|
use App\Setting\NamiSettings;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
use Lorisleiva\Actions\ActionRequest;
|
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
|
|
|
|
class MemberResyncAction
|
|
|
|
{
|
|
|
|
use AsAction;
|
|
|
|
|
|
|
|
public function handle(Member $member, NamiSettings $settings): void
|
|
|
|
{
|
|
|
|
$api = $settings->login();
|
|
|
|
|
|
|
|
if (!$member->hasNami || !$member->group->hasNami) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-02-23 00:38:17 +01:00
|
|
|
$fullMember = FullMemberAction::run($api, $member->group->nami_id, $member->nami_id);
|
2023-02-08 00:14:59 +01:00
|
|
|
|
2023-02-23 00:38:17 +01:00
|
|
|
InsertFullMemberAction::dispatch($fullMember);
|
2023-02-08 00:14:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function asController(ActionRequest $request, Member $member): RedirectResponse|Response
|
|
|
|
{
|
|
|
|
$this->handle(
|
|
|
|
$member,
|
|
|
|
app(NamiSettings::class),
|
|
|
|
);
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
}
|