Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/UsersController.php
Show First 20 Lines • Show All 475 Lines • ▼ Show 20 Lines | protected function userResponse(User $user): array | ||||
$response['aliases'][] = $item->alias; | $response['aliases'][] = $item->alias; | ||||
} | } | ||||
// Status info | // Status info | ||||
$response['statusInfo'] = self::statusInfo($user); | $response['statusInfo'] = self::statusInfo($user); | ||||
$response = array_merge($response, self::userStatuses($user)); | $response = array_merge($response, self::userStatuses($user)); | ||||
// Add discount info to wallet object output | |||||
$map_func = function ($wallet) { | |||||
$result = $wallet->toArray(); | |||||
if ($wallet->discount) { | |||||
$result['discount'] = $wallet->discount->discount; | |||||
$result['discount_description'] = $wallet->discount->description; | |||||
} | |||||
return $result; | |||||
}; | |||||
// Information about wallets and accounts for access checks | // Information about wallets and accounts for access checks | ||||
$response['wallets'] = $user->wallets->toArray(); | $response['wallets'] = $user->wallets->map($map_func)->toArray(); | ||||
$response['accounts'] = $user->accounts->toArray(); | $response['accounts'] = $user->accounts->map($map_func)->toArray(); | ||||
$response['wallet'] = $user->wallet()->toArray(); | $response['wallet'] = $map_func($user->wallet()); | ||||
return $response; | return $response; | ||||
} | } | ||||
/** | /** | ||||
* Prepare user statuses for the UI | * Prepare user statuses for the UI | ||||
* | * | ||||
* @param \App\User $user User object | * @param \App\User $user User object | ||||
▲ Show 20 Lines • Show All 160 Lines • Show Last 20 Lines |