CHANGE_ADD_NEW_API_FIREBASE_TOKEN_API_EMP_REST : AADHAVAN
This commit is contained in:
parent
ba4ad6bb62
commit
5e3c126b0b
@ -136,6 +136,7 @@ $routes->group("/employee", ["filter" => "authMVC"], function ($routes) {
|
|||||||
$routes->post("upload", "EmployeeController::employeesUplodWithEvents");
|
$routes->post("upload", "EmployeeController::employeesUplodWithEvents");
|
||||||
$routes->get("excel_error/(:any)", "EmployeeController::getExcelFileErrors/$1");
|
$routes->get("excel_error/(:any)", "EmployeeController::getExcelFileErrors/$1");
|
||||||
$routes->get("endorsement-list", "EmployeeController::endorsementList");
|
$routes->get("endorsement-list", "EmployeeController::endorsementList");
|
||||||
|
$routes->get("enrollment-list", "EmployeeController::enrollmentList");
|
||||||
$routes->get("truncate/(:any)", "EmployeeController::truncateFileData/$1");
|
$routes->get("truncate/(:any)", "EmployeeController::truncateFileData/$1");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -287,6 +288,7 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) {
|
|||||||
|
|
||||||
$routes->get("getChatResponse", "ChatBotController::getChatResponse");
|
$routes->get("getChatResponse", "ChatBotController::getChatResponse");
|
||||||
$routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) {
|
$routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) {
|
||||||
|
$routes->post("storeFireBase", "EmployeeRestController::storeFireBase");
|
||||||
$routes->post("saveMpin", "RestAuthenticationController::saveMpin");
|
$routes->post("saveMpin", "RestAuthenticationController::saveMpin");
|
||||||
$routes->post("updateMpin", "RestAuthenticationController::updateMpin");
|
$routes->post("updateMpin", "RestAuthenticationController::updateMpin");
|
||||||
$routes->get("getChatResponse", "ChatBotController::getChatResponse");
|
$routes->get("getChatResponse", "ChatBotController::getChatResponse");
|
||||||
|
|||||||
@ -2319,4 +2319,59 @@ public function getAdvertisementImage()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function storeFireBase()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$firebase_token = $this->request->getPost('firebase_token');
|
||||||
|
$mobile = $this->request->getPost('mobile');
|
||||||
|
|
||||||
|
// Ensure the mobile number is provided
|
||||||
|
if (empty($mobile)) {
|
||||||
|
return $this->respond(['status' => 'failed', 'code' => 400, 'message' => 'Mobile number is required'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch employee by mobile number
|
||||||
|
$employee = $this->employeeModel->where('mobile', $mobile)->first();
|
||||||
|
|
||||||
|
if ($employee) {
|
||||||
|
// Check if firebase_token is provided
|
||||||
|
if (!empty($firebase_token)) {
|
||||||
|
|
||||||
|
// Check if the current firebase_token is different from the new one
|
||||||
|
if ($employee['firebase_token'] !== $firebase_token) {
|
||||||
|
// Update the employee's firebase_token
|
||||||
|
$data['firebase_token'] = $firebase_token;
|
||||||
|
$id = $employee['id'];
|
||||||
|
// return json_encode($data);
|
||||||
|
// Direct database update query for testing
|
||||||
|
$db = \Config\Database::connect();
|
||||||
|
$builder = $db->table('employees');
|
||||||
|
$update_emp = $builder->update($data, ['id' => $id]);
|
||||||
|
|
||||||
|
// Check if the update was successful
|
||||||
|
if ($db->affectedRows() > 0) {
|
||||||
|
// Fetch the updated employee data
|
||||||
|
$updated_employee = $this->employeeModel->find($id);
|
||||||
|
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $updated_employee], 200);
|
||||||
|
} else {
|
||||||
|
log_message('error', 'Update failed. No rows affected.');
|
||||||
|
return $this->respond(['status' => 'failed', 'code' => 500, 'message' => 'Failed to update employee data'], 500);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $this->respond(['status' => 'failed', 'code' => 400, 'message' => 'New Firebase Token is the same as the current one'], 400);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $this->respond(['status' => 'failed', 'code' => 400, 'message' => 'Firebase Token is required'], 400);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $this->respond(['status' => 'failed', 'code' => 404, 'message' => 'Employee not found'], 404);
|
||||||
|
}
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
log_message('error', 'An error occurred: ' . $th->getMessage());
|
||||||
|
return $this->respond(['status' => 'failed', 'code' => 500, 'message' => 'An error occurred', 'error' => $th->getMessage()], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user