Skip to main content
Administrators can approve or reject pending employee requests. The approval process varies depending on the request type.

Approve Request

PUT /api/solicitudes/:id/aprobar

Authentication

Admin Access Required

This endpoint requires Admin or Super Admin role. Regular employees cannot approve requests.

Path Parameters

id
number
required
The unique identifier of the request to approve

Request Body

retroalimentacion
string
Optional feedback message for the employeeExample: "Approved. Enjoy your vacation!"

Response

message
string
Success message indicating the request type that was approved
solicitud_actualizada
object
The updated request object with approval details

Code Example

const token = 'admin_jwt_token';
const requestId = 123;

const response = await fetch(`/api/solicitudes/${requestId}/aprobar`, {
  method: 'PUT',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    retroalimentacion: 'Approved. Have a great time!'
  })
});

const data = await response.json();
console.log(data);

Success Response

200 OK
{
  "message": "Solicitud de 1 aprobada exitosamente.",
  "solicitud_actualizada": {
    "id_solicitud": 123,
    "id_estado_solicitud": 2,
    "id_aprobador": 5,
    "retroalimentacion": "Approved. Have a great time!"
  }
}

Error Responses

{
  "message": "Solicitud con ID 999 no encontrada"
}

Reject Request

PUT /api/solicitudes/:id/rechazar

Authentication

Admin Access Required

This endpoint requires Admin or Super Admin role. Regular employees cannot reject requests.

Path Parameters

id
number
required
The unique identifier of the request to reject

Request Body

retroalimentacion
string
Optional feedback explaining why the request was rejectedExample: "Insufficient staffing during this period"

Response

message
string
Success message: “Solicitud rechazada exitosamente”
solicitud_actualizada
object
The updated request object with rejection details

Code Example

const token = 'admin_jwt_token';
const requestId = 123;

const response = await fetch(`/api/solicitudes/${requestId}/rechazar`, {
  method: 'PUT',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    retroalimentacion: 'Cannot approve due to staffing requirements'
  })
});

const data = await response.json();
console.log(data);

Success Response

200 OK
{
  "message": "Solicitud rechazada exitosamente",
  "solicitud_actualizada": {
    "id_solicitud": 123,
    "id_estado_solicitud": 3,
    "id_aprobador": 5,
    "retroalimentacion": "Cannot approve due to staffing requirements"
  }
}

Error Responses

{
  "message": "Solicitud con ID 999 no encontrada"
}

Cancel Request (Employee)

PUT /api/solicitudes/:id/cancelar
Employees can cancel their own pending requests.

Authentication

Owner Only

Employees can only cancel their own requests. Admins cannot use this endpoint to cancel others’ requests.

Path Parameters

id
number
required
The unique identifier of the request to cancel

Code Example

const token = 'employee_jwt_token';
const requestId = 123;

const response = await fetch(`/api/solicitudes/${requestId}/cancelar`, {
  method: 'PUT',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  }
});

const data = await response.json();

Success Response

200 OK
{
  "message": "Solicitud cancelada exitosamente",
  "solicitud_actualizada": {
    "id_solicitud": 123,
    "id_estado_solicitud": 4
  }
}

Error Responses

{
  "message": "Solicitud no encontrada"
}

Approval Business Logic by Type

Vacation (Type 1)

  • Validates employee has sufficient vacation days
  • Checks date range validity
  • Deducts days from employee balance
  • Updates vacation record

Profile Update (Type 5)

  • Applies proposed changes to employee record
  • Updates phone, address, or profile image
  • No balance calculations needed

Absence (Type 3)

  • Simple approval without balance changes
  • Validates date range
  • Records approval

Other Types (2, 4)

  • Simple approval process
  • Date validation if applicable
  • No special business logic

Notifications

When a request is approved or rejected, the system automatically sends a notification to the employee: Approval Notification:
  • Type: SOLICITUD_APROBADA
  • Message includes approval confirmation
Rejection Notification:
  • Type: SOLICITUD_RECHAZADA
  • Message: “Tu solicitud ha sido rechazada”
  • Includes feedback if provided

Build docs developers (and LLMs) love