Skip to content

Commit

Permalink
added immunization update
Browse files Browse the repository at this point in the history
  • Loading branch information
CynthiaKamau committed Aug 12, 2021
1 parent 81b9373 commit 9680843
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
34 changes: 34 additions & 0 deletions app/Http/Controllers/API/ImmunizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

}

}
2 changes: 2 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 9680843

Please sign in to comment.