update api user dan export alamr center client

This commit is contained in:
2023-11-06 13:19:05 +07:00
parent 23886c52d2
commit 4aa6eaa889
26 changed files with 585 additions and 227 deletions

View File

@@ -3,6 +3,10 @@
namespace Modules\Linksehat\Transformers;
use Illuminate\Http\Resources\Json\JsonResource;
use App\Models\OLDLMS\User;
use App\Models\OLDLMS\UserDetail;
use DB;
class UserProfileResource extends JsonResource
{
@@ -12,25 +16,44 @@ class UserProfileResource extends JsonResource
* @param \Illuminate\Http\Request
* @return array
*/
protected $connection = 'oldlms';
public function toArray($request)
{
$memberProfile = User::with('detail')->where('nIDUser', $this->nID)->get()->toArray();
$dataMemberProfile = [];
if (count($memberProfile) > 0){
foreach($memberProfile as $m){
$urlAvatarDefault = $m['detail']['nIDJenisKelamin'] == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/male-avatar.png';
$avatarMember = $m['detail']['sImage'] ?? $urlAvatarDefault;
$relationship = DB::connection('oldlms')->table('tm_hubungan_keluarga')->where('nID', $m['nIDHubunganKeluarga'])->first('sHubunganKeluarga');
$data = [
'id' => $m['nID'],
'name' => $m['full_name'],
'relationship' => $relationship->sHubunganKeluarga,
'avatar' => $avatarMember,
];
array_push( $dataMemberProfile, $data);
}
}
// Principal
$urlAvatarDefault = $this->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/male-avatar.png';
$avatar = $this->detail->sImage ?? $urlAvatarDefault;
return [
'id' => $this->id,
'email' => $this->email,
'phone' => $this->phone,
'email_verified_at' => $this->email_verified_at,
'nik' => $this->person->nik ?? null,
'name_prefix' => $this->person->name_prefix ?? null,
'name' => $this->person->name ?? null,
'name_suffix' => $this->person->name_suffix ?? null,
'full_name' => $this->person->full_name ?? null,
'gender' => $this->person->gender ?? null,
'birth_date' => $this->person->birth_date ?? null,
'age' => $this->person->age ?? null,
'is_deceased' => $this->person->is_deceased ?? null,
'deceased_at' => $this->person->deceased_at ?? null,
'marital_status' => $this->person->marital_status ?? null,
'preferred_lang' => $this->meta->preferred_lang ?? 'id',
'id' => $this->nID,
'full_name' => $this->sFirstName . ' '. $this->sLastName,
'avatar' => $avatar,
'member_type' => $this->nIDUser ? 'Dependent' : 'Principal',
'member_profile' => $dataMemberProfile,
];
}
}