You've already forked isop-mirror
refactor: get new possible states from backend instead of computing them on frontend
This commit is contained in:
@@ -31,6 +31,26 @@ class InternshipStatusController extends Controller
|
||||
return response()->json($internship_statuses);
|
||||
}
|
||||
|
||||
public function get_next_states(int $id) {
|
||||
$user = auth()->user();
|
||||
$internship = Internship::find($id);
|
||||
|
||||
if(!$internship) {
|
||||
return response()->json([
|
||||
'message' => 'No such internship exists.'
|
||||
], 400);
|
||||
}
|
||||
|
||||
if ($user->role !== 'ADMIN' && $internship->user_id !== $user->id && $user->id !== $internship->contact) {
|
||||
abort(403, 'Unauthorized');
|
||||
}
|
||||
|
||||
$currentStatus = $this->currentInternshipStatus($internship);
|
||||
$nextPossibleStatuses = $this->possibleNewStatuses($currentStatus->status, $user->role);
|
||||
|
||||
return response()->json($nextPossibleStatuses);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
|
||||
@@ -34,6 +34,7 @@ Route::prefix('/internships')->group(function () {
|
||||
Route::get("/", [InternshipController::class, 'get'])->name("api.internships.get");
|
||||
Route::put("/status", [InternshipStatusController::class, 'update'])->name("api.internships.status.update");
|
||||
Route::get("/statuses", [InternshipStatusController::class, 'get'])->name("api.internships.get");
|
||||
Route::get("/next-statuses", [InternshipStatusController::class, 'get_next_states'])->name("api.internships.status.next.get");
|
||||
Route::post("/basic", [InternshipController::class, 'update_basic'])->name("api.internships.update.basic");
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user