validation : GWM
This commit is contained in:
parent
965ff4db48
commit
51648ee9f3
@ -116,6 +116,7 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) {
|
||||
$routes->get('policy/downloadPolicyFile', 'PolicyController::downloadPolicyFile');
|
||||
$routes->post('policy/uploadPolicyFile', 'PolicyController::uploadPolicyFile');
|
||||
$routes->get("policy/searchThePolicies", "PolicyController::searchThePolicies");
|
||||
$routes->get("policy/PolicyFilePath", "PolicyController::PolicyFilePath");
|
||||
|
||||
//claims
|
||||
$routes->get('claim/ClaimList', 'ClaimController::ClaimList');
|
||||
|
||||
@ -406,6 +406,51 @@ class PolicyController extends ResourceController
|
||||
}
|
||||
}
|
||||
|
||||
public function PolicyFilePath()
|
||||
{
|
||||
try {
|
||||
$policyId = $this->request->getGet('policy_id');
|
||||
$fileType = $this->request->getGet('file_type'); // policy_pdf , policy_payment_receipt
|
||||
|
||||
if (!$policyId || !$fileType) {
|
||||
return $this->respond(['status' => 'failed','code' => 400,'data' => 'policy_id and file_type are required'], 200);
|
||||
}
|
||||
|
||||
// Map file_type to DB column and folder
|
||||
$fileMap = [
|
||||
'policy_pdf' => ['column' => 'policy_pdf_file_name', 'folder' => 'policy_pdf'],
|
||||
'policy_payment_receipt'=> ['column' => 'policy_payment_receipt_file_name', 'folder' => 'policy_payment_receipt'],
|
||||
];
|
||||
|
||||
if (!array_key_exists($fileType, $fileMap)) {
|
||||
return $this->respond(['status' => 'failed','code' => 400,'data' => 'Invalid file_type'], 200);
|
||||
}
|
||||
|
||||
$fileColumn = $fileMap[$fileType]['column'];
|
||||
$folder = $fileMap[$fileType]['folder'];
|
||||
|
||||
// Fetch record from DB
|
||||
$fileRecord = $this->PolicyModel->where('is_active', 1)->find($policyId);
|
||||
|
||||
if (!$fileRecord || empty($fileRecord[$fileColumn])) {
|
||||
return $this->respond([ 'status' => 'failed','code' => 404,'data' => 'File not found in database'], 200);
|
||||
}
|
||||
|
||||
$filePath = WRITEPATH . "uploads/policy/{$folder}/" . $fileRecord[$fileColumn];
|
||||
|
||||
if (!file_exists($filePath)) {
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => 'File missing on server'], 200);
|
||||
}
|
||||
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $filePath ], 200);
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'message' => $e->getMessage() ], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function readFileAndCalculateCommission(array $data)
|
||||
{
|
||||
$policyId = $data['policy_id'];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user