From c751a82c19e13dd2b09f8c897e5247424bac01e0 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Tue, 2 Jun 2026 12:39:38 +0530 Subject: [PATCH] GWM : claim delete api --- app/Config/Routes.php | 1 + app/Controllers/ClaimController.php | 57 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 0417071..154c81f 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -150,6 +150,7 @@ $routes->group('api', ['filter' => ["jwtAuth:1,2,3,4,agent","appSignature"] ], f $routes->get('claim/ClaimList', 'ClaimController::ClaimList'); $routes->get('claim/getClaimById', 'ClaimController::getClaimById'); $routes->get('claim/downloadClaimFile', 'ClaimController::downloadClaimFile'); + $routes->get('claim/deleteClaim', 'ClaimController::deleteClaim'); $routes->post('claim/createClaim', 'ClaimController::createClaim'); $routes->post('claim/updateClaim', 'ClaimController::updateClaim'); diff --git a/app/Controllers/ClaimController.php b/app/Controllers/ClaimController.php index 77b260f..4898dfa 100644 --- a/app/Controllers/ClaimController.php +++ b/app/Controllers/ClaimController.php @@ -351,6 +351,63 @@ class ClaimController extends ResourceController } } + /** + * Soft delete claim by id (sets is_active = 0). + * Also soft deletes related claim files. + */ + public function deleteClaim() + { + try { + $claimId = $this->request->getGet('id'); + + if (empty($claimId)) { + return $this->respond(['status' => 'failed', 'code' => 400, 'data' => 'id is required'], 400); + } + + $claim = $this->ClaimModel + ->where('id', (int) $claimId) + ->where('is_active', 1) + ->first(); + + if (!$claim) { + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => 'Claim not found'], 404); + } + + $updatedBy = $this->request->getGet('updated_by'); + + $this->db->transStart(); + + $this->ClaimModel->update((int) $claimId, [ + 'is_active' => 0, + 'updated_by' => $updatedBy ?? null, + ]); + + $this->ClaimFilesModel + ->where('claim_id', (int) $claimId) + ->where('is_active', 1) + ->set([ + 'is_active' => 0, + 'updated_by' => $updatedBy ?? null, + ]) + ->update(); + + if ($this->db->transStatus() === false) { + $this->db->transRollback(); + return $this->respond(['status' => 'failed', 'code' => 500, 'data' => 'Failed to delete claim'], 500); + } + + $this->db->transComplete(); + + return $this->respond([ + 'status' => 'success', + 'code' => 200, + 'data' => 'Claim deleted successfully', + ], 200); + } catch (\Exception $e) { + return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500); + } + } + /** * Fetch a single claim by primary id with related lookups and file preview URLs. * Used to populate the edit form when the user clicks the edit button on a row.