update appointment

This commit is contained in:
Muhammad Fajar
2022-11-08 10:34:32 +07:00
parent f0bf98b153
commit 0b71987a8a
5 changed files with 7618 additions and 24968 deletions

View File

@@ -4,11 +4,13 @@ namespace Modules\Linksehat\Http\Controllers\Api;
use App\Helpers\Helper;
use App\Models\Appointment;
use App\Models\AppointmentParticipant;
use App\Models\Person;
use App\Models\PractitionerRole;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Gate;
use Modules\Linksehat\Transformers\Appointment\AppointmentDetailResource;
use Symfony\Component\HttpFoundation\Response;
@@ -79,9 +81,33 @@ class AppointmentController extends Controller
* @param int $id
* @return Renderable
*/
public function update(Request $request, $id)
public function update(Request $request, Appointment $appointment)
{
//
$idPatient = AppointmentParticipant::query()->where('appointment_id', $appointment->id)->where('participantable_type', Person::class)->first();
$patient = Person::query()->select(['owner_user_id'])->find($idPatient->participantable_id);
if (Gate::forUser(auth()->user())->allows('update-appointment', $patient)) {
$appointmentData = [
'start_time' => $request->date . ' ' . $request->time
];
$appointment->update($appointmentData);
$appointment->appointmentParticipants()->updateOrCreate(
[
'appointment_id' => $appointment->id,
'type' => 'patient',
'participantable_type' => Person::class,
],
[
'participantable_id' => $request->patient_id,
]
);
return Helper::responseJson(data: $appointment->with(['appointmentParticipants'])->get(), message: 'Data berhasil di update');
} elseif (Gate::forUser(auth()->user())->denies('update-appointment', $patient)) {
abort(Response::HTTP_FORBIDDEN, 'Tidak bisa update karena bukan pemilik!');
}
}
/**

View File

@@ -28,5 +28,9 @@ class AuthServiceProvider extends ServiceProvider
Gate::define('update-person', function ($user, $person) {
return $user->id == $person->owner_user_id;
});
Gate::define('update-appointment', function ($user, $patient) {
return $user->id == $patient->owner_user_id;
});
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -50,6 +50,7 @@
"@mui/x-data-grid": "^5.16.0",
"@mui/x-date-pickers": "5.0.0-beta.2",
"@vitejs/plugin-react": "^1.3.2",
"apexcharts": "^3.36.3",
"axios": "^0.27.2",
"change-case": "^4.1.2",
"csstype": "^3.1.0",
@@ -63,6 +64,7 @@
"nprogress": "^0.2.0",
"numeral": "^2.0.6",
"react": "^17.0.2",
"react-apexcharts": "^1.4.0",
"react-dom": "^17.0.2",
"react-dropzone": "^14.2.2",
"react-helmet-async": "^1.3.0",

File diff suppressed because it is too large Load Diff