improvement api mobile
This commit is contained in:
@@ -103,6 +103,8 @@ class ProfileController extends Controller
|
||||
'gender' => 'nIDJenisKelamin',
|
||||
'blood_type' => 'nIDGolonganDarah',
|
||||
'marital_status' => 'sMartialStatus',
|
||||
'weight' => 'sWeight',
|
||||
'height' => 'sHeight',
|
||||
];
|
||||
|
||||
// Update user data
|
||||
@@ -113,10 +115,22 @@ class ProfileController extends Controller
|
||||
}
|
||||
|
||||
// Update user detail
|
||||
foreach ($userDetailFields as $requestField => $column) {
|
||||
if ($request->filled($requestField)) {
|
||||
$userDetail->update([$column => $request->$requestField]);
|
||||
if($userDetail){
|
||||
foreach ($userDetailFields as $requestField => $column) {
|
||||
if ($request->filled($requestField)) {
|
||||
$userDetail->update([$column => $request->$requestField]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
UserDetail::create([
|
||||
'nIDUser' => $request->id,
|
||||
'dTanggalLahir' => $request->date_of_birth,
|
||||
'nIDJenisKelamin' => $request->gender,
|
||||
'nIDGolonganDarah' => $request->blood_type,
|
||||
'sMartialStatus' => $request->marital_status,
|
||||
'sWeight' => $request->weight,
|
||||
'sHeight' => $request->height,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,36 +24,47 @@ class ShowProfileResource extends JsonResource
|
||||
{
|
||||
|
||||
// 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;
|
||||
if ($this->detail){
|
||||
switch ($this->detail->nIDGolonganDarah) {
|
||||
case 1:
|
||||
$goldar = 'A';
|
||||
break;
|
||||
case 2:
|
||||
$goldar = 'B';
|
||||
break;
|
||||
case 3:
|
||||
$goldar = 'AB';
|
||||
break;
|
||||
case 4:
|
||||
$goldar = 'O';
|
||||
break;
|
||||
|
||||
default:
|
||||
$goldar = '-';
|
||||
break;
|
||||
}
|
||||
$urlAvatarDefault = $this->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/female-avatar.png';
|
||||
// Marital Status
|
||||
$maritalStatus = DB::connection('oldlms')->table('tm_status_pernikahan')->where('nID', $this->detail->sMartialStatus)->first('sStatusPernikahan');
|
||||
|
||||
// Goldar
|
||||
switch ($this->detail->nIDGolonganDarah) {
|
||||
case 1:
|
||||
$goldar = 'A';
|
||||
break;
|
||||
case 2:
|
||||
$goldar = 'B';
|
||||
break;
|
||||
case 3:
|
||||
$goldar = 'AB';
|
||||
break;
|
||||
case 4:
|
||||
$goldar = 'O';
|
||||
break;
|
||||
|
||||
default:
|
||||
$goldar = '-';
|
||||
break;
|
||||
// Hubungan Keluarga
|
||||
$relationship = DB::connection('oldlms')->table('tm_hubungan_keluarga')->where('nID', $this->nIDHubunganKeluarga)->first('sHubunganKeluarga');
|
||||
// dd( $this->detail->nIDGolonganDarah);
|
||||
$sWeight = $this->detail->sWeight ? $this->detail->sWeight : 0;
|
||||
$sHeight = $this->detail->sHeight ? $this->detail->sHeight : 0;
|
||||
$nIDJenisKelamin = $this->detail->nIDJenisKelamin == 1 ? 'Male' : 'Female';
|
||||
} else {
|
||||
$urlAvatarDefault = 'https://linksehat.dev/assets/img/users/male-avatar.png';
|
||||
$goldar = '-';
|
||||
$relationship = false;
|
||||
$maritalStatus = false;
|
||||
$sWeight = 0;
|
||||
$sHeight = 0;
|
||||
$nIDJenisKelamin = false;
|
||||
}
|
||||
|
||||
// Marital Status
|
||||
$maritalStatus = DB::connection('oldlms')->table('tm_status_pernikahan')->where('nID', $this->detail->sMartialStatus)->first('sStatusPernikahan');
|
||||
|
||||
// Hubungan Keluarga
|
||||
$relationship = DB::connection('oldlms')->table('tm_hubungan_keluarga')->where('nID', $this->nIDHubunganKeluarga)->first('sHubunganKeluarga');
|
||||
// dd( $this->detail->nIDGolonganDarah);
|
||||
|
||||
$avatar = $this->detail->sImage ?? $urlAvatarDefault;
|
||||
|
||||
|
||||
$userInsurance = UserInsurance::where('nIDUser', $this->nID)->get()->first();
|
||||
$memberId = Null;
|
||||
if($userInsurance){
|
||||
@@ -63,16 +74,16 @@ class ShowProfileResource extends JsonResource
|
||||
'id' => $this->nID,
|
||||
'first_name' => $this->sFirstName,
|
||||
'last_name' => $this->sLastName,
|
||||
'date_of_birth' => $this->detail->dTanggalLahir,
|
||||
'date_of_birth' => $this->detail ? $this->detail->dTanggalLahir : null,
|
||||
'avatar' => $avatar,
|
||||
'gender' => $this->detail->nIDJenisKelamin == 1 ? 'Male' : 'Female',
|
||||
'gender' => $nIDJenisKelamin ? $nIDJenisKelamin : '-',
|
||||
'phone' => $this->sPhone,
|
||||
'email' => $this->sEmail,
|
||||
'blood_type' => $goldar,
|
||||
'marital_status' => $maritalStatus ? $maritalStatus->sStatusPernikahan : '-',
|
||||
'relationship' => $relationship ? $relationship->sHubunganKeluarga : '-',
|
||||
'weight' => $this->detail->sWeight,
|
||||
'height' => $this->detail->sHeight,
|
||||
'weight' => $sWeight,
|
||||
'height' => $sHeight,
|
||||
'member_id' => $memberId,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ class UserProfileResource extends JsonResource
|
||||
|
||||
if (count($memberProfile) > 0){
|
||||
|
||||
$urlAvatarDefault = $this->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/male-avatar.png';
|
||||
$urlAvatarDefault = $this->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/female-avatar.png';
|
||||
$avatarMember = $this->detail->sImage ?? $urlAvatarDefault;
|
||||
$relationship = DB::connection('oldlms')->table('tm_hubungan_keluarga')->where('nID', $this->nIDHubunganKeluarga)->first('sHubunganKeluarga');
|
||||
|
||||
@@ -91,7 +91,7 @@ class UserProfileResource extends JsonResource
|
||||
array_push($dataMemberProfile, $dataUser);
|
||||
|
||||
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';
|
||||
$urlAvatarDefault = $m['detail']['nIDJenisKelamin'] == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/female-avatar.png';
|
||||
$avatarMember = $m['detail']['sImage'] ?? $urlAvatarDefault;
|
||||
$relationship = DB::connection('oldlms')->table('tm_hubungan_keluarga')->where('nID', $m['nIDHubunganKeluarga'])->first('sHubunganKeluarga');
|
||||
|
||||
@@ -114,7 +114,7 @@ class UserProfileResource extends JsonResource
|
||||
$dataMember = User::with('detail')->where('nID', $nID)->get()->first();
|
||||
|
||||
if ($this->detail){
|
||||
$urlAvatarDefault = $this->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/male-avatar.png';
|
||||
$urlAvatarDefault = $this->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/female-avatar.png';
|
||||
} else {
|
||||
$urlAvatarDefault = 'https://linksehat.dev/assets/img/users/male-avatar.png';
|
||||
}
|
||||
@@ -126,14 +126,14 @@ class UserProfileResource extends JsonResource
|
||||
$dataUser = [
|
||||
'id' => $dataMember->nID,
|
||||
'name' => $dataMember->sFirstName . ' ' . $dataMember->sLastName,
|
||||
'relationship' => $relationship ? $relationship->sHubunganKeluarga : '-',
|
||||
'relationship' => 'Me',
|
||||
'avatar' => $avatarMember
|
||||
];
|
||||
array_push($dataMemberProfile, $dataUser);
|
||||
|
||||
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';
|
||||
$urlAvatarDefault = $m['detail']['nIDJenisKelamin'] == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/female-avatar.png';
|
||||
$avatarMember = $m['detail']['sImage'] ?? $urlAvatarDefault;
|
||||
$relationship = DB::connection('oldlms')->table('tm_hubungan_keluarga')->where('nID', $m['nIDHubunganKeluarga'])->first('sHubunganKeluarga');
|
||||
|
||||
@@ -154,7 +154,7 @@ class UserProfileResource extends JsonResource
|
||||
|
||||
// Principal
|
||||
if ($this->detail){
|
||||
$urlAvatarDefault = $this->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/male-avatar.png';
|
||||
$urlAvatarDefault = $this->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/female-avatar.png';
|
||||
} else {
|
||||
$urlAvatarDefault = 'https://linksehat.dev/assets/img/users/male-avatar.png';
|
||||
}
|
||||
|
||||
@@ -27,6 +27,9 @@ class UserDetail extends Model
|
||||
'sCreateBy',
|
||||
'sKTP',
|
||||
'sImages',
|
||||
'sWeight',
|
||||
'sHeight',
|
||||
'nIDGolonganDarah',
|
||||
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user