The function first retrieves the employeeId and token from the request body.
Employee ID Validation: It checks if the employeeId is provided and is not empty. If missing, it responds with a 400 Bad Request error, indicating the employee ID is required.
Token Validation: It checks if a token is present in the request. If not, it returns a 400 Bad Request error, saying the token is required.
2. Token Verification
The token provided in the request is then validated:
It queries the ApiRoleModel to check if the token exists in the system.
If the token does not exist, the function returns an Unauthorized (401) response, saying the token is invalid.
It also checks the expiration date of the token to ensure it is still valid. If expired, it responds with an Unauthorized (401) error.
3. Fetch Employee Details
If the token is valid, the function proceeds to fetch employee details from the database:
It queries the StaffdetailsModel using the provided employeeId.
If no employee is found with the given ID, it returns a 404 Not Found error indicating the employee does not exist.
4. Fetch User Data
If the employee is found, the function retrieves the related user data:
It uses the UsersModel to get user details associated with the employee by looking up the user_id from the StaffdetailsModel.
If no user data is found for the employee, it responds with a 404 Not Found error.
5. Data Mapping and Formatting
Once both the employee and user data are retrieved, it prepares the response data:
It gathers relevant details such as:
Personal Information: first_name, last_name, email, contact_number, gender, dob.
Job Information: department_id, designation_id, office_shift_id, basic_salary, employment_type, etc.
Bank Information: account_title, account_number, bank_name.
Contract Info: The contract date (using date_of_joining).
Role: The role name of the employee.
The function uses helper functions (getGender, getDepartmentName, getShiftName, etc.) to translate IDs into readable names (e.g., department name, designation name, etc.).
6. Final Response
If all data retrieval and mappings are successful, the function responds with a 200 OK status, indicating the employee details were retrieved successfully. It returns the employee data in the response body.
If any issue arises (such as missing data or failed token validation), the function responds with an appropriate error message and status.
Summary of Key Steps:
Validation: It validates both the employeeId and token from the request, checking for their presence and validity.
Token Verification: It ensures the token is valid, not expired, and grants the necessary permissions.
Data Retrieval: The function fetches employee and user data from the database.
Data Mapping: It processes and formats the data, ensuring any IDs (like department, designation, etc.) are converted into their human-readable forms.
Response: If everything is valid, it returns the employee details. If not, it sends an error response with the relevant message.
This website uses
cookies. Continued use of this website indicates you have read and
understood our Privacy & Cookies policy and agree to its terms. Privacy & terms condition conditions