feat(frontend): Add HSE API services module
Create API service layer for HSE (Health, Safety, Environment) module: - incidentes.api.ts: Incidents management with stats and investigation workflow - capacitaciones.api.ts: Training courses management - inspecciones.api.ts: Inspections with findings tracking - index.ts: Barrel exports All services follow the established pattern from fraccionamientos.api.ts: - TypeScript interfaces for entities, filters, and DTOs - Paginated responses support - Axios integration with automatic auth headers - Complete CRUD operations aligned with backend endpoints Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
e4cfe62b1b
commit
676978146b
81
web/src/services/hse/capacitaciones.api.ts
Normal file
81
web/src/services/hse/capacitaciones.api.ts
Normal file
@ -0,0 +1,81 @@
|
||||
import api, { PaginatedResponse, PaginationParams } from '../api';
|
||||
|
||||
export type TipoCapacitacion = 'induccion' | 'especifica' | 'certificacion' | 'reentrenamiento';
|
||||
|
||||
export interface Capacitacion {
|
||||
id: string;
|
||||
tenantId: string;
|
||||
codigo: string;
|
||||
nombre: string;
|
||||
descripcion?: string;
|
||||
tipo: TipoCapacitacion;
|
||||
duracionHoras: number;
|
||||
temario?: string;
|
||||
objetivos?: string;
|
||||
requisitos?: string;
|
||||
activo: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface CapacitacionFilters extends PaginationParams {
|
||||
tipo?: TipoCapacitacion;
|
||||
activo?: boolean;
|
||||
}
|
||||
|
||||
export interface CreateCapacitacionDto {
|
||||
codigo: string;
|
||||
nombre: string;
|
||||
descripcion?: string;
|
||||
tipo: TipoCapacitacion;
|
||||
duracionHoras: number;
|
||||
temario?: string;
|
||||
objetivos?: string;
|
||||
requisitos?: string;
|
||||
activo?: boolean;
|
||||
}
|
||||
|
||||
export interface UpdateCapacitacionDto {
|
||||
codigo?: string;
|
||||
nombre?: string;
|
||||
descripcion?: string;
|
||||
tipo?: TipoCapacitacion;
|
||||
duracionHoras?: number;
|
||||
temario?: string;
|
||||
objetivos?: string;
|
||||
requisitos?: string;
|
||||
activo?: boolean;
|
||||
}
|
||||
|
||||
export const capacitacionesApi = {
|
||||
list: async (filters?: CapacitacionFilters): Promise<PaginatedResponse<Capacitacion>> => {
|
||||
const response = await api.get<PaginatedResponse<Capacitacion>>('/hse/capacitaciones', {
|
||||
params: filters,
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
get: async (id: string): Promise<Capacitacion> => {
|
||||
const response = await api.get<Capacitacion>(`/hse/capacitaciones/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
create: async (data: CreateCapacitacionDto): Promise<Capacitacion> => {
|
||||
const response = await api.post<Capacitacion>('/hse/capacitaciones', data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
update: async (id: string, data: UpdateCapacitacionDto): Promise<Capacitacion> => {
|
||||
const response = await api.patch<Capacitacion>(`/hse/capacitaciones/${id}`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
toggleActive: async (id: string): Promise<Capacitacion> => {
|
||||
const response = await api.post<Capacitacion>(`/hse/capacitaciones/${id}/toggle-active`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
delete: async (id: string): Promise<void> => {
|
||||
await api.delete(`/hse/capacitaciones/${id}`);
|
||||
},
|
||||
};
|
||||
115
web/src/services/hse/incidentes.api.ts
Normal file
115
web/src/services/hse/incidentes.api.ts
Normal file
@ -0,0 +1,115 @@
|
||||
import api, { PaginatedResponse, PaginationParams } from '../api';
|
||||
|
||||
export type TipoIncidente = 'accidente' | 'incidente' | 'casi_accidente';
|
||||
export type GravedadIncidente = 'leve' | 'moderado' | 'grave' | 'fatal';
|
||||
export type EstadoIncidente = 'abierto' | 'en_investigacion' | 'cerrado';
|
||||
|
||||
export interface Incidente {
|
||||
id: string;
|
||||
tenantId: string;
|
||||
fraccionamientoId: string;
|
||||
tipo: TipoIncidente;
|
||||
gravedad: GravedadIncidente;
|
||||
estado: EstadoIncidente;
|
||||
fecha: string;
|
||||
hora?: string;
|
||||
ubicacion?: string;
|
||||
descripcion: string;
|
||||
causas?: string;
|
||||
acciones?: string;
|
||||
responsableId?: string;
|
||||
investigadorId?: string;
|
||||
fechaInvestigacion?: string;
|
||||
fechaCierre?: string;
|
||||
observaciones?: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface IncidenteFilters extends PaginationParams {
|
||||
fraccionamientoId?: string;
|
||||
tipo?: TipoIncidente;
|
||||
gravedad?: GravedadIncidente;
|
||||
estado?: EstadoIncidente;
|
||||
dateFrom?: string;
|
||||
dateTo?: string;
|
||||
}
|
||||
|
||||
export interface CreateIncidenteDto {
|
||||
fraccionamientoId: string;
|
||||
tipo: TipoIncidente;
|
||||
gravedad: GravedadIncidente;
|
||||
fecha: string;
|
||||
hora?: string;
|
||||
ubicacion?: string;
|
||||
descripcion: string;
|
||||
causas?: string;
|
||||
acciones?: string;
|
||||
responsableId?: string;
|
||||
observaciones?: string;
|
||||
}
|
||||
|
||||
export interface UpdateIncidenteDto {
|
||||
tipo?: TipoIncidente;
|
||||
gravedad?: GravedadIncidente;
|
||||
estado?: EstadoIncidente;
|
||||
fecha?: string;
|
||||
hora?: string;
|
||||
ubicacion?: string;
|
||||
descripcion?: string;
|
||||
causas?: string;
|
||||
acciones?: string;
|
||||
responsableId?: string;
|
||||
investigadorId?: string;
|
||||
fechaInvestigacion?: string;
|
||||
fechaCierre?: string;
|
||||
observaciones?: string;
|
||||
}
|
||||
|
||||
export interface IncidenteStats {
|
||||
total: number;
|
||||
porTipo: Record<TipoIncidente, number>;
|
||||
porGravedad: Record<GravedadIncidente, number>;
|
||||
porEstado: Record<EstadoIncidente, number>;
|
||||
abiertos: number;
|
||||
cerrados: number;
|
||||
}
|
||||
|
||||
export const incidentesApi = {
|
||||
list: async (filters?: IncidenteFilters): Promise<PaginatedResponse<Incidente>> => {
|
||||
const response = await api.get<PaginatedResponse<Incidente>>('/hse/incidentes', {
|
||||
params: filters,
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
getStats: async (): Promise<IncidenteStats> => {
|
||||
const response = await api.get<IncidenteStats>('/hse/incidentes/stats');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
get: async (id: string): Promise<Incidente> => {
|
||||
const response = await api.get<Incidente>(`/hse/incidentes/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
create: async (data: CreateIncidenteDto): Promise<Incidente> => {
|
||||
const response = await api.post<Incidente>('/hse/incidentes', data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
update: async (id: string, data: UpdateIncidenteDto): Promise<Incidente> => {
|
||||
const response = await api.patch<Incidente>(`/hse/incidentes/${id}`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
investigate: async (id: string, data: { investigadorId: string; fechaInvestigacion?: string }): Promise<Incidente> => {
|
||||
const response = await api.post<Incidente>(`/hse/incidentes/${id}/investigate`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
close: async (id: string, data: { fechaCierre?: string; observaciones?: string }): Promise<Incidente> => {
|
||||
const response = await api.post<Incidente>(`/hse/incidentes/${id}/close`, data);
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
3
web/src/services/hse/index.ts
Normal file
3
web/src/services/hse/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from './incidentes.api';
|
||||
export * from './capacitaciones.api';
|
||||
export * from './inspecciones.api';
|
||||
118
web/src/services/hse/inspecciones.api.ts
Normal file
118
web/src/services/hse/inspecciones.api.ts
Normal file
@ -0,0 +1,118 @@
|
||||
import api, { PaginatedResponse, PaginationParams } from '../api';
|
||||
|
||||
export type GravedadHallazgo = 'baja' | 'media' | 'alta' | 'critica';
|
||||
|
||||
export interface TipoInspeccion {
|
||||
id: string;
|
||||
tenantId: string;
|
||||
codigo: string;
|
||||
nombre: string;
|
||||
descripcion?: string;
|
||||
activo: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface Inspeccion {
|
||||
id: string;
|
||||
tenantId: string;
|
||||
tipoInspeccionId: string;
|
||||
fraccionamientoId: string;
|
||||
fecha: string;
|
||||
hora?: string;
|
||||
responsableId: string;
|
||||
estado: string;
|
||||
observaciones?: string;
|
||||
hallazgos?: Hallazgo[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface Hallazgo {
|
||||
id: string;
|
||||
inspeccionId: string;
|
||||
item: string;
|
||||
descripcion: string;
|
||||
gravedad: GravedadHallazgo;
|
||||
accionCorrectiva?: string;
|
||||
responsableId?: string;
|
||||
fechaCompromiso?: string;
|
||||
fechaCierre?: string;
|
||||
cerrado: boolean;
|
||||
evidencia?: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface InspeccionFilters extends PaginationParams {
|
||||
tipoInspeccionId?: string;
|
||||
fraccionamientoId?: string;
|
||||
estado?: string;
|
||||
dateFrom?: string;
|
||||
dateTo?: string;
|
||||
}
|
||||
|
||||
export interface CreateInspeccionDto {
|
||||
tipoInspeccionId: string;
|
||||
fraccionamientoId: string;
|
||||
fecha: string;
|
||||
hora?: string;
|
||||
responsableId: string;
|
||||
observaciones?: string;
|
||||
}
|
||||
|
||||
export interface CreateHallazgoDto {
|
||||
item: string;
|
||||
descripcion: string;
|
||||
gravedad: GravedadHallazgo;
|
||||
accionCorrectiva?: string;
|
||||
responsableId?: string;
|
||||
fechaCompromiso?: string;
|
||||
}
|
||||
|
||||
export interface InspeccionStats {
|
||||
total: number;
|
||||
porEstado: Record<string, number>;
|
||||
hallazgosPorGravedad: Record<GravedadHallazgo, number>;
|
||||
hallazgosAbiertos: number;
|
||||
hallazgosCerrados: number;
|
||||
}
|
||||
|
||||
export const inspeccionesApi = {
|
||||
listTipos: async (): Promise<TipoInspeccion[]> => {
|
||||
const response = await api.get<TipoInspeccion[]>('/hse/inspecciones/tipos');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
list: async (filters?: InspeccionFilters): Promise<PaginatedResponse<Inspeccion>> => {
|
||||
const response = await api.get<PaginatedResponse<Inspeccion>>('/hse/inspecciones', {
|
||||
params: filters,
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
getStats: async (): Promise<InspeccionStats> => {
|
||||
const response = await api.get<InspeccionStats>('/hse/inspecciones/stats');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
get: async (id: string): Promise<Inspeccion> => {
|
||||
const response = await api.get<Inspeccion>(`/hse/inspecciones/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
create: async (data: CreateInspeccionDto): Promise<Inspeccion> => {
|
||||
const response = await api.post<Inspeccion>('/hse/inspecciones', data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
updateEstado: async (id: string, data: { estado: string; observaciones?: string }): Promise<Inspeccion> => {
|
||||
const response = await api.patch<Inspeccion>(`/hse/inspecciones/${id}/estado`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
addHallazgo: async (id: string, data: CreateHallazgoDto): Promise<Hallazgo> => {
|
||||
const response = await api.post<Hallazgo>(`/hse/inspecciones/${id}/hallazgos`, data);
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user