import { Router } from 'express' ; import { formatDate , validateDate } from '../../../utils/dates' ; import { getDamnsInformation } from '../../../services/sabesp' ; import { mapV2 } from '../../../utils/mapper' ; import { logger } from '../../../utils/logger' ; const routesV2 = Router ( ) ; async function getMappedDataByDate ( date ) { const data = await getDamnsInformation ( date ) ; return mapV2 ( data ) ; } routesV2 . get ( '/' , async ( _req , res ) => { const today = formatDate ( new Date ( ) ) ; const data = await getMappedDataByDate ( today ) ; res . json ( data ) ; } ) ; routesV2 . get ( '/:date' , async ( req , res , next ) => { const { date } = req . params ; try { if ( date && validateDate ( date ) ) { const data = await getMappedDataByDate ( date ) ; res . json ( data ) ; } } catch ( err ) { logger . error ( err ) ; next ( err ) ; } } ) ; export { routesV2 } ;