GWM : hr auth token api

This commit is contained in:
Gowtham M 2025-10-06 14:47:02 +05:30
parent 417f77693b
commit 540ce84162

View File

@ -590,38 +590,71 @@ class RestAuthenticationController extends AdminController
if(isset($this->request->getJSON()->mobile_no)){
$hrData = $this->hrModel ->select('level_contacts.* , client_branch.client_id as client_id')
$getAllhrData = $this->hrModel->select('level_contacts.id ,level_contacts.mobile , level_contacts.email , clients.id as client_id, clients.client_name, clients.short_name , client_branch.id as client_branch_id,client_branch.branch_name , client_branch.post_branch_id')
->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left')
->join('clients', 'client_branch.client_id = clients.id', 'left')
->where('level_contacts.mobile', $mobile_number )
->where('level_contacts.contact_type', 'client')
->find();
->findAll();
}else if(isset($this->request->getJSON()->otp)){
$this->hrModel->where('email', $email)->where('otp', $otp)->where('contact_type', 'client')->set(['otp'=>null])->update();
$hrData = $this->hrModel ->select('level_contacts.* , client_branch.client_id as client_id')
->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left')
->where('level_contacts.email', $email )
->where('level_contacts.contact_type', 'client')
->find();
$getAllhrData = $this->hrModel->select('level_contacts.id ,level_contacts.mobile , level_contacts.email , clients.id as client_id, clients.client_name, clients.short_name , client_branch.id as client_branch_id,client_branch.branch_name , client_branch.post_branch_id')
->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left')
->join('clients', 'client_branch.client_id = clients.id', 'left')
->where('level_contacts.email', $email )
->where('level_contacts.contact_type', 'client')
->findAll();
}
if(count($getAllhrData))
{
$db2 = \Config\Database::connect('postDB');
foreach ($getAllhrData as $key => $value) {
$HRAccessData = $db2->table('hr_access_control hr')
->where('hr.pre_client_id',$value['client_id'])
->where('hr.pre_branch_id', $value['client_branch_id'])
->where('hr.pre_hr_id', $value['id'])
->get()->getRowArray();
if (!empty($HRAccessData) && isset($HRAccessData['allowed_modules'])) {
$decoded = json_decode($HRAccessData['allowed_modules'], true);
$getAllhrData[$key]['allowed_modules'] = $decoded;
$token = JWTToken::encode($HRAccessData);
$getAllhrData[$key]['token'] = $token;
} else {
$getAllhrData[$key]['allowed_modules'] = [];
$getAllhrData[$key]['token'] = "";
}
}
}
//call and get allowed module data from post enrollment
$queryParams = [
'hr_id' => $hrData['0']['id'],
'request_for' => 'pre_enrollment'
];
$HRAccessRes = $this->callThirdPartyGETAPI($queryParams,'getHRAccessData');
$HRAccessData = json_decode($HRAccessRes,true);
if(isset($HRAccessData['data']['allowed_modules'])){ $hrData['0']['allowed_modules'] = json_decode($HRAccessData['data']['allowed_modules'],true)['pre']; }else{ $hrData['0']['allowed_modules'] = []; }
$hrData['0']['token_type'] = 'pre';
$result = JWTToken::encode($hrData['0']);
// Call the third-party API function
$apiResponse = $this->callThirdPartyAPI($this->request->getJSON(),'getVerifiedHrData');
return $this->respond(['status' => 'success','code' => 200,'data' => $result , 'post_enrollment'=> json_decode($apiResponse, true)],200);
return $this->respond(['status' => 'success','code' => 200,'data' => $getAllhrData , 'post_enrollment'=> json_decode($apiResponse, true)],200);
//call and get allowed module data from post enrollment
// $queryParams = [
// 'hr_id' => $hrData['0']['id'],
// 'request_for' => 'pre_enrollment'
// ];
// $HRAccessRes = $this->callThirdPartyGETAPI($queryParams,'getHRAccessData');
// $HRAccessData = json_decode($HRAccessRes,true);
// if(isset($HRAccessData['data']['allowed_modules'])){ $hrData['0']['allowed_modules'] = json_decode($HRAccessData['data']['allowed_modules'],true)['pre']; }else{ $hrData['0']['allowed_modules'] = []; }
// $hrData['0']['token_type'] = 'pre';
// $result = JWTToken::encode($hrData['0']);
// // Call the third-party API function
// $apiResponse = $this->callThirdPartyAPI($this->request->getJSON(),'getVerifiedHrData');
// return $this->respond(['status' => 'success','code' => 200,'data' => $result , 'post_enrollment'=> json_decode($apiResponse, true)],200);
} else {