Skip to main content
TicketsService is part of the shared library (projects/shared/src/lib/tickets.service.ts) and is injectable at the root level — you do not need to add it to any module’s providers array.
The service currently targets http://127.0.0.1:8000/api/tickets. The production URL (https://back-helpdesk-dmep.onrender.com) is commented out in the source. To switch to production, uncomment the baseUrl line for the Render deployment and comment out the localhost line in tickets.service.ts.

Method summary

MethodHTTPDescription
createPOST /api/tickets/crearSubmit a new ticket
consultarPOST /api/tickets/consultarLook up a ticket from the public portal
dashboardGET /api/tickets/dashboardList all tickets for the admin dashboard
getByIdGET /api/tickets/:idFetch a single ticket with its history
dashboardMetricasGET /api/tickets/dashboard-metricasFetch aggregated KPI metrics
actualizarPOST /api/tickets/:id/actualizarUpdate status, priority, area, or response
asignarPOST /api/tickets/:id/asignarAssign a ticket to an agent
transferirPOST /api/tickets/:id/transferirTransfer a ticket to a new area or agent
reclasificarPOST /api/tickets/:id/reclasificarChange priority and category
pausarPOST /api/tickets/:id/pausarPause an active ticket
reabrirPOST /api/tickets/:id/reabrirReopen a closed or paused ticket
cancelarPOST /api/tickets/:id/cancelarCancel a ticket (user or agent)
archivarPOST /api/tickets/:id/archivarArchive a resolved ticket

Source

import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

import {
  TicketCreatePayload,
  TicketCreateResponse,
  TicketConsultaPayload,
  TicketConsultaResponse,
  TicketMDA,
} from '../models/ticket.model';

@Injectable({
  providedIn: 'root',
})
export class TicketsService {
  private readonly http = inject(HttpClient);
  // private readonly baseUrl = 'https://back-helpdesk-dmep.onrender.com';
  private readonly baseUrl = 'http://127.0.0.1:8000/api/tickets';

  create(payload: TicketCreatePayload): Observable<TicketCreateResponse> {
    return this.http.post<TicketCreateResponse>(`${this.baseUrl}/crear`, payload);
  }

  consultar(payload: TicketConsultaPayload): Observable<TicketConsultaResponse> {
    return this.http.post<TicketConsultaResponse>(`${this.baseUrl}/consultar`, payload);
  }

  dashboard(): Observable<TicketMDA[]> {
    return this.http.get<TicketMDA[]>(`${this.baseUrl}/dashboard`);
  }

  getById(ticketId: string): Observable<any> {
    return this.http.get<any>(`${this.baseUrl}/${ticketId}`);
  }

  dashboardMetricas(): Observable<any[]> {
    return this.http.get<any[]>(`${this.baseUrl}/dashboard-metricas`);
  }

  actualizar(
    ticketId: string,
    payload: {
      estado: string;
      prioridad: string;
      area: string;
      respuesta: string;
    }
  ): Observable<{ message: string }> {
    return this.http.post<{ message: string }>(
      `${this.baseUrl}/${ticketId}/actualizar`,
      payload
    );
  }

  asignar(ticketId: string, agenteId: string, motivo: string): Observable<{ message: string }> {
    return this.http.post<{ message: string }>(`${this.baseUrl}/${ticketId}/asignar`, {
      agenteId,
      motivo,
    });
  }

  transferir(
    ticketId: string,
    nuevaArea: string,
    agenteId: string,
    motivo: string
  ): Observable<{ message: string }> {
    return this.http.post<{ message: string }>(`${this.baseUrl}/${ticketId}/transferir`, {
      nuevaArea,
      agenteId,
      motivo,
    });
  }

  reclasificar(
    ticketId: string,
    nuevaPrioridad: string,
    nuevaCategoria: string,
    motivo: string
  ): Observable<{ message: string }> {
    return this.http.post<{ message: string }>(`${this.baseUrl}/${ticketId}/reclasificar`, {
      nuevaPrioridad,
      nuevaCategoria,
      motivo,
    });
  }

  pausar(ticketId: string, motivo: string): Observable<{ message: string }> {
    return this.http.post<{ message: string }>(`${this.baseUrl}/${ticketId}/pausar`, {
      motivo,
    });
  }

  reabrir(ticketId: string, motivo: string): Observable<{ message: string }> {
    return this.http.post<{ message: string }>(`${this.baseUrl}/${ticketId}/reabrir`, {
      motivo,
    });
  }

  cancelar(ticketId: string, motivo: string, rol: 'USUARIO' | 'AGENTE'): Observable<{ message: string }> {
    return this.http.post<{ message: string }>(`${this.baseUrl}/${ticketId}/cancelar`, {
      motivo,
      rol,
    });
  }

  archivar(ticketId: string, motivo: string): Observable<{ message: string }> {
    return this.http.post<{ message: string }>(
      `${this.baseUrl}/${ticketId}/archivar`,
      { motivo }
    );
  }
}

Methods

create

create(payload: TicketCreatePayload): Observable<TicketCreateResponse>
Submits a new support ticket. Used by the public-facing portal when an end user opens a request. HTTP: POST /api/tickets/crear Parameters
payload
TicketCreatePayload
required
The ticket creation payload. See Ticket model for all fields.
Returns: Observable<TicketCreateResponse> — includes the new ticket’s UUID, label, SLA hours, and SLA deadline. See TicketCreateResponse. Usage example
const payload: TicketCreatePayload = {
  nombre: 'Ana García',
  email: '[email protected]',
  tipo: 'PETICION',
  categoria: 'Soporte técnico',
  descripcion: 'No puedo acceder al sistema desde ayer.',
  prioridad: 'MEDIA',
};

