CHANGES-IN-RESTAPI:GWM

This commit is contained in:
bitbucket 2024-03-18 15:14:16 +05:30
parent 1803ec8ac1
commit 409dd470d4
6 changed files with 179 additions and 8 deletions

View File

@ -195,9 +195,12 @@ $routes->cli('processjob', 'JobWorker::processJob');
// $routes->get("/api", "RestAuthenticationController::index");
//Employee login api's
$routes->post("/employeeRest/verifyEmployeeNumber", "RestAuthenticationController::verifyEmployeeWithMobileNumber");
$routes->post("/employeeRest/getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData");
//HR login api's
$routes->post("/employeeRest/verifyHrWithMobileNumber", "RestAuthenticationController::verifyHrWithMobileNumber");
$routes->post("/employeeRest/getVerifiedHrData", "RestAuthenticationController::getVerifiedHrData");
$routes->group("/api", ["filter" => "authJWT"], function($routes){
$routes->post("logined", "RestAuthenticationController::logined");
@ -220,6 +223,9 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){
$routes->post("addEmployeeAndDependence", "EmployeeRestController::addEmployeeAndDependence");
$routes->get("getEmployeePolicy", "EmployeeRestController::getEmployeePolicy");
$routes->post("createOrUpdateEmployeePolicySiAmount", "EmployeeRestController::createOrUpdateEmployeePolicySiAmount");
$routes->get("deleteDependence", "EmployeeRestController::deleteDependence");
$routes->get("getEmployeeAndDependenceByClientId", "EmployeeRestController::getEmployeeAndDependenceByClientId");
});

View File

@ -69,7 +69,7 @@ class EmployeeRestController extends AdminController
} catch (\Throwable $th) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
}
}
}
public function editEmployeeProfile()
@ -185,11 +185,65 @@ class EmployeeRestController extends AdminController
}
public function deleteDependence()
{
try {
$delete = $this->employeeModel->where('id', $this->request->getGet('id'))->delete();
if ($delete) {
return $this->respond(['status' => 'success','code' => 200,'data' =>[] ], 200);
} 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 getEmployeeAndDependenceByClientId()
{
try {
$empData = $this->employeeModel
->where('client_id', $this->request->getGet('client_id'))
->where('relationship', 'self')
->orderBy('id')
->findAll();
$result = [];
foreach ($empData as $employee) {
$employeeDependence = $this->employeeModel
->where('emp_code', $employee['emp_code'])
->where('relationship !=', 'self')
->findAll();
// Use object notation to access properties and set 'dependence'
$employee['dependence'] = $employeeDependence ?: [];
$result[] = $employee;
}
// You probably meant to check $result, not $data
if ($result) {
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} 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 getEmployeePolicy()
{
// $id= 4;
// try {
try {
$id = $this->request->getGet('id');
$keysToRemove = ["removable_keys"];
@ -248,9 +302,40 @@ class EmployeeRestController extends AdminController
}else{
return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404);
}
// } catch (\Exception $e) {
// return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
// }
} catch (\Exception $e) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
}
}
public function createOrUpdateEmployeePolicySiAmount()
{
try {
$requestData = $this->request->getJSON();
$checkIfExist = $this->employeePolicyModel->where('employee_id', $requestData['employee_id'])
->where('client_policy_id', $requestData['client_policy_id'])
->findAll();
// dd($checkIfExist);
if ($checkIfExist) {
$empPolicy = $this->employeePolicyModel->updateSiAndPremium($requestData['client_policy_id'], $requestData['employee_id'], $requestData['basic_cover_si']);
}else{
$data['employee_id']= $requestData['employee_id'];
$data['client_policy_id']= $requestData['client_policy_id'];
$data['basic_cover_si']= $requestData['basic_cover_si'];
$this->employeePolicyModel->insert($data);
}
return $this->respond(['status' => 'success','code' => 200,'data' => []], 200);
} catch (\Exception $e) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
}
}

View File

@ -20,6 +20,7 @@ use CodeIgniter\API\ResponseTrait;
use App\Models\EmployeeModel;
use App\Models\AuthHistoryModel;
use App\Models\LevelContactModel;
use Firebase\JWT\JWT;
// require_once('../vendor/autoload.php');
@ -33,6 +34,7 @@ class RestAuthenticationController extends AdminController
protected $myLogger;
protected $employeeModel;
protected $authHistoryModel;
protected $hrModel;
public function __construct()
@ -42,6 +44,7 @@ class RestAuthenticationController extends AdminController
$this->employeeModel = new EmployeeModel();
$this->authHistoryModel = new AuthHistoryModel();
$this->hrModel = new LevelContactModel();
}
@ -121,6 +124,68 @@ class RestAuthenticationController extends AdminController
}
}
public function verifyHrWithMobileNumber()
{
try {
$mobile_number = $this->request->getJSON()->mobile_number;
$randomNumber = rand(100000, 999999);
$HrData = $this->hrModel->where('mobile', $mobile_number)->where('contact_type', 'client')->first();
if ($HrData) {
$id= $HrData["id"];
$otp = $this->hrModel->where('id', $id)->set('otp', $randomNumber)->update();
$result = ['user_verification' => true , 'otp'=>$randomNumber];
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
} else {
$result = ['user_verification' => false];
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404);
}
} catch (\Throwable $th) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
}
}
public function getVerifiedHrData()
{
try {
$mobile_number = $this->request->getJSON()->mobile_number;
$otp = $this->request->getJSON()->otp;
$hrData = $this->hrModel->where('mobile', $mobile_number)->first();
if ($hrData && $otp == $hrData["otp"]) {
$auth = HttpRequestHelper::getRequestInfo();
if ($auth) {
$data = [
'user_id' => $hrData['id'],
'user_type' => 'hr',
'ip' => $auth['ip'],
'platform' => $auth['platform'],
'broswer' => $auth['browser'],
];
$authdata= $this->authHistoryModel->insert($data);
}
$otp_null = $this->hrModel->where('id', $hrData["id"])->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.mobile', $mobile_number )
->find();
$result = JWTToken::encode($hrData);
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
} else {
return $this->respond(['status' => 'failed','code' => 404,'data' => "No data"],404);
}
} catch (\Exception $e) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500);
}
}
public function employeeLogout()

View File

@ -189,5 +189,18 @@ class EmployeePolicyModel extends Model
->find();
}
public function updateSiAndPremium( $client_policy_id, $employee_id,$basic_cover_si)
{
$query = "UPDATE employee_polices
SET employee_polices.basic_cover_si = '{$basic_cover_si}'
WHERE employee_polices.employee_id = '{$employee_id}'
AND employee_polices.client_policy_id = '{$client_policy_id}'";
$this->query($query);
}
//------------------------------------------------------------------
}

View File

@ -20,6 +20,7 @@ class LevelContactModel extends Model
"designation",
"created_by",
"updated_by",
"otp",
"is_active",
];

View File

@ -3,6 +3,7 @@
namespace App\Models;
use App\Models\PolicyPremium1Model;
use App\Models\PolicyPremium2Model;
use App\Models\PolicyGridModel;
use CodeIgniter\Model;
class PolicesModel extends Model
@ -46,7 +47,7 @@ class PolicesModel extends Model
}
$grid_id = $premium_slab_data[0]['policy_grid_id'];
$policyGridModel = new policyGridModel();
$policyGridModel = new PolicyGridModel();
$results = $policyGridModel->find($grid_id);
return ['slab_rates' => $premium_slab_data,'grid_master' => $results];
}