Skip to content

Commit

Permalink
Added overload to getAccount which takes an ID
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Nov 5, 2023
1 parent e095852 commit ad7f0f8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const account_endpoint = 'account';
*/
export type AccountAction = 'get' | 'set' | 'create' | 'delete' | 'login' | 'logout';

export const accountAttributes = ['id', 'username', 'email', 'oplvl', 'lastchange', 'created', 'disabled', 'token', 'session'] as const;

/**
* The account's level of access and status
*/
Expand Down Expand Up @@ -201,12 +203,17 @@ export async function deleteAccount(id: string, reason?: string): Promise<void>
}

/**
* Requests info about an account
* Gets info about an account
* @param id the account's id
* @param key the key to identify the account with (e.g. id)
* @param value the value of the key (e.g. the account's id)
* @returns The account's data
*/
export async function getAccount(key: string, value: string): Promise<Account> {
export async function getAccount(id: string): Promise<Account>;
export async function getAccount(key: string, value?: string): Promise<Account> {
if(!(key in accountAttributes)) {
[key, value] = ['id', key];
}
checkAccountAttribute(key as keyof FullAccount, value);
const result = await request<AccountResult>('GET', account_endpoint, { action: 'get', [key]: value });
return parseAccount(result);
Expand Down

0 comments on commit ad7f0f8

Please sign in to comment.