Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/lucavallini/aibar-frontend/llms.txt

Use this file to discover all available pages before exploring further.

The Users module (/usuarios) is an administration-only area where an administrator can create new system accounts, update existing user details and roles, and deactivate accounts that are no longer needed. Employees with the empleado role cannot navigate to this route — the adminGuard blocks access and redirects them to /viajes. All user data persists in the database even after deactivation, preserving the full audit trail.
This module is protected by adminGuard. Only users with the administrador role can access /usuarios. Any other authenticated user is automatically redirected to /viajes upon attempting to visit this route.

Data Models

Usuario

The core interface returned by every read and write operation in the Users module.
export interface Usuario {
  id: string;
  nombre_usuario: string;      // Auto-derived from nombre_completo by the backend
  nombre_completo: string;
  dni: string;
  rol: 'administrador' | 'empleado';
  activo: boolean;
  creado_en: string;           // ISO 8601 timestamp
}
nombre_usuario is never set by the frontend. The backend derives it automatically from nombre_completo when the account is created. After creation, the administrator should communicate the generated nombre_usuario and the chosen password to the new employee.

UsuarioCreate

Payload sent when creating a new account.
export interface UsuarioCreate {
  nombre_completo: string;
  dni: string;
  password: string;
  rol: 'administrador' | 'empleado';
}

UsuarioUpdate

Partial payload for editing an existing account. All fields are optional; only the fields that are provided are updated.
export interface UsuarioUpdate {
  nombre_completo?: string;
  dni?: string;
  rol?: 'administrador' | 'empleado';
}

Roles

The application recognises exactly two roles. Every user account must be assigned one of them.

administrador

Full access to all modules including Users and Audit Log. Can create, edit, and deactivate any account (except their own deactivation).

empleado

Restricted to operational modules: Trips, Drivers, Trucks, Fines, and Fuel. Cannot access /usuarios or /auditoria.

UsuariosService API

The service is injected application-wide via providedIn: 'root' and wraps four HTTP calls against the /usuarios endpoint.
@Injectable({ providedIn: 'root' })
export class UsuariosService {
  private apiUrl = `${environment.apiUrl}/usuarios`;

  constructor(private http: HttpClient) {}

  listar(pagina: number = 1, tamanoPagina: number = 20): Observable<RespuestaPaginada<Usuario>> {
    return this.http.get<RespuestaPaginada<Usuario>>(
      `${this.apiUrl}/?pagina=${pagina}&tamano_pagina=${tamanoPagina}`
    );
  }

  crear(datos: UsuarioCreate): Observable<Usuario> {
    return this.http.post<Usuario>(`${this.apiUrl}/`, datos);
  }

  actualizar(id: string, datos: UsuarioUpdate): Observable<Usuario> {
    return this.http.patch<Usuario>(`${this.apiUrl}/${id}`, datos);
  }

  darDeBaja(id: string): Observable<Usuario> {
    return this.http.delete<Usuario>(`${this.apiUrl}/${id}`);
  }
}

listar(pagina, tamanoPagina)

Fetches a paginated list of all users, both active and inactive.
ParameterTypeDefaultDescription
paginanumber1Page number to retrieve
tamanoPaginanumber20Number of records per page
HTTP request: GET /usuarios/?pagina=1&tamano_pagina=20 Returns: Observable<RespuestaPaginada<Usuario>>
export interface RespuestaPaginada<T> {
  items: T[];
  total: number;
  pagina: number;
  tamano_pagina: number;
  total_paginas: number;
}

crear(datos: UsuarioCreate)

Creates a new user account. The backend derives nombre_usuario from nombre_completo and returns the full Usuario object, including the generated username. HTTP request: POST /usuarios/ Returns: Observable<Usuario> Validation (enforced in ListaUsuarios):
  • nombre_completo must not be blank
  • dni must not be blank
  • password must be at least 6 characters
If a user with the same dni already exists, the backend responds with HTTP 400. The component surfaces this as “Ya existe un usuario con ese DNI”.

actualizar(id, datos: UsuarioUpdate)

Updates one or more fields on an existing account via a partial PATCH. The password field cannot be changed through this endpoint. HTTP request: PATCH /usuarios/{id} Returns: Observable<Usuario>

darDeBaja(id)

Soft-deactivates the user account — it sets activo: false on the backend. The record is not deleted. A deactivated user can no longer log in, but all their history and audit entries are preserved. HTTP request: DELETE /usuarios/{id} Returns: Observable<Usuario>
An administrator cannot deactivate their own account. The component guards against this with esUsuarioActual(): the Baja button is hidden for the currently logged-in user, and the backend will respond with HTTP 400 if this constraint is violated via the API directly.

Create Account Form Fields

The Nuevo usuario modal collects the following fields, which map directly to UsuarioCreate:
nombre_completo
string
required
Full name of the new user (e.g. "Juan García"). The backend uses this value to auto-generate the nombre_usuario login handle.
dni
string
required
National identity document number. Must be unique across all user accounts. Used as a secondary identifier throughout the system.
password
string
required
Initial password for the account. Must be at least 6 characters long. The administrator is responsible for communicating this password to the new user after creation.
rol
'administrador' | 'empleado'
required
Role to assign to the new account. Defaults to empleado in the creation form. Choose administrador only when the new user needs full system access.

Usage Example

The following example shows how ListaUsuarios creates a new employee account and handles the two most common error cases:
// Initialise the form with safe defaults
formularioVacioAlta(): UsuarioCreate {
  return { nombre_completo: '', dni: '', password: '', rol: 'empleado' };
}

// Called when the administrator clicks "Crear usuario"
confirmarAlta(): void {
  if (
    !this.nuevoUsuario.nombre_completo.trim() ||
    !this.nuevoUsuario.dni.trim() ||
    this.nuevoUsuario.password.length < 6
  ) {
    this.error.set('Completá nombre, DNI y una contraseña de al menos 6 caracteres');
    return;
  }

  this.usuariosService.crear(this.nuevoUsuario).subscribe({
    next: (usuarioCreado) => {
      this.cerrarAlta();
      this.pagina.set(1);
      this.cargarUsuarios();
      // Notify the administrator of the generated username
      alert(
        `Usuario creado: ${usuarioCreado.nombre_usuario}\n` +
        `Comunicale este usuario y la contraseña que elegiste.`
      );
    },
    error: (err) => {
      if (err.status === 400) {
        this.error.set('Ya existe un usuario con ese DNI');
      } else {
        this.error.set('No se pudo crear el usuario');
      }
    }
  });
}

User Table Columns

The /usuarios view renders one row per account with the following columns, sourced directly from the Usuario interface:
ColumnSource fieldNotes
Nombre completonombre_completoEditable via the Edit modal
Usuarionombre_usuarioRead-only; auto-generated by the backend
DNIdniEditable; must remain unique
RolrolDisplayed as a coloured badge; editable
EstadoactivoDisplays Activo or Inactivo
AccionesEdit button always visible; Baja button hidden for own account and already-inactive accounts

Workflow

1

Open the New User modal

Click + Nuevo usuario in the page header. The form initialises with blank fields and rol defaulting to empleado.
2

Fill in the required fields

Enter the Nombre completo, DNI, and an initial Contraseña of at least 6 characters. Select the appropriate Rol.
3

Submit and note the username

Click Crear usuario. On success, the app displays an alert with the auto-generated nombre_usuario. Share this login handle and the chosen password with the new user.
4

Edit or deactivate as needed

Use the Editar button in the table row to update the name, DNI, or role at any time. Use Baja to soft-deactivate an account — the user will be unable to log in, but their records remain intact.

Build docs developers (and LLMs) love