diff --git a/app/Http/Controllers/API/ImmunizationController.php b/app/Http/Controllers/API/ImmunizationController.php index 2cb58c9..6db51dc 100644 --- a/app/Http/Controllers/API/ImmunizationController.php +++ b/app/Http/Controllers/API/ImmunizationController.php @@ -9,6 +9,7 @@ use App\Immunization; use Illuminate\Http\Request; use App\Http\Controllers\Controller; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; class ImmunizationController extends Controller @@ -120,4 +121,37 @@ public function new_immunization(Request $request) } + + public function update_immunization(Request $request) + { + $request->validate([ + 'disease_id' => 'required|numeric|exists:diseases,id', + 'date' => 'required', + ],[ + 'disease_id.required' => 'Please select a disease' + ]); + + $disease = Immunization::where('user_id', $request->user_id)->where('disease_id', $request->disease_id )->first(); + + if(is_null($disease)) + abort(404, "Immunization disease not found"); + + DB::transaction(function () use ($request, $disease) { + $disease->user_id = \auth()->user()->id; + $disease->disease_id = $request->disease_id; + $disease->date = $request->date; + $disease->next_immunization_date = $request->next_immunization_date; + $disease->update(); + + Log::info("Immunization updated succesfully"); + + }); + + return response()->json([ + 'success' => true, + 'message' => 'Immunization updated succesfully' + ], 201); + + } + } diff --git a/routes/api.php b/routes/api.php index a03f452..d43eb33 100644 --- a/routes/api.php +++ b/routes/api.php @@ -67,6 +67,8 @@ Route::get('immunizations/all', 'ImmunizationController@all_immunizations'); Route::get('immunizations/all/disease/{id}', 'ImmunizationController@all_immunizations_by_disease'); Route::post('immunizations/new', 'ImmunizationController@new_immunization'); + Route::post('immunizations/update', 'ImmunizationController@update_immunization'); + //exposures Route::get('exposures', 'ExposureController@exposures');