41 lines
1.8 KiB
TypeScript
41 lines
1.8 KiB
TypeScript
|
|
import apiClient from '../apiClient';
|
||
|
|
import type { PubliSeccionDto } from '../../models/dtos/Distribucion/PubliSeccionDto';
|
||
|
|
import type { CreatePubliSeccionDto } from '../../models/dtos/Distribucion/CreatePubliSeccionDto';
|
||
|
|
import type { UpdatePubliSeccionDto } from '../../models/dtos/Distribucion/UpdatePubliSeccionDto';
|
||
|
|
|
||
|
|
const getSeccionesPorPublicacion = async (idPublicacion: number, soloActivas?: boolean): Promise<PubliSeccionDto[]> => {
|
||
|
|
const params: Record<string, boolean> = {};
|
||
|
|
if (soloActivas !== undefined) {
|
||
|
|
params.soloActivas = soloActivas;
|
||
|
|
}
|
||
|
|
const response = await apiClient.get<PubliSeccionDto[]>(`/publicaciones/${idPublicacion}/secciones`, { params });
|
||
|
|
return response.data;
|
||
|
|
};
|
||
|
|
|
||
|
|
const getPubliSeccionById = async (idPublicacion: number, idSeccion: number): Promise<PubliSeccionDto> => {
|
||
|
|
const response = await apiClient.get<PubliSeccionDto>(`/publicaciones/${idPublicacion}/secciones/${idSeccion}`);
|
||
|
|
return response.data;
|
||
|
|
};
|
||
|
|
|
||
|
|
const createPubliSeccion = async (idPublicacion: number, data: CreatePubliSeccionDto): Promise<PubliSeccionDto> => {
|
||
|
|
const response = await apiClient.post<PubliSeccionDto>(`/publicaciones/${idPublicacion}/secciones`, data);
|
||
|
|
return response.data;
|
||
|
|
};
|
||
|
|
|
||
|
|
const updatePubliSeccion = async (idPublicacion: number, idSeccion: number, data: UpdatePubliSeccionDto): Promise<void> => {
|
||
|
|
await apiClient.put(`/publicaciones/${idPublicacion}/secciones/${idSeccion}`, data);
|
||
|
|
};
|
||
|
|
|
||
|
|
const deletePubliSeccion = async (idPublicacion: number, idSeccion: number): Promise<void> => {
|
||
|
|
await apiClient.delete(`/publicaciones/${idPublicacion}/secciones/${idSeccion}`);
|
||
|
|
};
|
||
|
|
|
||
|
|
const publiSeccionService = {
|
||
|
|
getSeccionesPorPublicacion,
|
||
|
|
getPubliSeccionById,
|
||
|
|
createPubliSeccion,
|
||
|
|
updatePubliSeccion,
|
||
|
|
deletePubliSeccion,
|
||
|
|
};
|
||
|
|
|
||
|
|
export default publiSeccionService;
|