This API endpoint is used to save or update the working hours for an employee, for a specified date range. The data is sent via a POST request and includes employee details, the type of hours (e.g., tips), and the number of hours worked.
API Request Parameters (Summary):
token (string): Required for authentication; must be valid and not expired.
start_date (string): Required; format MM/DD/YYYY. The start date of the work period.
end_date (string): Required; format MM/DD/YYYY. The end date of the work period.
employee_id (integer): Required; unique identifier for the employee.
hours_type (string): Required; type of hours being logged (e.g., "Tips").
hours_value (numeric): Required; the number of hours worked, represented as a numeric value.
Process Flow (Summary):
Input Validation: Checks if all required fields are present and have the correct data types.
Token Authentication: Validates the token and ensures it hasn’t expired. Returns 401 Unauthorized if invalid.
Permission Check: Verifies that the user’s role includes permission to create/update hours.
Employee Validation: Checks if the employee exists in the database. Returns 400 Bad Request if not.
Hours Type Validation: Ensures the specified hours type exists in the employee’s country allowances.
Check for Existing Records: Checks if the record for the given date range exists. If it does, updates; if not, inserts a new record.
Saving or Updating Hours: Saves or updates the hours based on the validation and existence of records.