feat(transactions): add full pagination support with older_id and custom count parameters
This commit is contained in:
@@ -111,18 +111,41 @@ export class BunqMonetaryAccount {
|
||||
|
||||
/**
|
||||
* gets all transactions on this account
|
||||
* @param options - Pagination options or a number for backward compatibility (treated as newer_id)
|
||||
*/
|
||||
public async getTransactions(startingIdArg: number | false = false): Promise<BunqTransaction[]> {
|
||||
const paginationOptions: IBunqPaginationOptions = {
|
||||
count: 200,
|
||||
newer_id: startingIdArg,
|
||||
public async getTransactions(options?: IBunqPaginationOptions | number | false): Promise<BunqTransaction[]> {
|
||||
let paginationOptions: IBunqPaginationOptions = {};
|
||||
|
||||
// Backward compatibility: if a number or false is passed, treat it as newer_id
|
||||
if (typeof options === 'number' || options === false) {
|
||||
paginationOptions.newer_id = options;
|
||||
} else if (options) {
|
||||
paginationOptions = { ...options };
|
||||
}
|
||||
|
||||
// Set default count if not specified
|
||||
if (!paginationOptions.count) {
|
||||
paginationOptions.count = 200;
|
||||
}
|
||||
|
||||
// Build clean pagination object - only include properties that are not false/undefined
|
||||
const cleanPaginationOptions: IBunqPaginationOptions = {
|
||||
count: paginationOptions.count,
|
||||
};
|
||||
|
||||
if (paginationOptions.newer_id !== undefined && paginationOptions.newer_id !== false) {
|
||||
cleanPaginationOptions.newer_id = paginationOptions.newer_id;
|
||||
}
|
||||
|
||||
if (paginationOptions.older_id !== undefined && paginationOptions.older_id !== false) {
|
||||
cleanPaginationOptions.older_id = paginationOptions.older_id;
|
||||
}
|
||||
|
||||
await this.bunqAccountRef.apiContext.ensureValidSession();
|
||||
|
||||
const response = await this.bunqAccountRef.getHttpClient().list(
|
||||
`/v1/user/${this.bunqAccountRef.userId}/monetary-account/${this.id}/payment`,
|
||||
paginationOptions
|
||||
cleanPaginationOptions
|
||||
);
|
||||
|
||||
const transactionsArray: BunqTransaction[] = [];
|
||||
|
Reference in New Issue
Block a user