Exportar datos de osp de la db en un excel
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
TrainingSchema,
|
||||
trainingApiResponseSchema,
|
||||
} from '../schemas/training';
|
||||
import z from 'zod';
|
||||
|
||||
export const getTrainingStatisticsAction = async (
|
||||
params: {
|
||||
@@ -159,3 +160,39 @@ export const getTrainingByIdAction = async (id: number) => {
|
||||
|
||||
return response?.data;
|
||||
};
|
||||
|
||||
export const exportTrainingAction = async (
|
||||
params: {
|
||||
startDate?: string;
|
||||
endDate?: string;
|
||||
stateId?: number;
|
||||
municipalityId?: number;
|
||||
parishId?: number;
|
||||
ospType?: string;
|
||||
} = {},
|
||||
) => {
|
||||
const searchParams = new URLSearchParams();
|
||||
if (params.startDate) searchParams.append('startDate', params.startDate);
|
||||
if (params.endDate) searchParams.append('endDate', params.endDate);
|
||||
if (params.stateId) searchParams.append('stateId', params.stateId.toString());
|
||||
if (params.municipalityId)
|
||||
searchParams.append('municipalityId', params.municipalityId.toString());
|
||||
if (params.parishId)
|
||||
searchParams.append('parishId', params.parishId.toString());
|
||||
if (params.ospType) searchParams.append('ospType', params.ospType);
|
||||
|
||||
|
||||
const [error, response] = await safeFetchApi(
|
||||
z.any(), //Schema
|
||||
`/training/export/all?${searchParams.toString()}`,
|
||||
'GET',
|
||||
undefined,
|
||||
{ responseType: 'arraybuffer' },
|
||||
);
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.message || 'Error al exportar los datos');
|
||||
}
|
||||
|
||||
return Array.from(new Uint8Array(response));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user