this.ticketsService.create(payload).subscribe({
  next: (res) => console.log('Ticket creado:', res.ticketLabel),
  error: (err) => console.error(err),
});

consultar

consultar(payload: TicketConsultaPayload): Observable<TicketConsultaResponse>
Looks up a ticket by label and email. Used by the public portal so end users can track the status of their own tickets without logging in. HTTP: POST /api/tickets/consultar Parameters
payload
TicketConsultaPayload
required
Must contain the ticket label and the email used when the ticket was created. See TicketConsultaPayload.
Returns: Observable<TicketConsultaResponse> — contains the public ticket view and its history. See TicketConsultaResponse.

dashboard

dashboard(): Observable<TicketMDA[]>
Retrieves all tickets for the admin dashboard list view. Each item includes computed SLA fields (horasRestantes, slaVencido) and the assigned agent’s name. HTTP: GET /api/tickets/dashboard Parameters: None. Returns: Observable<TicketMDA[]> — array of tickets with admin-level SLA metadata. See TicketMDA.

getById

getById(ticketId: string): Observable<any>
Fetches a single ticket by its UUID, including the full activity history. HTTP: GET /api/tickets/:id Parameters
ticketId
string
required
UUID of the ticket to retrieve.
Returns: Observable<any> — ticket detail object with a historial array of activity entries.

dashboardMetricas

dashboardMetricas(): Observable<any[]>
Returns aggregated ticket metrics for the KPI dashboard. Use this to populate summary cards showing totals by status, priority, or area. HTTP: GET /api/tickets/dashboard-metricas Parameters: None. Returns: Observable<any[]> — array of metric objects from the backend.

actualizar

actualizar(
  ticketId: string,
  payload: { estado: string; prioridad: string; area: string; respuesta: string }
): Observable<{ message: string }>
Updates the status, priority, area assignment, or agent response for a ticket. HTTP: POST /api/tickets/:id/actualizar Parameters
ticketId
string
required
UUID of the ticket to update.
estado
string
required
New status value. See TicketStatus for valid values.
prioridad
string
required
New priority level.
area
string
required
Area to assign the ticket to.
respuesta
string
required
Agent response text to attach to the ticket.
Returns: Observable<{ message: string }>

asignar

asignar(ticketId: string, agenteId: string, motivo: string): Observable<{ message: string }>
Assigns a ticket to a specific agent. HTTP: POST /api/tickets/:id/asignar Parameters
ticketId
string
required
UUID of the ticket to assign.
agenteId
string
required
UUID of the agent to assign the ticket to.
motivo
string
required
Reason for the assignment. Recorded in the ticket history.
Returns: Observable<{ message: string }>

transferir

transferir(
  ticketId: string,
  nuevaArea: string,
  agenteId: string,
  motivo: string
): Observable<{ message: string }>
Transfers a ticket to a different area and optionally reassigns it to a new agent. HTTP: POST /api/tickets/:id/transferir Parameters
ticketId
string
required
UUID of the ticket to transfer.
nuevaArea
string
required
The destination area.
agenteId
string
required
UUID of the agent in the destination area.
motivo
string
required
Reason for the transfer. Recorded in the ticket history.
Returns: Observable<{ message: string }>

reclasificar

reclasificar(
  ticketId: string,
  nuevaPrioridad: string,
  nuevaCategoria: string,
  motivo: string
): Observable<{ message: string }>
Changes the priority and category of a ticket. HTTP: POST /api/tickets/:id/reclasificar Parameters
ticketId
string
required
UUID of the ticket to reclassify.
nuevaPrioridad
string
required
New priority level. See TicketPrioridad for valid values.
nuevaCategoria
string
required
New category string.
motivo
string
required
Reason for reclassification. Recorded in the ticket history.
Returns: Observable<{ message: string }>

pausar

pausar(ticketId: string, motivo: string): Observable<{ message: string }>
Pauses an active ticket, changing its status to PAUSADO. HTTP: POST /api/tickets/:id/pausar Parameters
ticketId
string
required
UUID of the ticket to pause.
motivo
string
required
Reason for pausing. Recorded in the ticket history.
Returns: Observable<{ message: string }>

reabrir

reabrir(ticketId: string, motivo: string): Observable<{ message: string }>
Reopens a closed or paused ticket. HTTP: POST /api/tickets/:id/reabrir Parameters
ticketId
string
required
UUID of the ticket to reopen.
motivo
string
required
Reason for reopening. Recorded in the ticket history.
Returns: Observable<{ message: string }>

cancelar

cancelar(ticketId: string, motivo: string, rol: 'USUARIO' | 'AGENTE'): Observable<{ message: string }>
Cancels a ticket. The rol parameter tells the backend whether the action was taken by the end user or an agent, which may affect business rules and audit logging. HTTP: POST /api/tickets/:id/cancelar Parameters
ticketId
string
required
UUID of the ticket to cancel.
motivo
string
required
Reason for cancellation. Recorded in the ticket history.
rol
'USUARIO' | 'AGENTE'
required
The role of the actor performing the cancellation. Pass 'USUARIO' when the end user cancels their own ticket; pass 'AGENTE' when a help desk agent cancels it.
Returns: Observable<{ message: string }>

archivar

archivar(ticketId: string, motivo: string): Observable<{ message: string }>
Archives a resolved ticket, removing it from the active dashboard. HTTP: POST /api/tickets/:id/archivar Parameters
ticketId
string
required
UUID of the ticket to archive.
motivo
string
required
Reason for archiving. Recorded in the ticket history.
Returns: Observable<{ message: string }>

Build docs developers (and LLMs) love