2023-07-14 01:32:20 +00:00
import { REGION_DOMAIN_NAMES , RegionDomain } from '../../constants/regions' ;
2023-07-11 19:54:57 +00:00
import { TanksStats } from '../../types/tanksStats' ;
import { WARGAMING_APPLICATION_ID } from '../node/arguments' ;
import throwError from '../node/throwError' ;
import getWargamingResponse from './getWargamingResponse' ;
2023-06-03 01:19:52 +00:00
2023-07-14 01:32:20 +00:00
export default async function getTankStats ( server : RegionDomain , id : number ) {
2023-06-03 01:19:52 +00:00
const tankStats = await getWargamingResponse < TanksStats >(
2023-06-12 01:17:26 +00:00
`https://api.wotblitz. ${ server } /wotb/tanks/stats/?application_id= ${ WARGAMING_APPLICATION_ID } &account_id= ${ id } ` ,
2023-06-03 01:19:52 +00:00
);
if ( tankStats [ id ] === null ) {
2023-06-27 17:22:27 +00:00
throw throwError (
2023-06-06 16:50:33 +00:00
'No tank stats available' ,
2023-07-14 01:32:20 +00:00
`Wargaming says there is no tank stats for this account. This account may not have any battles/tanks or exist in the ${ REGION_DOMAIN_NAMES [ server ] } server.` ,
2023-06-06 16:50:33 +00:00
);
2023-06-03 01:19:52 +00:00
}
return tankStats [ id ];
}