Skip to content

Commit 460cee1

Browse files
axshaniilyamerman
andauthored
Meta data (#140)
* added meta data to list functions * lint-fix Co-authored-by: Ilya Merman <[email protected]>
1 parent b9b9d6c commit 460cee1

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

resources/authorization.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Authorization } from "../types/authorization"
2-
import { UnitConfig, UnitResponse } from "../types/common"
2+
import { Meta, UnitConfig, UnitResponse } from "../types/common"
33
import { BaseResource } from "./baseResource"
44

55
export class Authorizations extends BaseResource {
@@ -12,7 +12,7 @@ export class Authorizations extends BaseResource {
1212
return this.httpGet<UnitResponse<Authorization>>(`/${id}`)
1313
}
1414

15-
public async find(params?: AuthorizationQueryParams): Promise<UnitResponse<Authorization[]>> {
15+
public async find(params?: AuthorizationQueryParams): Promise<UnitResponse<Authorization[]> & Meta> {
1616
const parameters: any = {
1717
"page[limit]": (params?.limit ? params.limit : 100),
1818
"page[offset]": (params?.offset ? params.offset : 0),
@@ -30,7 +30,7 @@ export class Authorizations extends BaseResource {
3030
parameters[`filter[status][${idx}]`] = s
3131
})
3232

33-
return this.httpGet<UnitResponse<Authorization[]>>("", { params: parameters })
33+
return this.httpGet<UnitResponse<Authorization[]> & Meta>("", { params: parameters })
3434
}
3535
}
3636

resources/customer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UnitResponse, UnitConfig } from "../types/common"
1+
import { UnitResponse, UnitConfig, Meta } from "../types/common"
22
import { Customer, PatchCustomerRequest } from "../types/customer"
33
import { BaseResource } from "./baseResource"
44

@@ -16,7 +16,7 @@ export class Customers extends BaseResource {
1616
return this.httpGet<UnitResponse<Customer>>(`/${customerId}`)
1717
}
1818

19-
public async list(params?: CustomersListParams): Promise<UnitResponse<Customer[]>> {
19+
public async list(params?: CustomersListParams): Promise<UnitResponse<Customer[]> & Meta> {
2020

2121
const parameters = {
2222
"page[limit]": (params?.limit ? params.limit : 100),
@@ -27,7 +27,7 @@ export class Customers extends BaseResource {
2727
"sort": params?.sort ? params.sort : "-createdAt"
2828
}
2929

30-
return this.httpGet<UnitResponse<Customer[]>>("", { params: parameters })
30+
return this.httpGet<UnitResponse<Customer[]> & Meta>("", { params: parameters })
3131
}
3232
}
3333

resources/payments.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Account } from "../types/account"
2-
import { Include, UnitConfig, UnitResponse } from "../types/common"
2+
import { Include, Meta, UnitConfig, UnitResponse } from "../types/common"
33
import { Customer } from "../types/customer"
44
import { CreatePaymentRequest, PatchPaymentRequest, Payment } from "../types/payments"
55
import { Transaction } from "../types/transactions"
@@ -31,7 +31,7 @@ export class Payments extends BaseResource {
3131
return this.httpGet<UnitResponse<Payment & Include<Account[] | Customer[] | Transaction[]>>>(`/${id}`, { params })
3232
}
3333

34-
public async list(params?: PaymentListParams): Promise<UnitResponse<Payment[] & Include<Account[] | Customer[] | Transaction[]>>> {
34+
public async list(params?: PaymentListParams): Promise<UnitResponse<Payment[] & Include<Account[] | Customer[] | Transaction[]> & Meta>> {
3535
const parameters: any = {
3636
"page[limit]": (params?.limit ? params.limit : 100),
3737
"page[offset]": (params?.offset ? params.offset : 0),
@@ -59,7 +59,7 @@ export class Payments extends BaseResource {
5959
parameters[`filter[direction][${idx}]`] = d
6060
})
6161

62-
return this.httpGet<UnitResponse<Payment[] & Include<Account[] | Customer[] | Transaction[]>>>("", { params: parameters })
62+
return this.httpGet<UnitResponse<Payment[] & Include<Account[] | Customer[] | Transaction[]> & Meta>>("", { params: parameters })
6363
}
6464
}
6565

resources/transactions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Include, UnitConfig, UnitResponse } from "../types/common"
1+
import { Include, Meta, UnitConfig, UnitResponse } from "../types/common"
22
import { Customer } from "../types/customer"
33
import { Account } from "../types/account"
44
import { Transaction } from "../types/transactions"
@@ -28,7 +28,7 @@ export class Transactions extends BaseResource {
2828
return await this.httpGet<UnitResponse<Transaction> & Include<Account[] | Customer[]>>(`/accounts/${accountId}/transactions/${transactionId}`, { params: parameters })
2929
}
3030

31-
public async list(params?: TransactionListParams): Promise<UnitResponse<Transaction[]> & Include<Account[] | Customer[]>> {
31+
public async list(params?: TransactionListParams): Promise<UnitResponse<Transaction[]> & Include<Account[] | Customer[]> & Meta> {
3232
const parameters: any = {
3333
"page[limit]": (params?.limit ? params.limit : 100),
3434
"page[offset]": (params?.offset ? params.offset : 0),
@@ -49,7 +49,7 @@ export class Transactions extends BaseResource {
4949
parameters[`filter[type][${idx}]`] = t
5050
})
5151

52-
return await this.httpGet<UnitResponse<Transaction[]> & Include<Account[] | Customer[]>>("/transactions", { params: parameters })
52+
return await this.httpGet<UnitResponse<Transaction[]> & Include<Account[] | Customer[]> & Meta>("/transactions", { params: parameters })
5353
}
5454

5555
/**

types/common.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,19 @@ export interface Include<T> {
366366
included?: T
367367
}
368368

369+
export interface Meta extends UnimplementedFields {
370+
/**
371+
* JSON object that contains pagination data
372+
*/
373+
meta:{
374+
pagination: {
375+
total: number
376+
limit: number
377+
offset: number
378+
}
379+
}
380+
}
381+
369382
export interface UnitConfig {
370383
axios?: AxiosInstance
371384
}

0 commit comments

Comments
 (0)