Skip to content

Commit 81c2a9c

Browse files
axshaniilyamerman
andauthored
added BaseListParams interface that extends UnimplementedFields (#155)
added new filters to ListParams every ListParams extends BaseListParams Co-authored-by: Ilya Merman <[email protected]>
1 parent 28da86c commit 81c2a9c

16 files changed

+248
-241
lines changed

resources/account.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Include, UnitResponse, UnitConfig} from "../types/common"
1+
import {Include, UnitResponse, UnitConfig, BaseListParams} from "../types/common"
22
import {Customer} from "../types/customer"
33
import {
44
CreateAccountRequest,
@@ -47,14 +47,19 @@ export class Accounts extends BaseResource {
4747
}
4848

4949
public async list(params?: AccountListParams): Promise<UnitResponse<Account[]> & Include<Customer[]>> {
50-
const parameters = {
51-
"page[limit]": (params?.limit ? params?.limit : 100),
52-
"page[offset]": (params?.offset ? params?.offset : 0),
53-
...(params?.customerId && {"filter[customerId]": params?.customerId}),
54-
...(params?.tags && {"filter[tags]": params?.tags}),
55-
...(params?.include && {"include": params?.include}),
50+
const parameters: any = {
51+
"page[limit]": (params?.limit ? params.limit : 100),
52+
"page[offset]": (params?.offset ? params.offset : 0),
53+
...(params?.customerId && {"filter[customerId]": params.customerId}),
54+
...(params?.tags && {"filter[tags]": params.tags}),
55+
...(params?.include && {"include": params.include}),
5656
}
5757

58+
if (params?.status)
59+
params.status.forEach((s, idx) => {
60+
parameters[`filter[status][${idx}]`] = s
61+
})
62+
5863
return this.httpGet<UnitResponse<Account[]> & Include<Customer[]>>("", {params: parameters})
5964
}
6065

@@ -71,19 +76,7 @@ export class Accounts extends BaseResource {
7176
}
7277
}
7378

74-
export interface AccountListParams {
75-
/**
76-
* Maximum number of resources that will be returned. Maximum is 1000 resources. [See Pagination](https://developers.unit.co/#intro-pagination).
77-
* default: 100
78-
*/
79-
limit?: number
80-
81-
/**
82-
* Number of resources to skip. [See Pagination](https://developers.unit.co/#intro-pagination).
83-
* default: 0
84-
*/
85-
offset?: number
86-
79+
export interface AccountListParams extends BaseListParams {
8780
/**
8881
* Optional. Filters the results by the specified customer id.
8982
* default: empty
@@ -96,6 +89,11 @@ export interface AccountListParams {
9689
*/
9790
tags?: object
9891

92+
/**
93+
* Optional. Filter Account by its status (Open, Frozen, or Closed). Usage example: filter[status][0]=Closed
94+
*/
95+
status?: string[]
96+
9997
/**
10098
* Optional. Related resource available to include: customer. See [Getting Related Resources](https://developers.unit.co/#intro-getting-related-resources).
10199
* default: empty

resources/application.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Application, ApplicationDocument, CreateApplicationRequest, PatchApplicationRequest, UploadDocumentRequest } from "../types/application"
2-
import { UnitResponse, Include, UnitConfig } from "../types/common"
2+
import { UnitResponse, Include, UnitConfig, BaseListParams } from "../types/common"
33
import { BaseResource } from "./baseResource"
44

55
export class Applications extends BaseResource {
@@ -69,19 +69,7 @@ export class Applications extends BaseResource {
6969
}
7070
}
7171

72-
export interface ApplicationListParams {
73-
/**
74-
* Maximum number of resources that will be returned. Maximum is 1000 resources. [See Pagination](https://developers.unit.co/#intro-pagination).
75-
* default: 100
76-
*/
77-
limit?: number
78-
79-
/**
80-
* Number of resources to skip. [See Pagination](https://developers.unit.co/#intro-pagination).
81-
* default: 0
82-
*/
83-
offset?: number
84-
72+
export interface ApplicationListParams extends BaseListParams {
8573
/**
8674
* Optional. Search term according to the Full-Text Search Rules.
8775
* default: empty

resources/authorization.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ export class Authorizations extends BaseResource {
2222
...(params?.since && { "filter[since]": params.since }),
2323
...(params?.until && { "filter[until]": params.until }),
2424
...(params?.includeNonAuthorized && { "filter[includeNonAuthorized]": params.includeNonAuthorized }),
25-
...(params?.sort && { "sort": params.sort })
25+
...(params?.sort && { "sort": params.sort }),
26+
...(params?.toAmount && { "filter[toAmount]": params.toAmount }),
27+
...(params?.fromAmount && { "filter[fromAmount]": params.fromAmount })
2628
}
2729

28-
if (params?.status)
29-
params.status.forEach((s, idx) => {
30-
parameters[`filter[status][${idx}]`] = s
30+
if (params?.merchantCategoryCode)
31+
params.merchantCategoryCode.forEach((mcc, idx) => {
32+
parameters[`filter[merchantCategoryCode][${idx}]`] = mcc
3133
})
3234

3335
return this.httpGet<UnitResponse<Authorization[]> & Meta>("", { params: parameters })
@@ -89,4 +91,19 @@ export interface AuthorizationQueryParams {
8991
* Optional. Leave empty or provide sort=createdAt for ascending order. Provide sort=-createdAt (leading minus sign) for descending order.
9092
*/
9193
sort?: string
94+
95+
/**
96+
* Optional. Filter result by their 4-digit ISO 18245 merchant category code (MCC).
97+
*/
98+
merchantCategoryCode?: number[]
99+
100+
/**
101+
* Optional. Filters the result that have an amount that is higher or equal to the specified amount (in cents). e.g. 5000
102+
*/
103+
fromAmount?: number
104+
105+
/**
106+
* Optional. Filters the result that have an amount that is lower or equal to the specified amount (in cents). e.g. 7000
107+
*/
108+
toAmount?: number
92109
}

resources/authorizationRequest.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@ export class AuthorizationRequests extends BaseResource {
1818
}
1919

2020
public async list(params?: AuthorizationRequestQueryParams): Promise<UnitResponse<PurchaseAuthorizationRequest[]>> {
21-
const parameters = {
22-
"page[limit]": (params?.limit ? params?.limit : 100),
23-
"page[offset]": (params?.offset ? params?.offset : 0),
24-
...(params?.accountId && { "filter[accountId]": params?.accountId }),
25-
...(params?.customerId && { "filter[customerId]": params?.customerId })
21+
const parameters: any = {
22+
"page[limit]": (params?.limit ? params.limit : 100),
23+
"page[offset]": (params?.offset ? params.offset : 0),
24+
...(params?.accountId && { "filter[accountId]": params.accountId }),
25+
...(params?.customerId && { "filter[customerId]": params.customerId }),
26+
...(params?.toAmount && { "filter[toAmount]": params.toAmount }),
27+
...(params?.fromAmount && { "filter[fromAmount]": params.fromAmount })
2628
}
2729

30+
if (params?.merchantCategoryCode)
31+
params.merchantCategoryCode.forEach((mcc, idx) => {
32+
parameters[`filter[merchantCategoryCode][${idx}]`] = mcc
33+
})
34+
2835
return this.httpGet<UnitResponse<PurchaseAuthorizationRequest[]>>("", { params: parameters })
2936
}
3037

@@ -75,4 +82,19 @@ interface AuthorizationRequestQueryParams {
7582
* default: empty
7683
*/
7784
customerId?: string
85+
86+
/**
87+
* Optional. Filter result by their 4-digit ISO 18245 merchant category code (MCC).
88+
*/
89+
merchantCategoryCode?: number[]
90+
91+
/**
92+
* Optional. Filters the result that have an amount that is higher or equal to the specified amount (in cents). e.g. 5000
93+
*/
94+
fromAmount?: number
95+
96+
/**
97+
* Optional. Filters the result that have an amount that is lower or equal to the specified amount (in cents). e.g. 7000
98+
*/
99+
toAmount?: number
78100
}

resources/cards.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Card, CardLimits, CreateDebitCardRequest, PinStatus, ReplaceCardRequest } from "../types/cards"
2-
import { Include, UnitConfig, UnitResponse } from "../types/common"
2+
import { BaseListParams, Include, UnitConfig, UnitResponse } from "../types/common"
33
import { Customer } from "../types/customer"
44
import { Account } from "../types/account"
55
import { BaseResource } from "./baseResource"
@@ -56,14 +56,19 @@ export class Cards extends BaseResource {
5656
}
5757

5858
public async list(params?: CardListParams): Promise<UnitResponse<Card[]> & Include<Account[] | Customer[]>> {
59-
const parameters = {
60-
"page[limit]": (params?.limit ? params?.limit : 100),
61-
"page[offset]": (params?.offset ? params?.offset : 0),
62-
...(params?.accountId && { "filter[accountId]": params?.accountId }),
63-
...(params?.customerId && { "filter[customerId]": params?.customerId }),
64-
...(params?.include && { "include": params?.include })
59+
const parameters: any = {
60+
"page[limit]": (params?.limit ? params.limit : 100),
61+
"page[offset]": (params?.offset ? params.offset : 0),
62+
...(params?.accountId && { "filter[accountId]": params.accountId }),
63+
...(params?.customerId && { "filter[customerId]": params.customerId }),
64+
...(params?.include && { "include": params.include })
6565
}
6666

67+
if (params?.status)
68+
params.status.forEach((s, idx) => {
69+
parameters[`filter[status][${idx}]`] = s
70+
})
71+
6772
return this.httpGet<UnitResponse<Card[]> & Include<Account[] | Customer[]>>("", { params: parameters })
6873
}
6974

@@ -78,19 +83,7 @@ export class Cards extends BaseResource {
7883
}
7984
}
8085

81-
export interface CardListParams {
82-
/**
83-
* Maximum number of resources that will be returned. Maximum is 1000 resources. See Pagination.
84-
* default: 100
85-
*/
86-
limit?: number
87-
88-
/**
89-
* Number of resources to skip. See Pagination.
90-
* default: 0
91-
*/
92-
offset?: number
93-
86+
export interface CardListParams extends BaseListParams {
9487
/**
9588
* Optional. Filters the results by the specified account id.
9689
* default: empty
@@ -108,4 +101,9 @@ export interface CardListParams {
108101
* default: empty
109102
*/
110103
include?: string
104+
105+
/**
106+
* Optional. Filter customers by status (Active, Archived). Usage example: *filter[status][0]=Active
107+
*/
108+
status?: string[]
111109
}

resources/checkDeposit.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Account, Customer, Transaction } from "../types"
22
import { CheckDeposit, CreateCheckDepositRequest, PatchCheckDepositRequest, UploadCheckDepositRequest } from "../types/checkDeposit"
3-
import { UnitResponse, Include, UnitConfig } from "../types/common"
3+
import { UnitResponse, Include, UnitConfig, BaseListParams } from "../types/common"
44
import { BaseResource } from "./baseResource"
55

66
export class CheckDeposits extends BaseResource {
@@ -46,19 +46,7 @@ export class CheckDeposits extends BaseResource {
4646
}
4747
}
4848

49-
export interface CheckDepositListParams {
50-
/**
51-
* Maximum number of resources that will be returned. Maximum is 1000 resources. [See Pagination](https://developers.unit.co/#intro-pagination).
52-
* default: 100
53-
*/
54-
limit?: number
55-
56-
/**
57-
* Number of resources to skip. [See Pagination](https://developers.unit.co/#intro-pagination).
58-
* default: 0
59-
*/
60-
offset?: number
61-
49+
export interface CheckDepositListParams extends BaseListParams {
6250
/**
6351
* Optional. Filters the results by the specified account id.
6452
* default: empty

resources/counterparty.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UnitConfig, UnitResponse } from "../types/common"
1+
import { BaseListParams, UnitConfig, UnitResponse } from "../types/common"
22
import { AchCounterparty, CounterpartyBalance, CreateCounterpartyRequest, PatchCounterpartyRequest } from "../types/counterparty"
33
import { BaseResource } from "./baseResource"
44

@@ -24,7 +24,8 @@ export class Counterparties extends BaseResource {
2424
const parameters = {
2525
"page[limit]": (params?.limit ? params?.limit : 100),
2626
"page[offset]": (params?.offset ? params?.offset : 0),
27-
...(params?.customerId && { "filter[customerId]": params?.customerId })
27+
...(params?.customerId && { "filter[customerId]": params?.customerId }),
28+
...(params?.tags && { "filter[tags]": params?.tags }),
2829
}
2930

3031
return this.httpGet<UnitResponse<AchCounterparty[]>>("", { params: parameters })
@@ -39,22 +40,15 @@ export class Counterparties extends BaseResource {
3940
}
4041
}
4142

42-
export interface CounterpartyListParams {
43-
/**
44-
* Maximum number of resources that will be returned. Maximum is 1000 resources. See Pagination.
45-
* default: 100
46-
*/
47-
limit?: number
48-
49-
/**
50-
* Number of resources to skip. See Pagination.
51-
* default: 0
52-
*/
53-
offset?: number
54-
43+
export interface CounterpartyListParams extends BaseListParams {
5544
/**
5645
* Optional. Filters the results by the specified customer id.
5746
* default: empty
5847
*/
5948
customerId?: string
49+
50+
/**
51+
* Optional. Filter Counterparties by Tags.
52+
*/
53+
tags?: object
6054
}

resources/customer.ts

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

@@ -18,7 +18,7 @@ export class Customers extends BaseResource {
1818

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

21-
const parameters = {
21+
const parameters: any = {
2222
"page[limit]": (params?.limit ? params.limit : 100),
2323
"page[offset]": (params?.offset ? params.offset : 0),
2424
...(params?.query && { "filter[query]": params.query }),
@@ -27,23 +27,16 @@ export class Customers extends BaseResource {
2727
"sort": params?.sort ? params.sort : "-createdAt"
2828
}
2929

30+
if (params?.status)
31+
params.status.forEach((s, idx) => {
32+
parameters[`filter[status][${idx}]`] = s
33+
})
34+
3035
return this.httpGet<UnitResponse<Customer[]> & Meta>("", { params: parameters })
3136
}
3237
}
3338

34-
export interface CustomersListParams {
35-
/**
36-
* Maximum number of resources that will be returned. Maximum is 1000 resources. See Pagination.
37-
* default: 100
38-
*/
39-
limit?: number
40-
41-
/**
42-
* Number of resources to skip. See Pagination.
43-
* default: 0
44-
*/
45-
offset?: number
46-
39+
export interface CustomersListParams extends BaseListParams {
4740
/**
4841
* Optional. Search term according to the Full-Text Search Rules.
4942
* default: empty
@@ -62,6 +55,11 @@ export interface CustomersListParams {
6255
*/
6356
tags?: object
6457

58+
/**
59+
* Optional. Filter customers by status (Active, Archived). Usage example: *filter[status][0]=Active
60+
*/
61+
status?: string[]
62+
6563
/**
6664
* Optional. sort=createdAt for ascending order or sort=-createdAt (leading minus sign) for descending order.
6765
* default: sort=-createdAt

resources/events.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UnitConfig, UnitResponse } from "../types/common"
1+
import { BaseListParams, UnitConfig, UnitResponse } from "../types/common"
22
import { UnitEvent } from "../types/events"
33
import { BaseResource } from "./baseResource"
44

@@ -27,19 +27,7 @@ export class Events extends BaseResource {
2727
}
2828
}
2929

30-
export interface EventListParams {
31-
/**
32-
* Maximum number of resources that will be returned. Maximum is 1000 resources. See Pagination.
33-
* default: 100
34-
*/
35-
limit?: number
36-
37-
/**
38-
* Number of resources to skip. See Pagination.
39-
* default: 0
40-
*/
41-
offset?: number
42-
30+
export interface EventListParams extends BaseListParams {
4331
/**
4432
* Optional. Filter events by event type
4533
* default: empty

0 commit comments

Comments
 (0)