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!');
}
}
/**