Group Management API
The Groups (Grupos) API provides endpoints for managing work groups, assigning operational roles to personnel, and controlling group membership. This module handles both operational groups (production floor teams organized by shifts) and administrative groups, with strict validation rules to prevent cross-type assignments.Permissions
All group endpoints require authentication and specific permissions:- VIEW_STAFF - Required for viewing groups and operational roles
- MANAGE_STAFF - Required for creating groups, managing memberships, and assigning operational roles
Get All Groups
Authorization
Required Permission:VIEW_STAFF
Response Schema
Returns a list of all active groups:Indicates if the request was successful
Array of group objects
Unique group identifier
Group name
Group type:
operativo or administrativoCurrent shift assignment (e.g., “T1”, “T2”, “T3”, “T4”). Administrative groups are fixed at “T4”.
Active status (1 = active, 0 = inactive)
Group creation timestamp
Last update timestamp
Get Group Details
Parameters
Group ID
Authorization
Required Permission:VIEW_STAFF
Response Schema
Returns comprehensive group details including current members and historical changes:Request success indicator
Detailed group information
Current active group members
Membership record ID
Personnel ID
First name
Last name
Employee code
Organizational role title
Current operational role name
Membership start timestamp
Membership end timestamp (null for active members)
Reason for assignment
ID of user who assigned this member
Complete membership history including removed members
Add Group Member
Parameters
Group ID
Authorization
Required Permission:MANAGE_STAFF
Request Body
Personnel ID to add to the group
Reason for adding the member. Defaults to “Asignación operativa estándar” if not provided.
Mark this assignment as a correction. If true, “[CORRECCIÓN]” prefix is added to the audit log.
Business Logic
Validation Rules
- Group Existence: Group must exist in the system
- Personnel Existence: Person must exist in the system
- Terminal State Protection: Cannot add personnel with
estado_laboral = "Baja" - Type Segregation:
- Personnel from “Administración” area can only join
administrativogroups - Personnel from other areas (e.g., “Producción”) can only join
operativogroups - Violation returns error: “Un colaborador administrativo no puede pertenecer a un grupo operativo” or vice versa
- Personnel from “Administración” area can only join
- Duplicate Prevention: Personnel cannot be added if they’re already an active member
- Transaction Safety: All operations run within a database transaction
- Audit Trail: Logged with action
GRUPO_ADD_INTEGRANTEincluding member details and group info
Error Responses
Remove Group Member
Parameters
Group ID
Personnel ID to remove from the group
Authorization
Required Permission:MANAGE_STAFF
Request Body
Reason for removal. Defaults to “Remoción operativa estándar” if not provided.
Mark this removal as a correction. If true, “[CORRECCIÓN]” prefix is added to the audit log.
Business Logic
- Membership Validation: Verifies that the person is currently an active member of the group
- Soft Delete: Sets
fecha_hasta = CURRENT_TIMESTAMPrather than deleting the record - Historical Preservation: Membership history is preserved for audit and reporting
- Transaction Safety: Runs within a database transaction
- Audit Trail: Logged with action
GRUPO_REMOVE_INTEGRANTEincluding person and group details
Error Responses
Rotate Group Shift
Parameters
Group ID
Authorization
Required Permission:MANAGE_STAFF
Request Body
New shift identifier (e.g., “T1”, “T2”, “T3”)
Business Logic
- Group Validation: Group must exist
- Type Restriction: Administrative groups (
tipo = "administrativo") have a fixed shift (“T4”) and cannot be rotated- Returns error: “El turno del grupo administrativo es fijo (T4)”
- Transaction Safety: Runs within a database transaction
- Audit Trail: Logged with action
GRUPO_ROTAR_TURNOshowing previous and new shift values - Timestamp Update: The
updated_atfield is automatically updated
Shift rotation is typically used for operational groups that follow rotating shift schedules (e.g., weekly rotation between T1, T2, and T3).
Error Responses
Get Operational Roles
Authorization
Required Permission:VIEW_STAFF
Response Schema
Returns the catalog of operational roles:Request success indicator
Usage
This endpoint provides the operational role catalog used for:- Populating dropdown menus when assigning operational roles
- Validating rol_operativo_id in assignment operations
- Displaying operational role capabilities and responsibilities
Assign Operational Role
Parameters
Personnel ID
Authorization
Required Permission:MANAGE_STAFF
Request Body
Operational role ID to assign. Must be a valid role from the roles_operativos catalog.
Reason for the role assignment. Defaults to “Cambio de rol operativo estándar” if not provided.
Mark this assignment as a correction. If true, “[CORRECCIÓN]” prefix is added to the audit log.
Business Logic
- Role Validation: Validates that the operational role exists and is active
- Historical Tracking:
- Previous operational role assignment is closed by setting
fecha_hasta = CURRENT_TIMESTAMP - New role assignment is inserted with
fecha_hasta = NULL(indicating current/active)
- Previous operational role assignment is closed by setting
- One Active Role: Each person can have only one active operational role at a time
- Transaction Safety: Runs within a database transaction
- Audit Trail: Logged with action
ROL_OPERATIVO_CHANGEincluding the new role name
System Roles vs Operational Roles:
- System Role (assigned via
/api/personal/:id/rol): Controls application permissions (e.g., Administrador, Supervisor, Operario) - Operational Role (assigned via this endpoint): Defines production floor competencies (e.g., Auxiliar, Operador Especializado, Técnico)
Error Responses
Get Personnel Operational History
Parameters
Personnel ID
Authorization
Required Permission:VIEW_STAFF
Response Schema
Returns the complete operational role history for a person:Request success indicator
Ordered list of operational role assignments (most recent first)
Assignment record ID
Personnel ID
Operational role ID
Operational role name
Role start timestamp
Role end timestamp (null for current active role)
Reason for the assignment
ID of user who made the assignment
Usage
This endpoint is useful for:- Tracking personnel career progression
- Auditing role changes
- Generating competency reports
- Identifying training and development paths
Data Models
Group Entity
Stored in thegrupos table:
Group Membership Entity
Stored in thegrupo_integrantes table:
Operational Role Assignment Entity
Stored in thepersona_roles_operativos table:
Operational Role Catalog
Stored in theroles_operativos table:
Business Rules Summary
Group Type Segregation
-
Operational Groups (
tipo = "operativo"):- Only for personnel from “Producción” and similar operational areas
- Subject to shift rotation
- Organized by production schedules
-
Administrative Groups (
tipo = "administrativo"):- Only for personnel from “Administración” area
- Fixed shift (T4 - typically administrative hours)
- Cannot be rotated
State Validation
- Personnel with
estado_laboral = "Baja"(terminated) cannot be added to groups - All group operations respect terminal state protection
Historical Integrity
- Group memberships are soft-deleted (fecha_hasta is set, not deleted)
- Operational role assignments maintain complete history
- All changes are audited with reasons and timestamps
Audit Compliance
- All mutations require a
motivo(reason) - Corrections are explicitly marked with
es_correccionflag - Audit logs include before/after states for all changes
Best Practices
Type Safety
- Validate area before assignment: Check personnel area before attempting to add to a group
- Respect shift constraints: Don’t attempt to rotate administrative group shifts
Historical Queries
- Current vs Historical: Use
fecha_hasta IS NULLto filter for current/active records:
- Role progression tracking: Query
persona_roles_operativosordered byfecha_desde DESCto see career progression
Performance
- Cache operational roles: The roles catalog is relatively static. Cache it client-side.
- Batch member additions: If adding multiple members to a group, make parallel requests: