CHANGE_GET_CLIENT_DETAILS_API : RV
This commit is contained in:
parent
7ccb23434d
commit
ef4271b1c7
@ -1713,22 +1713,127 @@ class EmployeeRestController extends AdminController
|
||||
|
||||
}
|
||||
|
||||
// public function getClientDetails()
|
||||
// {
|
||||
// try {
|
||||
|
||||
// $jwt = $this->request->getHeaderLine('Authorization');
|
||||
// $jwtParts = explode(' ', $jwt);
|
||||
// $token = $jwtParts[1];
|
||||
// $decodedPayload = json_decode(base64_decode(explode('.', $token)[1]), true);
|
||||
// $token_type = $decodedPayload['token_type'];
|
||||
|
||||
// if ($token_type == 'pre') {
|
||||
// $client = $this->clientModel->where('id', $this->request->getGet('client_id'))->first();
|
||||
// if ($client) {
|
||||
// $client['client_logo'] = base_url() . 'public/uploads/logo/' . $client['client_logo'];
|
||||
// $clientPolicy = $this->clientPolicyModel->where('client_id', $this->request->getGet('client_id'))
|
||||
// ->where('client_branch_id', $this->request->getGet('client_branch_id'))->findAll();
|
||||
// return $this->respond(['status' => 'success', 'code' => 200, 'data' => ['client' => $client, 'client_policy' => $clientPolicy]], 200);
|
||||
// } else if ($token_type == 'post') {
|
||||
|
||||
// $restAuthController = new RestAuthenticationController;
|
||||
|
||||
// //call and get Client Details data from post enrollment
|
||||
// $queryParams = [
|
||||
// 'client_id' => $this->request->getGet('client_id'),
|
||||
// 'client_branch_id' => $this->request->getGet('client_branch_id')
|
||||
// ];
|
||||
|
||||
// return $restAuthController->callThirdPartyGETAPI($queryParams, 'getClientDetails');
|
||||
// } else {
|
||||
// return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404);
|
||||
// }
|
||||
// } else {
|
||||
// return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404);
|
||||
// }
|
||||
// } catch (\Exception $e) {
|
||||
// return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
// }
|
||||
// }
|
||||
|
||||
public function getClientDetails()
|
||||
{
|
||||
{
|
||||
log_message('error', 'STEP 1: getClientDetails called');
|
||||
|
||||
try {
|
||||
// STEP 2: Extract Authorization header
|
||||
$jwt = $this->request->getHeaderLine('Authorization');
|
||||
log_message('error', 'STEP 2: Authorization header: ' . $jwt);
|
||||
|
||||
$client = $this->clientModel->where('id',$this->request->getGet('client_id'))->first();
|
||||
if($client) {
|
||||
$client['client_logo'] = base_url().'public/uploads/logo/'.$client['client_logo'];
|
||||
$clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id'))
|
||||
->where('client_branch_id',$this->request->getGet('client_branch_id'))->findAll();
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => ['client'=>$client,'client_policy'=>$clientPolicy]], 200);
|
||||
$jwtParts = explode(' ', $jwt);
|
||||
if (count($jwtParts) < 2) {
|
||||
log_message('error', 'STEP 2.1: Invalid Authorization header format');
|
||||
return $this->respond(['status' => 'failed', 'code' => 400, 'data' => 'Invalid Authorization header'], 400);
|
||||
}
|
||||
|
||||
}else{
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404);
|
||||
$token = $jwtParts[1];
|
||||
log_message('error', 'STEP 3: Extracted JWT token');
|
||||
|
||||
$tokenParts = explode('.', $token);
|
||||
if (count($tokenParts) !== 3) {
|
||||
log_message('error', 'STEP 3.1: Invalid JWT structure');
|
||||
return $this->respond(['status' => 'failed', 'code' => 400, 'data' => 'Invalid JWT token'], 400);
|
||||
}
|
||||
|
||||
$decodedPayload = json_decode(base64_decode($tokenParts[1]), true);
|
||||
log_message('error', 'STEP 4: Decoded JWT payload: ' . json_encode($decodedPayload));
|
||||
|
||||
$token_type = $decodedPayload['token_type'] ?? null;
|
||||
log_message('error', 'STEP 5: Token type = ' . $token_type);
|
||||
|
||||
$client_id = $this->request->getGet('client_id');
|
||||
$client_branch_id = $this->request->getGet('client_branch_id');
|
||||
log_message('error', 'STEP 6: Query params - client_id: ' . $client_id . ', client_branch_id: ' . $client_branch_id);
|
||||
|
||||
if ($token_type === 'pre') {
|
||||
log_message('error', 'STEP 7: Handling "pre" token type');
|
||||
|
||||
$client = $this->clientModel->where('id', $client_id)->first();
|
||||
if ($client) {
|
||||
log_message('error', 'STEP 8: Found client: ' . json_encode($client));
|
||||
|
||||
$client['client_logo'] = base_url() . 'public/uploads/logo/' . $client['client_logo'];
|
||||
|
||||
$clientPolicy = $this->clientPolicyModel
|
||||
->where('client_id', $client_id)
|
||||
->where('client_branch_id', $client_branch_id)
|
||||
->findAll();
|
||||
|
||||
log_message('error', 'STEP 9: Found client policy count: ' . count($clientPolicy));
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'data' => [
|
||||
'client' => $client,
|
||||
'client_policy' => $clientPolicy
|
||||
]
|
||||
], 200);
|
||||
} else {
|
||||
log_message('error', 'STEP 10: No client found for client_id: ' . $client_id);
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404);
|
||||
}
|
||||
} elseif ($token_type === 'post') {
|
||||
log_message('error', 'STEP 11: Handling "post" token type');
|
||||
|
||||
$restAuthController = new RestAuthenticationController;
|
||||
|
||||
$queryParams = [
|
||||
'client_id' => $client_id,
|
||||
'client_branch_id' => $client_branch_id
|
||||
];
|
||||
|
||||
log_message('error', 'STEP 12: Calling post enrollment API with params: ' . json_encode($queryParams));
|
||||
|
||||
return $restAuthController->callThirdPartyGETAPI($queryParams, 'getClientDetails');
|
||||
} else {
|
||||
log_message('error', 'STEP 13: Unknown token_type: ' . $token_type);
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
|
||||
log_message('error', 'STEP 14: Exception occurred - ' . $e->getMessage());
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user