|
@@ -20,6 +20,7 @@ use App\Models\Enums\ObjectApprovalStatus;
|
|
|
use App\Repositories\ActionRepository;
|
|
|
use App\Services\Approval\ActionService;
|
|
|
use App\Services\Approval\StoreService;
|
|
|
+use Illuminate\Database\Eloquent\Builder;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
@@ -30,7 +31,15 @@ class ApprovalController extends Controller
|
|
|
*/
|
|
|
public function index(Request $request)
|
|
|
{
|
|
|
- $approvals = Approval::with(['createdBy'])->filter($request->all())->orderByDesc("created_at")->paginate();
|
|
|
+ $query = Approval::with(['createdBy']);
|
|
|
+
|
|
|
+ match ($request->get("tab")) {
|
|
|
+ 'wait_for_me' => $query->allowed(true),
|
|
|
+ 'pr' => $query->where("created_by", Auth::id()),
|
|
|
+ default => $query->allowed(),
|
|
|
+ };
|
|
|
+
|
|
|
+ $approvals = $query->filter($request->all())->orderByDesc("created_at")->paginate();
|
|
|
|
|
|
return new ApprovalCollection($approvals);
|
|
|
}
|
|
@@ -52,7 +61,7 @@ class ApprovalController extends Controller
|
|
|
{
|
|
|
$approval = Approval::query()
|
|
|
->where("id", $id)
|
|
|
- ->where(fn($query) => $query->where("users", 'like', '%,'.Auth::id().',%')->orWhere("created_by", Auth::id()))
|
|
|
+ ->allowed()
|
|
|
->firstOrFail();
|
|
|
|
|
|
$approvalObjectType = ApprovalObjectType::from($approval->object_type);
|
|
@@ -88,7 +97,7 @@ class ApprovalController extends Controller
|
|
|
public function action(ActionRequest $request, string $id, ActionService $actionService)
|
|
|
{
|
|
|
$approval = Approval::query()
|
|
|
- ->where("users", 'like', '%,'.Auth::id().',%')
|
|
|
+ ->allowed(true)
|
|
|
->whereIn("status", [
|
|
|
ObjectApprovalStatus::DOING->value,
|
|
|
])
|