39 lines
1.8 KiB
TypeScript
39 lines
1.8 KiB
TypeScript
|
|
import apiClient from '../apiClient';
|
||
|
|
import type { PorcPagoDto } from '../../models/dtos/Distribucion/PorcPagoDto';
|
||
|
|
import type { CreatePorcPagoDto } from '../../models/dtos/Distribucion/CreatePorcPagoDto';
|
||
|
|
import type { UpdatePorcPagoDto } from '../../models/dtos/Distribucion/UpdatePorcPagoDto';
|
||
|
|
|
||
|
|
const getPorcentajesPorPublicacion = async (idPublicacion: number): Promise<PorcPagoDto[]> => {
|
||
|
|
const response = await apiClient.get<PorcPagoDto[]>(`/publicaciones/${idPublicacion}/porcentajespago`);
|
||
|
|
return response.data;
|
||
|
|
};
|
||
|
|
|
||
|
|
// getPorcPagoById no es estrictamente necesario para el CRUD dentro de la página de una publicación,
|
||
|
|
// pero podría ser útil para una edición muy específica o si se accede directamente.
|
||
|
|
const getPorcPagoById = async (idPublicacion: number, idPorcentaje: number): Promise<PorcPagoDto> => {
|
||
|
|
const response = await apiClient.get<PorcPagoDto>(`/publicaciones/${idPublicacion}/porcentajespago/${idPorcentaje}`);
|
||
|
|
return response.data;
|
||
|
|
};
|
||
|
|
|
||
|
|
const createPorcPago = async (idPublicacion: number, data: CreatePorcPagoDto): Promise<PorcPagoDto> => {
|
||
|
|
const response = await apiClient.post<PorcPagoDto>(`/publicaciones/${idPublicacion}/porcentajespago`, data);
|
||
|
|
return response.data;
|
||
|
|
};
|
||
|
|
|
||
|
|
const updatePorcPago = async (idPublicacion: number, idPorcentaje: number, data: UpdatePorcPagoDto): Promise<void> => {
|
||
|
|
await apiClient.put(`/publicaciones/${idPublicacion}/porcentajespago/${idPorcentaje}`, data);
|
||
|
|
};
|
||
|
|
|
||
|
|
const deletePorcPago = async (idPublicacion: number, idPorcentaje: number): Promise<void> => {
|
||
|
|
await apiClient.delete(`/publicaciones/${idPublicacion}/porcentajespago/${idPorcentaje}`);
|
||
|
|
};
|
||
|
|
|
||
|
|
const porcPagoService = {
|
||
|
|
getPorcentajesPorPublicacion,
|
||
|
|
getPorcPagoById,
|
||
|
|
createPorcPago,
|
||
|
|
updatePorcPago,
|
||
|
|
deletePorcPago,
|
||
|
|
};
|
||
|
|
|
||
|
|
export default porcPagoService;
|