Fix Person
This commit is contained in:
@@ -64,13 +64,15 @@ class PersonController extends Controller
|
|||||||
'main_address_id',
|
'main_address_id',
|
||||||
'domicile_address_id',
|
'domicile_address_id',
|
||||||
]);
|
]);
|
||||||
|
$personData['last_weight_kg'] = $request->weight ?? null;
|
||||||
|
$personData['last_height_cm'] = $request->height ?? null;
|
||||||
$personData = array_merge($personData, [
|
$personData = array_merge($personData, [
|
||||||
'owner_user_id' => auth()->user()->id,
|
'owner_user_id' => auth()->user()->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$personModel = Person::query()->create($personData);
|
$personModel = Person::query()->create($personData);
|
||||||
|
|
||||||
return Helper::responseJson(['persons' => $personModel], Response::HTTP_CREATED, 'Data berhasil di buat');
|
return Helper::responseJson(['persons' => new PersonResource($personModel)], Response::HTTP_CREATED, 'Data berhasil di buat');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,8 +116,11 @@ class PersonController extends Controller
|
|||||||
'main_address_id',
|
'main_address_id',
|
||||||
'domicile_address_id',
|
'domicile_address_id',
|
||||||
]);
|
]);
|
||||||
|
$personData['last_weight_kg'] = $request->weight ?? null;
|
||||||
|
$personData['last_height_cm'] = $request->height ?? null;
|
||||||
|
|
||||||
$family->update($personData);
|
$family->fill($personData);
|
||||||
|
$family->save();
|
||||||
|
|
||||||
if ($request->hasFile('user_avatar')) {
|
if ($request->hasFile('user_avatar')) {
|
||||||
$pathFileAvatar = File::storeFile('avatar', $family->id, $request->file('user_avatar'));
|
$pathFileAvatar = File::storeFile('avatar', $family->id, $request->file('user_avatar'));
|
||||||
@@ -154,7 +159,7 @@ class PersonController extends Controller
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Helper::responseJson(data: ['persons' => $family], message: 'Data Berhasil di update');
|
return Helper::responseJson(data: ['persons' => PersonResource::make($family)], message: 'Data Berhasil di update');
|
||||||
} elseif (Gate::forUser(auth()->user())->denies('update-person', $family)) {
|
} elseif (Gate::forUser(auth()->user())->denies('update-person', $family)) {
|
||||||
abort(Response::HTTP_FORBIDDEN, 'Tidak bisa update karena bukan pemilik!');
|
abort(Response::HTTP_FORBIDDEN, 'Tidak bisa update karena bukan pemilik!');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,21 +17,30 @@ class PersonResource extends JsonResource
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
|
'name_prefix' => $this->name_prefix,
|
||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
|
'name_suffix' => $this->name_suffix,
|
||||||
|
'full_name' => $this->full_name,
|
||||||
'birth_place' => $this->birth_place,
|
'birth_place' => $this->birth_place,
|
||||||
'gender' => $this->gender,
|
'birth_date' => $this->birth_date,
|
||||||
|
'gender' => !empty($this->gender) ? ($this->gender == 'M' ? 'P' : 'W') : null, // For App
|
||||||
|
'citizenship' => $this->citizenship,
|
||||||
'phone' => $this->phone,
|
'phone' => $this->phone,
|
||||||
'email' => $this->email,
|
'email' => $this->email,
|
||||||
'blood_type' => $this->blood_type,
|
'blood_type' => $this->blood_type,
|
||||||
'weight' => $this->weight,
|
'weight' => (float) $this->last_weight_kg,
|
||||||
'height' => $this->height,
|
'height' => (float) $this->last_height_cm,
|
||||||
'relation_with_owner' => ($this->user && $this->user->person_id == $this->id) ? 'Self' : $this->pivot->relation_with_owner ?? null,
|
'relation_with_owner' => ($this->user && $this->user->person_id == $this->id) ? 'Self' : $this->pivot->relation_with_owner ?? null,
|
||||||
'marital_status' => $this->marital_status,
|
'marital_status' => $this->marital_status,
|
||||||
'last_education' => $this->last_education,
|
'last_education' => $this->last_education,
|
||||||
'current_employment' => $this->current_employment,
|
'current_employment' => $this->current_employment,
|
||||||
'nik' => $this->nik,
|
'nik' => $this->nik,
|
||||||
'religion' => $this->religion,
|
'religion' => $this->religion,
|
||||||
|
'is_deceased' => $this->is_deceased == 1,
|
||||||
|
'deceased_at' => $this->deceased_at,
|
||||||
'avatar_url' => $this->avatar->url ?? asset('images/default-doctor-avatar.png'),
|
'avatar_url' => $this->avatar->url ?? asset('images/default-doctor-avatar.png'),
|
||||||
|
'main_address' => $this->current_address,
|
||||||
|
'domicile_address' => $this->domicile_address,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ class Person extends Model
|
|||||||
'last_education',
|
'last_education',
|
||||||
'religion',
|
'religion',
|
||||||
'blood_type',
|
'blood_type',
|
||||||
'weight',
|
'last_weight_kg',
|
||||||
'height',
|
'last_height_cm',
|
||||||
'is_deceased',
|
'is_deceased',
|
||||||
'deceased_at',
|
'deceased_at',
|
||||||
'marital_status',
|
'marital_status',
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('persons', function (Blueprint $table) {
|
||||||
|
$table->float('last_weight_kg', 5, 2, true)->nullable()->after('blood_type');
|
||||||
|
$table->float('last_height_cm', 5, 2, true)->nullable()->after('blood_type');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('persons', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('last_weight_kg');
|
||||||
|
$table->dropColumn('last_height_cm');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user