|
@@ -119,13 +119,26 @@ class ApprovalController extends Controller
|
|
|
/**
|
|
|
* Remove the specified resource from storage.
|
|
|
*/
|
|
|
- public function cancel(string $id)
|
|
|
+ public function cancel(Request $request)
|
|
|
{
|
|
|
+ $mode = $request->get("mode", "approval");
|
|
|
+ throw_validation_if(!$request->get("id"), "ID cannot be empty");
|
|
|
+
|
|
|
+ $where = match ($mode) {
|
|
|
+ "approval" => ["id" => $request->id],
|
|
|
+ "object_type" => ["object_type" => $request->object_type, "object_id" => $request->id],
|
|
|
+ default => [],
|
|
|
+ };
|
|
|
+
|
|
|
+ throw_validation_if(! $where, "Please enter valid parameters.");
|
|
|
+
|
|
|
$approval = Approval::query()
|
|
|
->whereIn("status", [
|
|
|
ObjectApprovalStatus::DOING->value,
|
|
|
])
|
|
|
- ->findOrFail($id);
|
|
|
+ ->where($where)
|
|
|
+ ->first();
|
|
|
+ throw_validation_if(! $approval, "The data does not exist or the operation is denied permission.");
|
|
|
|
|
|
$object = ApprovalObjectType::from($approval->object_type)->modelBuilderAllowed($approval->object_id)->findOrFail($approval->object_id);
|
|
|
|