Files
blitzkit/src/core/blitz/getTankStats.ts
T

20 lines
840 B
TypeScript
Raw Normal View History

import { REGION_NAMES, Region } from '../../constants/regions';
2023-09-23 21:51:00 +00:00
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
2023-09-19 15:52:39 +00:00
import { TankStats } from '../../types/tanksStats';
2023-07-11 19:54:57 +00:00
import throwError from '../node/throwError';
import getWargamingResponse from './getWargamingResponse';
2023-09-19 15:52:39 +00:00
export default async function getTankStats(region: Region, id: number) {
const tankStats = await getWargamingResponse<TankStats>(
2023-09-23 21:51:00 +00:00
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
);
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-09-19 15:52:39 +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_NAMES[region]} server.`,
2023-06-06 16:50:33 +00:00
);
}
return tankStats[id];
}