File tree Expand file tree Collapse file tree 6 files changed +35
-35
lines changed Expand file tree Collapse file tree 6 files changed +35
-35
lines changed Original file line number Diff line number Diff line change @@ -228,7 +228,7 @@ describe('AccountHttp', () => {
228228 describe ( 'transactions' , ( ) => {
229229 it ( 'should call transactions successfully by type' , async ( ) => {
230230 const transactions = await accountRepository . getAccountTransactions (
231- publicAccount . address , new QueryParams ( ) , new TransactionFilter ( ) . setType ( [ TransactionType . TRANSFER ] ) ) . toPromise ( ) ;
231+ publicAccount . address , new QueryParams ( ) , new TransactionFilter ( { types : [ TransactionType . TRANSFER ] } ) ) . toPromise ( ) ;
232232 expect ( transactions . length ) . to . be . greaterThan ( 0 ) ;
233233 transactions . forEach ( ( t ) => {
234234 expect ( t . type ) . to . be . eq ( TransactionType . TRANSFER ) ;
Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ describe('BlockHttp', () => {
112112
113113 it ( 'should return block transactions data given height with paginated transactionId' , async ( ) => {
114114 const transactions = await blockRepository . getBlockTransactions ( UInt64 . fromUint ( 1 ) ,
115- new QueryParams ( ) . setPageSize ( 10 ) . setId ( nextId ) ) . toPromise ( ) ;
115+ new QueryParams ( { pageSize : 10 , id : nextId } ) ) . toPromise ( ) ;
116116 expect ( transactions [ 0 ] . transactionInfo ! . id ) . to . be . equal ( firstId ) ;
117117 expect ( transactions . length ) . to . be . greaterThan ( 0 ) ;
118118 } ) ;
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ export abstract class Http {
5959
6060 transactionFilter ( filter ?: TransactionFilter ) : any {
6161 return {
62- type : filter ? filter . convertCSV ( filter . type ) : undefined ,
62+ type : filter ? filter . convertCSV ( filter . types ) : undefined ,
6363 } ;
6464 }
6565
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ export class QueryParams {
4848 public id ?: string ;
4949
5050 /**
51- * Creates an instance of QueryParams.
51+ * Constructor
5252 * @param {{
5353 * pageSize?: number,
5454 * order?: Order,
@@ -62,23 +62,21 @@ export class QueryParams {
6262 } ) {
6363 if ( args ) {
6464 if ( args . pageSize ) this . setPageSize ( args . pageSize )
65- if ( args . order ) this . setOrder ( Order [ args . order ] )
66- if ( args . id ) this . setId ( args . id )
65+ if ( args . order ) this . order = args . order
66+ if ( args . id ) this . id = args . id
6767 }
6868 }
6969
70- public setPageSize ( pageSize : number ) : QueryParams {
71- this . pageSize = ( pageSize >= 10 && pageSize <= 100 ) ? pageSize : 10 ;
72- return this ;
73- }
74-
75- public setId ( id ?: string ) : QueryParams {
76- this . id = id ;
77- return this ;
78- }
79-
80- public setOrder ( order : Order = Order . DESC ) : QueryParams {
81- this . order = order ;
82- return this ;
70+ /**
71+ * Set page size
72+ * @private
73+ * @param {number } [pageSize]
74+ * @returns {void }
75+ */
76+ private setPageSize ( pageSize ?: number ) : void {
77+ if ( pageSize && pageSize > 100 ) {
78+ throw new Error ( 'The page size has to be between 10 and 100' )
79+ }
80+ this . pageSize = pageSize || 10
8381 }
8482}
Original file line number Diff line number Diff line change 1515 */
1616
1717import { TransactionType } from '../model/transaction/TransactionType' ;
18- import { QueryParams } from './QueryParams' ;
1918
2019/**
2120 * The Transaction filter class
@@ -24,27 +23,29 @@ export class TransactionFilter {
2423 /**
2524 * Transaction type list
2625 */
27- public type ?: TransactionType [ ] ;
26+ readonly types ?: TransactionType [ ] ;
27+
2828 /**
2929 * Constructor
30+ * @param {{
31+ * type: TransactionType[],
32+ * }} [args]
3033 */
31- constructor ( ) {
32- }
33-
34- public setType ( type ?: TransactionType [ ] ) : TransactionFilter {
35- this . type = type ;
36- return this ;
34+ constructor ( args ?: {
35+ types ?: TransactionType [ ] ,
36+ } ) {
37+ if ( args && args . types ) this . types = args . types
3738 }
3839
3940 /**
40- * Return comma seperated list
41- * @param type Transaction type list
41+ * Return comma separated list
42+ * @param types Transaction type list
4243 */
43- public convertCSV ( type ?: TransactionType [ ] ) : string | undefined {
44- if ( ! type || type . length === 0 ) {
44+ public convertCSV ( types ?: TransactionType [ ] ) : string | undefined {
45+ if ( ! types || types . length === 0 ) {
4546 return undefined ;
4647 } else {
47- return type . map ( ( t ) => t . valueOf ( ) . toString ( ) ) . join ( ',' ) ;
48+ return types . map ( ( t ) => t . valueOf ( ) . toString ( ) ) . join ( ',' ) ;
4849 }
4950 }
5051}
Original file line number Diff line number Diff line change @@ -20,9 +20,10 @@ import { TransactionType } from '../../src/model/transaction/TransactionType';
2020
2121describe ( 'TransactionFilter' , ( ) => {
2222 it ( 'should return correct query param' , ( ) => {
23- const param = new TransactionFilter ( )
24- . setType ( [ TransactionType . TRANSFER , TransactionType . ACCOUNT_LINK ] ) ;
23+ const param = new TransactionFilter ( {
24+ types : [ TransactionType . TRANSFER , TransactionType . ACCOUNT_LINK ] ,
25+ } )
2526
26- expect ( param . convertCSV ( param . type ) ) . to . be . equal ( '16724,16716' ) ;
27+ expect ( param . convertCSV ( param . types ) ) . to . be . equal ( '16724,16716' ) ;
2728 } ) ;
2829} ) ;
You can’t perform that action at this time.
0 commit comments