@@ -6,18 +6,18 @@ import { Config } from '../../../tools/types';
66
77async function Post ( req : NextApiRequest , res : NextApiResponse ) {
88 // Parse req.body as a ServiceItem
9- const serviceId = req . body ;
9+ const { id } = req . body ;
10+ const { type } = req . query ;
1011 const configName = getCookie ( 'config-name' , { req } ) ;
1112 const { config } : { config : Config } = getConfig ( configName ?. toString ( ) ?? 'default' ) . props ;
1213 // Find service with serviceId in config
13- const service = config . services . find ( ( service ) => service . id === serviceId ) ;
14+ const service = config . services . find ( ( service ) => service . id === id ) ;
1415 if ( ! service ) {
1516 return res . status ( 500 ) . json ( {
1617 statusCode : 500 ,
1718 message : 'Missing service' ,
1819 } ) ;
1920 }
20- const { type } = req . query ;
2121
2222 const nextMonth = new Date ( new Date ( ) . setMonth ( new Date ( ) . getMonth ( ) + 2 ) ) . toISOString ( ) ;
2323 const lastMonth = new Date ( new Date ( ) . setMonth ( new Date ( ) . getMonth ( ) - 2 ) ) . toISOString ( ) ;
@@ -62,10 +62,10 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
6262 origin = origin . slice ( 0 , - 1 ) ;
6363 }
6464 const pined = `${ origin } ${ url ?. url } ?apiKey=${ service . apiKey } &end=${ nextMonth } &start=${ lastMonth } ` ;
65- const data = await axios . get (
66- `${ origin } ${ url ?. url } ?apiKey=${ service . apiKey } &end=${ nextMonth } &start=${ lastMonth } `
67- ) ;
68- return res . status ( 200 ) . json ( data . data ) ;
65+ return axios
66+ . get ( `${ origin } ${ url ?. url } ?apiKey=${ service . apiKey } &end=${ nextMonth } &start=${ lastMonth } ` )
67+ . then ( ( response ) => res . status ( 200 ) . json ( response . data ) )
68+ . catch ( ( e ) => res . status ( 500 ) . json ( e ) ) ;
6969 // // Make a request to the URL
7070 // const response = await axios.get(url);
7171 // // Return the response
0 commit comments