2023-10-12 13:00:33 -05:00
|
|
|
import { Region } from '../../constants/regions';
|
|
|
|
|
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
2023-10-20 10:50:54 -05:00
|
|
|
import fetchBlitz from './fetchBlitz';
|
2023-10-12 13:00:33 -05:00
|
|
|
import { normalizeIds } from './normalizeIds';
|
|
|
|
|
|
|
|
|
|
interface IndividualAccountAchievements {
|
|
|
|
|
achievements: {
|
|
|
|
|
[achievement: string]: number;
|
|
|
|
|
};
|
|
|
|
|
max_series: {
|
|
|
|
|
[achievement: string]: number;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface AccountAchievements {
|
|
|
|
|
[id: number]: IndividualAccountAchievements;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getAccountAchievements<
|
|
|
|
|
Ids extends number | number[],
|
|
|
|
|
ReturnType = Ids extends number
|
|
|
|
|
? IndividualAccountAchievements
|
|
|
|
|
: IndividualAccountAchievements[],
|
|
|
|
|
>(region: Region, ids: Ids) {
|
2023-10-14 10:58:48 -05:00
|
|
|
const object = await fetchBlitz<AccountAchievements>(
|
2023-10-12 13:00:33 -05:00
|
|
|
`https://api.wotblitz.${region}/wotb/account/achievements/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${normalizeIds(
|
|
|
|
|
ids,
|
|
|
|
|
)}`,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (typeof ids === 'number') {
|
|
|
|
|
return object[ids as number] as ReturnType;
|
|
|
|
|
} else {
|
|
|
|
|
return ids.map((id) => object[id]) as ReturnType;
|
|
|
|
|
}
|
|
|
|
|
}
|