diff --git a/Modules/Linksehat/Http/Controllers/Api/PersonController.php b/Modules/Linksehat/Http/Controllers/Api/PersonController.php index d64f8d66..28d8abc8 100755 --- a/Modules/Linksehat/Http/Controllers/Api/PersonController.php +++ b/Modules/Linksehat/Http/Controllers/Api/PersonController.php @@ -64,13 +64,15 @@ class PersonController extends Controller 'main_address_id', 'domicile_address_id', ]); + $personData['last_weight_kg'] = $request->weight ?? null; + $personData['last_height_cm'] = $request->height ?? null; $personData = array_merge($personData, [ 'owner_user_id' => auth()->user()->id, ]); $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', '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')) { $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)) { abort(Response::HTTP_FORBIDDEN, 'Tidak bisa update karena bukan pemilik!'); } diff --git a/Modules/Linksehat/Transformers/Person/PersonResource.php b/Modules/Linksehat/Transformers/Person/PersonResource.php index 98fd686e..18acd361 100755 --- a/Modules/Linksehat/Transformers/Person/PersonResource.php +++ b/Modules/Linksehat/Transformers/Person/PersonResource.php @@ -17,21 +17,30 @@ class PersonResource extends JsonResource { return [ 'id' => $this->id, + 'name_prefix' => $this->name_prefix, 'name' => $this->name, + 'name_suffix' => $this->name_suffix, + 'full_name' => $this->full_name, '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, 'email' => $this->email, 'blood_type' => $this->blood_type, - 'weight' => $this->weight, - 'height' => $this->height, + 'weight' => (float) $this->last_weight_kg, + 'height' => (float) $this->last_height_cm, 'relation_with_owner' => ($this->user && $this->user->person_id == $this->id) ? 'Self' : $this->pivot->relation_with_owner ?? null, 'marital_status' => $this->marital_status, 'last_education' => $this->last_education, 'current_employment' => $this->current_employment, 'nik' => $this->nik, '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'), + 'main_address' => $this->current_address, + 'domicile_address' => $this->domicile_address, ]; } } diff --git a/app/Models/Person.php b/app/Models/Person.php index dce3ef27..d95d7cc2 100755 --- a/app/Models/Person.php +++ b/app/Models/Person.php @@ -27,8 +27,8 @@ class Person extends Model 'last_education', 'religion', 'blood_type', - 'weight', - 'height', + 'last_weight_kg', + 'last_height_cm', 'is_deceased', 'deceased_at', 'marital_status', diff --git a/database/migrations/2022_11_15_102019_add_height_weight_to_persons_table.php b/database/migrations/2022_11_15_102019_add_height_weight_to_persons_table.php new file mode 100644 index 00000000..c9cfc9ec --- /dev/null +++ b/database/migrations/2022_11_15_102019_add_height_weight_to_persons_table.php @@ -0,0 +1,34 @@ +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'); + }); + } +};