const axios = require('../axios')

const atinaApi = process.env.ATINA_FE_API || '167.172.170.78';

module.exports = async (req, res) => {
    // Assuming the fechaDeEmision is provided as a query parameter
    const { fechaDeEmision } = req.query;
    const { jwttoken, entidad } = req.headers
    
    // Make a GET request to the consulta/ListaDE endpoint with dynamic fechaDeEmision
    return axios({
        method: 'get',
        headers: {
            jwttoken,
            entidad,
        },
        url: `https://${atinaApi}:8082/api/consulta/ListaDE?mode=FechaEmision&fechaDeEmision=${fechaDeEmision}`,
        
    }).then(response => {
        // Return the response from the API endpoint
        res.json(response.data);
    })
    .catch(error => {
        console.error(JSON.stringify(error.response.data));
        // Return any error that occurred during the request
        res.status(error.response.status).json({ ...error.response.data });
    });
}