Files
bunq/ts/bunq.classes.user.ts
Juergen Kunz 193524f15c update
2025-07-18 10:31:12 +00:00

177 lines
4.2 KiB
TypeScript

import * as plugins from './bunq.plugins';
import { BunqApiContext } from './bunq.classes.apicontext';
import { IBunqUser } from './bunq.interfaces';
export class BunqUser {
private apiContext: BunqApiContext;
constructor(apiContext: BunqApiContext) {
this.apiContext = apiContext;
}
/**
* Get current user information
*/
public async getInfo(): Promise<any> {
await this.apiContext.ensureValidSession();
const response = await this.apiContext.getHttpClient().get('/v1/user');
if (response.Response && response.Response[0]) {
return response.Response[0];
}
throw new Error('Failed to get user information');
}
/**
* List all users (usually returns just the current user)
*/
public async list(): Promise<any[]> {
await this.apiContext.ensureValidSession();
const response = await this.apiContext.getHttpClient().list('/v1/user');
return response.Response || [];
}
/**
* Update user information
*/
public async update(userId: number, updates: any): Promise<any> {
await this.apiContext.ensureValidSession();
const response = await this.apiContext.getHttpClient().put(
`/v1/user/${userId}`,
updates
);
return response.Response;
}
/**
* Get user by ID
*/
public async get(userId: number): Promise<any> {
await this.apiContext.ensureValidSession();
const response = await this.apiContext.getHttpClient().get(
`/v1/user/${userId}`
);
if (response.Response && response.Response[0]) {
return response.Response[0];
}
throw new Error('User not found');
}
/**
* Update notification filters for a user
*/
public async updateNotificationFilters(userId: number, filters: any[]): Promise<void> {
await this.apiContext.ensureValidSession();
await this.apiContext.getHttpClient().post(
`/v1/user/${userId}/notification-filter-url`,
{
notification_filters: filters
}
);
}
/**
* List notification filters
*/
public async listNotificationFilters(userId: number): Promise<any[]> {
await this.apiContext.ensureValidSession();
const response = await this.apiContext.getHttpClient().list(
`/v1/user/${userId}/notification-filter-url`
);
return response.Response || [];
}
/**
* Create a legal name for a user
*/
public async createLegalName(userId: number, legalName: string): Promise<any> {
await this.apiContext.ensureValidSession();
const response = await this.apiContext.getHttpClient().post(
`/v1/user/${userId}/legal-name`,
{
legal_name: legalName
}
);
return response.Response;
}
/**
* List legal names
*/
public async listLegalNames(userId: number): Promise<any[]> {
await this.apiContext.ensureValidSession();
const response = await this.apiContext.getHttpClient().list(
`/v1/user/${userId}/legal-name`
);
return response.Response || [];
}
/**
* Get user limits
*/
public async getLimits(userId: number): Promise<any[]> {
await this.apiContext.ensureValidSession();
const response = await this.apiContext.getHttpClient().list(
`/v1/user/${userId}/limit`
);
return response.Response || [];
}
/**
* Create or update a user avatar
*/
public async updateAvatar(userId: number, attachmentId: string): Promise<any> {
await this.apiContext.ensureValidSession();
const response = await this.apiContext.getHttpClient().post(
`/v1/user/${userId}/avatar`,
{
attachment_public_uuid: attachmentId
}
);
return response.Response;
}
/**
* Get user avatar
*/
public async getAvatar(userId: number): Promise<any> {
await this.apiContext.ensureValidSession();
const response = await this.apiContext.getHttpClient().get(
`/v1/user/${userId}/avatar`
);
return response.Response;
}
/**
* Delete user avatar
*/
public async deleteAvatar(userId: number): Promise<void> {
await this.apiContext.ensureValidSession();
await this.apiContext.getHttpClient().delete(
`/v1/user/${userId}/avatar`
);
}
}