-
Notifications
You must be signed in to change notification settings - Fork 1
/
UserUpdateJob.php
46 lines (38 loc) · 1.33 KB
/
UserUpdateJob.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace App\Jobs;
use App\Enums\UserRoles;
use App\Http\QuaverApi\QuaverApi;
use App\Models\User;
use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class UserUpdateJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, Batchable;
public User $user;
public function __construct(User $user)
{
$this->user = $user->withoutRelations();
}
public function handle(): void
{
try {
$user_api = QuaverApi::getUserFull($this->user->quaver_user_id);
if ($user_api) {
$this->user->username = $user_api['info']['username'];
$this->user->country = $user_api['info']['country'] ?? 'XX';
$this->user->quaver_4k_rank = $user_api['keys4']['globalRank'];
$this->user->quaver_7k_rank = $user_api['keys7']['globalRank'];
$this->user->save();
foreach ($this->user->teams as $team) {
$team->updateTeamRank();
}
}
} catch (\Exception $e) {
$this->user->roles()->create(['role' => UserRoles::Blacklisted]);
}
}
}