@@ -6,18 +6,18 @@ import { Config } from '../../../tools/types';
6
6
7
7
async function Post ( req : NextApiRequest , res : NextApiResponse ) {
8
8
// Parse req.body as a ServiceItem
9
- const serviceId = req . body ;
9
+ const { id } = req . body ;
10
+ const { type } = req . query ;
10
11
const configName = getCookie ( 'config-name' , { req } ) ;
11
12
const { config } : { config : Config } = getConfig ( configName ?. toString ( ) ?? 'default' ) . props ;
12
13
// 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 ) ;
14
15
if ( ! service ) {
15
16
return res . status ( 500 ) . json ( {
16
17
statusCode : 500 ,
17
18
message : 'Missing service' ,
18
19
} ) ;
19
20
}
20
- const { type } = req . query ;
21
21
22
22
const nextMonth = new Date ( new Date ( ) . setMonth ( new Date ( ) . getMonth ( ) + 2 ) ) . toISOString ( ) ;
23
23
const lastMonth = new Date ( new Date ( ) . setMonth ( new Date ( ) . getMonth ( ) - 2 ) ) . toISOString ( ) ;
@@ -62,10 +62,10 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
62
62
origin = origin . slice ( 0 , - 1 ) ;
63
63
}
64
64
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 ) ) ;
69
69
// // Make a request to the URL
70
70
// const response = await axios.get(url);
71
71
// // Return the response
0 commit comments