46 lines
1.8 KiB
TypeScript
46 lines
1.8 KiB
TypeScript
|
|
import apiClient from '../apiClient';
|
||
|
|
import type { CanillaDto } from '../../models/dtos/Distribucion/CanillaDto';
|
||
|
|
import type { CreateCanillaDto } from '../../models/dtos/Distribucion/CreateCanillaDto';
|
||
|
|
import type { UpdateCanillaDto } from '../../models/dtos/Distribucion/UpdateCanillaDto';
|
||
|
|
import type { ToggleBajaCanillaDto } from '../../models/dtos/Distribucion/ToggleBajaCanillaDto';
|
||
|
|
|
||
|
|
|
||
|
|
const getAllCanillas = async (nomApeFilter?: string, legajoFilter?: number, soloActivos?: boolean): Promise<CanillaDto[]> => {
|
||
|
|
const params: Record<string, string | number | boolean> = {};
|
||
|
|
if (nomApeFilter) params.nomApe = nomApeFilter;
|
||
|
|
if (legajoFilter !== undefined && legajoFilter !== null) params.legajo = legajoFilter;
|
||
|
|
if (soloActivos !== undefined) params.soloActivos = soloActivos;
|
||
|
|
|
||
|
|
const response = await apiClient.get<CanillaDto[]>('/canillas', { params });
|
||
|
|
return response.data;
|
||
|
|
};
|
||
|
|
|
||
|
|
const getCanillaById = async (id: number): Promise<CanillaDto> => {
|
||
|
|
const response = await apiClient.get<CanillaDto>(`/canillas/${id}`);
|
||
|
|
return response.data;
|
||
|
|
};
|
||
|
|
|
||
|
|
const createCanilla = async (data: CreateCanillaDto): Promise<CanillaDto> => {
|
||
|
|
const response = await apiClient.post<CanillaDto>('/canillas', data);
|
||
|
|
return response.data;
|
||
|
|
};
|
||
|
|
|
||
|
|
const updateCanilla = async (id: number, data: UpdateCanillaDto): Promise<void> => {
|
||
|
|
await apiClient.put(`/canillas/${id}`, data);
|
||
|
|
};
|
||
|
|
|
||
|
|
const toggleBajaCanilla = async (id: number, data: ToggleBajaCanillaDto): Promise<void> => {
|
||
|
|
// El backend espera el DTO en el cuerpo para este endpoint específico.
|
||
|
|
await apiClient.post(`/canillas/${id}/toggle-baja`, data);
|
||
|
|
};
|
||
|
|
|
||
|
|
|
||
|
|
const canillaService = {
|
||
|
|
getAllCanillas,
|
||
|
|
getCanillaById,
|
||
|
|
createCanilla,
|
||
|
|
updateCanilla,
|
||
|
|
toggleBajaCanilla,
|
||
|
|
};
|
||
|
|
|
||
|
|
export default canillaService;
|