Delete Employee Api 0 0

Last updated on Nov 26, 2024 06:41 in API
Posted Bykirt
  1. Input Validation: It checks that the request contains a valid token. If the token is missing or invalid, an error response is returned.

  2. Token and Permissions Check: The function validates the token by checking its existence, expiration, and whether the user has the necessary permissions (employees_delete) to delete an employee. If any of these conditions fail, an error response is returned.

  3. Employee and User Validation: It checks if the employee exists in the database by verifying the employeeId. Additionally, it checks if there is linked user data for the employee. If any of these checks fail, the function returns an error.

  4. Deleting Related Data: If the employee exists, it checks for and deletes related records such as bank details from the EmployeeBankDetailModel.

  5. Deleting the Employee: The function deletes the employee's record from the StaffdetailsModel and any associated user data from the UsersModel.

  6. Success Response: If all operations succeed, a success response is returned, confirming the employee was deleted.

The code ensures proper validation, permission checks, and cleanup of related data before performing the delete operation.


** The time is base on UTC timezone