2025-08-01 14:38:15 -03:00
|
|
|
import apiClient from '../apiClient';
|
|
|
|
|
import type { AjusteDto } from '../../models/dtos/Suscripciones/AjusteDto';
|
|
|
|
|
import type { CreateAjusteDto } from '../../models/dtos/Suscripciones/CreateAjusteDto';
|
2025-08-08 09:48:15 -03:00
|
|
|
import type { UpdateAjusteDto } from '../../models/dtos/Suscripciones/UpdateAjusteDto';
|
2025-08-01 14:38:15 -03:00
|
|
|
|
|
|
|
|
const API_URL_BY_SUSCRIPTOR = '/suscriptores';
|
|
|
|
|
const API_URL_BASE = '/ajustes';
|
|
|
|
|
|
2025-08-08 09:48:15 -03:00
|
|
|
const getAjustesPorSuscriptor = async (idSuscriptor: number, fechaDesde?: string, fechaHasta?: string): Promise<AjusteDto[]> => {
|
|
|
|
|
// URLSearchParams nos ayuda a construir la query string de forma segura y limpia
|
|
|
|
|
const params = new URLSearchParams();
|
|
|
|
|
if (fechaDesde) {
|
|
|
|
|
params.append('fechaDesde', fechaDesde);
|
|
|
|
|
}
|
|
|
|
|
if (fechaHasta) {
|
|
|
|
|
params.append('fechaHasta', fechaHasta);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Si hay parámetros, los añadimos a la URL. Si no, la URL queda limpia.
|
|
|
|
|
const queryString = params.toString();
|
|
|
|
|
const url = `${API_URL_BY_SUSCRIPTOR}/${idSuscriptor}/ajustes${queryString ? `?${queryString}` : ''}`;
|
|
|
|
|
|
|
|
|
|
const response = await apiClient.get<AjusteDto[]>(url);
|
2025-08-01 14:38:15 -03:00
|
|
|
return response.data;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const createAjusteManual = async (data: CreateAjusteDto): Promise<AjusteDto> => {
|
|
|
|
|
const response = await apiClient.post<AjusteDto>(API_URL_BASE, data);
|
|
|
|
|
return response.data;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const anularAjuste = async (idAjuste: number): Promise<void> => {
|
|
|
|
|
await apiClient.post(`${API_URL_BASE}/${idAjuste}/anular`);
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-08 09:48:15 -03:00
|
|
|
const updateAjuste = async (idAjuste: number, data: UpdateAjusteDto): Promise<void> => {
|
|
|
|
|
await apiClient.put(`${API_URL_BASE}/${idAjuste}`, data);
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-01 14:38:15 -03:00
|
|
|
export default {
|
|
|
|
|
getAjustesPorSuscriptor,
|
|
|
|
|
createAjusteManual,
|
2025-08-08 09:48:15 -03:00
|
|
|
anularAjuste,
|
|
|
|
|
updateAjuste,
|
2025-08-01 14:38:15 -03:00
|
|
|
};
|