Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/infrastructure/AccountHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ describe('AccountHttp', () => {
describe('transactions', () => {
it('should call transactions successfully by type', async () => {
const transactions = await accountRepository.getAccountTransactions(
publicAccount.address, new QueryParams(), new TransactionFilter().setType([TransactionType.TRANSFER])).toPromise();
publicAccount.address, new QueryParams(), new TransactionFilter({ types: [TransactionType.TRANSFER] })).toPromise();
expect(transactions.length).to.be.greaterThan(0);
transactions.forEach((t) => {
expect(t.type).to.be.eq(TransactionType.TRANSFER);
Expand Down
2 changes: 1 addition & 1 deletion e2e/infrastructure/BlockHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('BlockHttp', () => {

it('should return block transactions data given height with paginated transactionId', async () => {
const transactions = await blockRepository.getBlockTransactions(UInt64.fromUint(1),
new QueryParams().setPageSize(10).setId(nextId)).toPromise();
new QueryParams({ pageSize: 10, id: nextId})).toPromise();
expect(transactions[0].transactionInfo!.id).to.be.equal(firstId);
expect(transactions.length).to.be.greaterThan(0);
});
Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/Http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export abstract class Http {

transactionFilter(filter?: TransactionFilter): any {
return {
type: filter ? filter.convertCSV(filter.type) : undefined,
type: filter ? filter.convertCSV(filter.types) : undefined,
};
}

Expand Down
50 changes: 32 additions & 18 deletions src/infrastructure/QueryParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,49 @@ export class QueryParams {
* Page size between 10 and 100, otherwise 10
*/
public pageSize = 10;
/**
* Id after which we want objects to be returned
*/
public id?: string;
/**
* Order of transactions.
* DESC. Newer to older.
* ASC. Older to newer.
*/

public order: Order = Order.DESC;

/**
* Constructor
* Id after which we want objects to be returned
*/
constructor() {
}

public setPageSize(pageSize: number): QueryParams {
this.pageSize = (pageSize >= 10 && pageSize <= 100) ? pageSize : 10;
return this;
}
public id?: string;

public setId(id?: string): QueryParams {
this.id = id;
return this;
/**
* Constructor
* @param {{
* pageSize?: number,
* order?: Order,
* id?: string;
* }} configuration arguments
*/
constructor(args?: {
pageSize?: number,
order?: Order,
id?: string;
}) {
if (args) {
if (args.pageSize) this.setPageSize(args.pageSize)
if (args.order) this.order = args.order
if (args.id) this.id = args.id
}
}

public setOrder(order: Order = Order.DESC): QueryParams {
this.order = order;
return this;
/**
* Set page size
* @private
* @param {number} [pageSize]
* @returns {void}
*/
private setPageSize(pageSize?: number): void {
if (pageSize && pageSize > 100) {
throw new Error('The page size has to be between 10 and 100')
}
this.pageSize = pageSize || 10
}
}
27 changes: 14 additions & 13 deletions src/infrastructure/TransactionFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import { TransactionType } from '../model/transaction/TransactionType';
import { QueryParams } from './QueryParams';

/**
* The Transaction filter class
Expand All @@ -24,27 +23,29 @@ export class TransactionFilter {
/**
* Transaction type list
*/
public type?: TransactionType[];
readonly types?: TransactionType[];

/**
* Constructor
* @param {{
* type: TransactionType[],
* }} [args]
*/
constructor() {
}

public setType(type?: TransactionType[]): TransactionFilter {
this.type = type;
return this;
constructor(args?: {
types?: TransactionType[],
}) {
if (args && args.types) this.types = args.types
}

/**
* Return comma seperated list
* @param type Transaction type list
* Return comma separated list
* @param types Transaction type list
*/
public convertCSV(type?: TransactionType[]): string | undefined {
if (!type || type.length === 0) {
public convertCSV(types?: TransactionType[]): string | undefined {
if (!types || types.length === 0) {
return undefined;
} else {
return type.map((t) => t.valueOf().toString()).join(',');
return types.map((t) => t.valueOf().toString()).join(',');
}
}
}
7 changes: 4 additions & 3 deletions test/infrastructure/TransactionFilter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import { TransactionType } from '../../src/model/transaction/TransactionType';

describe('TransactionFilter', () => {
it('should return correct query param', () => {
const param = new TransactionFilter()
.setType([TransactionType.TRANSFER, TransactionType.ACCOUNT_LINK]);
const param = new TransactionFilter({
types: [TransactionType.TRANSFER, TransactionType.ACCOUNT_LINK],
})

expect(param.convertCSV(param.type)).to.be.equal('16724,16716');
expect(param.convertCSV(param.types)).to.be.equal('16724,16716');
});
});