update appointment
This commit is contained in:
@@ -4,11 +4,13 @@ namespace Modules\Linksehat\Http\Controllers\Api;
|
|||||||
|
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
use App\Models\Appointment;
|
use App\Models\Appointment;
|
||||||
|
use App\Models\AppointmentParticipant;
|
||||||
use App\Models\Person;
|
use App\Models\Person;
|
||||||
use App\Models\PractitionerRole;
|
use App\Models\PractitionerRole;
|
||||||
use Illuminate\Contracts\Support\Renderable;
|
use Illuminate\Contracts\Support\Renderable;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Routing\Controller;
|
use Illuminate\Routing\Controller;
|
||||||
|
use Illuminate\Support\Facades\Gate;
|
||||||
use Modules\Linksehat\Transformers\Appointment\AppointmentDetailResource;
|
use Modules\Linksehat\Transformers\Appointment\AppointmentDetailResource;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
@@ -79,9 +81,33 @@ class AppointmentController extends Controller
|
|||||||
* @param int $id
|
* @param int $id
|
||||||
* @return Renderable
|
* @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!');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -28,5 +28,9 @@ class AuthServiceProvider extends ServiceProvider
|
|||||||
Gate::define('update-person', function ($user, $person) {
|
Gate::define('update-person', function ($user, $person) {
|
||||||
return $user->id == $person->owner_user_id;
|
return $user->id == $person->owner_user_id;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Gate::define('update-appointment', function ($user, $patient) {
|
||||||
|
return $user->id == $patient->owner_user_id;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
25081
frontend/client-portal/package-lock.json
generated
25081
frontend/client-portal/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -50,6 +50,7 @@
|
|||||||
"@mui/x-data-grid": "^5.16.0",
|
"@mui/x-data-grid": "^5.16.0",
|
||||||
"@mui/x-date-pickers": "5.0.0-beta.2",
|
"@mui/x-date-pickers": "5.0.0-beta.2",
|
||||||
"@vitejs/plugin-react": "^1.3.2",
|
"@vitejs/plugin-react": "^1.3.2",
|
||||||
|
"apexcharts": "^3.36.3",
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
"change-case": "^4.1.2",
|
"change-case": "^4.1.2",
|
||||||
"csstype": "^3.1.0",
|
"csstype": "^3.1.0",
|
||||||
@@ -63,6 +64,7 @@
|
|||||||
"nprogress": "^0.2.0",
|
"nprogress": "^0.2.0",
|
||||||
"numeral": "^2.0.6",
|
"numeral": "^2.0.6",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
|
"react-apexcharts": "^1.4.0",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
"react-dropzone": "^14.2.2",
|
"react-dropzone": "^14.2.2",
|
||||||
"react-helmet-async": "^1.3.0",
|
"react-helmet-async": "^1.3.0",
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user