From 5dec08dba85cdfcc74d95b303a9f74549c60f460 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Thu, 27 Nov 2025 12:41:54 +0530 Subject: [PATCH] FIX_GET_VERIFIED_USER_DATA_OTP_EMPTY_HANDLE --- .../RestAuthenticationController.php | 77 ++++++++++--------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 761ceffa..8bd9962b 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -398,47 +398,54 @@ class RestAuthenticationController extends AdminController $otp = isset($this->request->getJSON()->otp) ? $this->request->getJSON()->otp : null; $client_id = $this->request->getJSON()->client_id ?? null; - if (isset($mobile_number)) - { - // $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first(); - $builder = $this->employeeModel - ->select('employees.*') - ->join('employee_polices', 'employees.id = employee_polices.employee_id') - ->where('employees.mobile', $mobile_number) - ->where('employees.relationship', 'Self') - ->where('employee_polices.is_active', 1) - ->whereIn('employee_polices.status', ['active', 'expired']) - ->where('employees.is_active', 1) - ->whereIn('employees.emp_status', ['active', 'expired']) - ->where('otp', $otp); + if(empty($otp)){ + return $this->respond(['status' => 'failed','code' => 400,'message' => 'OTP is required'], 200); + } - if (!empty($client_id)) { - $builder->where('employees.client_id', $client_id); - } + if (empty($mobile_number) && empty($email_id)) { + return $this->respond(['status' => 'failed','code' => 400,'message' => 'Mobile number or Email ID is required'], 200); + } - $employeeData = $builder->orderBy('employees.id', 'desc')->first(); + if (isset($mobile_number)) + { + // $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first(); + $builder = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.mobile', $mobile_number) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['active', 'expired']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active', 'expired']) + ->where('otp', $otp); - } else { - // $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('otp', $otp)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first(); - $builder = $this->employeeModel - ->select('employees.*') - ->join('employee_polices', 'employees.id = employee_polices.employee_id') - ->where('employees.email_corporate', $email_id) - ->where('employees.relationship', 'Self') - ->where('employee_polices.is_active', 1) - ->whereIn('employee_polices.status', ['active', 'expired']) - ->where('employees.is_active', 1) - ->whereIn('employees.emp_status', ['active', 'expired']) - ->where('otp', $otp); + if (!empty($client_id)) { + $builder->where('employees.client_id', $client_id); + } - if (!empty($client_id)) { - $builder->where('employees.client_id', $client_id); - } + $employeeData = $builder->orderBy('employees.id', 'desc')->first(); - $employeeData = $builder->orderBy('employees.id', 'desc')->first(); - } + } else { + // $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('otp', $otp)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first(); + $builder = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.email_corporate', $email_id) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['active', 'expired']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active', 'expired']) + ->where('otp', $otp); + + if (!empty($client_id)) { + $builder->where('employees.client_id', $client_id); + } + + $employeeData = $builder->orderBy('employees.id', 'desc')->first(); + } - $lastQuery = $this->employeeModel->db->getLastQuery(); $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - getVerifiedUserData: Last Executed Query: " . $lastQuery); $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - getVerifiedUserData: employeeData: " . json_encode($employeeData ?? []));