File tree Expand file tree Collapse file tree 5 files changed +2552
-7207
lines changed Expand file tree Collapse file tree 5 files changed +2552
-7207
lines changed Original file line number Diff line number Diff line change 13
13
"@windingtree/sdk-storage" : " workspace:*" ,
14
14
"@windingtree/sdk-messages" : " workspace:*" ,
15
15
"@windingtree/sdk-node-api" : " workspace:*" ,
16
+ "@windingtree/sdk-db" : " workspace:*" ,
16
17
"wtmp-examples-shared-files" : " workspace:*" ,
17
18
"eslint" : " ^8.45.0" ,
18
19
"eslint-config-react-app" : " ^7.0.1" ,
Original file line number Diff line number Diff line change 9
9
GenericQuery ,
10
10
} from '@windingtree/sdk-types' ;
11
11
import { centerEllipsis , formatBalance } from '@windingtree/sdk-react/utils' ;
12
+ import { PaginatedDealRecords } from '@windingtree/sdk-db' ;
12
13
13
14
/**
14
15
* Deals table
@@ -30,7 +31,7 @@ export const Deals = () => {
30
31
if ( ! node ) {
31
32
return ;
32
33
}
33
- const records = await node . deals . getAll . query ( { } ) ;
34
+ const { records } = await node . deals . getAll . query ( { } ) as PaginatedDealRecords ;
34
35
console . log ( 'Deals:' , records ) ;
35
36
setDeals ( records ) ;
36
37
} , [ node ] ) ;
@@ -88,6 +89,9 @@ export const Deals = () => {
88
89
</ tbody >
89
90
</ table >
90
91
</ div >
92
+
93
+ { message && < div style = { { marginTop : 20 } } > 🚨 { message } </ div > }
94
+ { error && < div style = { { marginTop : 20 } } > 🚨 { error } </ div > }
91
95
</ div >
92
96
) ;
93
97
} ;
Original file line number Diff line number Diff line change @@ -5,6 +5,11 @@ import { createLogger } from '@windingtree/sdk-logger';
5
5
6
6
const logger = createLogger ( 'DealsDb' ) ;
7
7
8
+ export interface PaginatedDealRecords extends Required < PaginationOptions > {
9
+ total : number ;
10
+ records : DealRecord [ ] ;
11
+ }
12
+
8
13
/**
9
14
* Interface defining the properties of a Deal.
10
15
*/
@@ -84,7 +89,7 @@ export class DealsDb {
84
89
* @returns {Promise<DealRecord[]> } Deals records
85
90
* @memberof DealsDb
86
91
*/
87
- getAll ( pagination ?: PaginationOptions ) : Promise < DealRecord [ ] > {
92
+ getAll ( pagination ?: PaginationOptions ) : Promise < PaginatedDealRecords > {
88
93
// eslint-disable-next-line @typescript-eslint/no-misused-promises, no-async-promise-executor
89
94
return new Promise ( async ( resolve , reject ) => {
90
95
try {
@@ -105,7 +110,11 @@ export class DealsDb {
105
110
cursor ++ ;
106
111
}
107
112
108
- resolve ( records ) ;
113
+ resolve ( {
114
+ ...page ,
115
+ total : cursor ,
116
+ records,
117
+ } ) ;
109
118
} catch ( error ) {
110
119
logger . error ( 'getAll' , error ) ;
111
120
reject ( error ) ;
Original file line number Diff line number Diff line change @@ -77,21 +77,24 @@ describe('DealsDb', () => {
77
77
it ( 'get all deal records from the storage' , async ( ) => {
78
78
const pagination = { start : 0 , skip : 10 } ;
79
79
const deals = await dealsDb . getAll ( pagination ) ;
80
- expect ( deals . length ) . toEqual ( pagination . skip ) ;
81
- deals . forEach ( ( d ) => {
80
+ expect ( deals . records . length ) . toEqual ( pagination . skip ) ;
81
+ deals . records . forEach ( ( d ) => {
82
82
const record = records . find ( ( r ) => r . offer . id === d . offer . id ) ;
83
83
expect ( record ) . to . be . deep . eq ( d ) ;
84
84
} ) ;
85
+ expect ( deals . total ) . to . be . equal ( records . length ) ;
86
+ expect ( deals . start ) . to . be . equal ( pagination . start ) ;
87
+ expect ( deals . skip ) . to . be . equal ( pagination . skip ) ;
85
88
} ) ;
86
89
87
90
it ( 'should return an empty array when no deals are found' , async ( ) => {
88
91
const deals = await dealsDb . getAll ( { start : 100 , skip : 10 } ) ;
89
- expect ( deals . length ) . toBe ( 0 ) ;
92
+ expect ( deals . records . length ) . toBe ( 0 ) ;
90
93
} ) ;
91
94
92
95
it ( 'should return all remaining deals when the skip count exceeds available deals' , async ( ) => {
93
96
const deals = await dealsDb . getAll ( { start : 5 , skip : 10 } ) ;
94
- expect ( deals . length ) . toBe ( 5 ) ;
97
+ expect ( deals . records . length ) . toBe ( 5 ) ;
95
98
} ) ;
96
99
} ) ;
97
100
} ) ;
You can’t perform that action at this time.
0 commit comments