2023-06-03 01:19:52 +00:00
import { BLITZ_SERVERS , BlitzServer } from '../../constants/servers.js' ;
import { TanksStats } from '../../types/tanksStats.js' ;
2023-06-27 01:43:30 +00:00
import { WARGAMING_APPLICATION_ID } from '../node/args.js' ;
import errorWithCause from '../node/errorWithCause.js' ;
2023-06-03 01:19:52 +00:00
import getWargamingResponse from './getWargamingResponse.js' ;
2023-06-18 01:56:21 +00:00
export default async function getTankStats ( server : BlitzServer , 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-06 16:50:33 +00:00
throw errorWithCause (
'No tank stats available' ,
`Wargaming says there is no tank stats for this account. This account may not have any battles/tanks or exist in the ${ BLITZ_SERVERS [ server ] } server.` ,
);
2023-06-03 01:19:52 +00:00
}
return tankStats [ id ];
}