Skip to content

Commit 10067f7

Browse files
Bluedot-DevEmre
andauthored
Freeze and unfreeze account requests is added to accounts (#112)
* Freeze and unfreeze account requests is added to accounts Freeze and unfreeze account request are added to account.ts. FreezeAccount type is also added to types. * Requested changes is implemented Co-authored-by: Emre <[email protected]>
1 parent 141c3d8 commit 10067f7

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

resources/account.ts

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
import { Include, UnitResponse, UnitConfig } from "../types/common"
2-
import { Customer } from "../types/customer"
3-
import { CreateAccountRequest, Account, PatchAccountRequest, AccountLimits, AccountDepositProduct, CloseAccountRequest } from "../types/account"
4-
import { BaseResource } from "./baseResource"
1+
import {Include, UnitResponse, UnitConfig} from "../types/common"
2+
import {Customer} from "../types/customer"
3+
import {
4+
CreateAccountRequest,
5+
Account,
6+
PatchAccountRequest,
7+
AccountLimits,
8+
AccountDepositProduct,
9+
CloseAccountRequest,
10+
FreezeAccountRequest
11+
} from "../types/account"
12+
import {BaseResource} from "./baseResource"
513

614
export class Accounts extends BaseResource {
715

@@ -10,7 +18,7 @@ export class Accounts extends BaseResource {
1018
}
1119

1220
public async create(request: CreateAccountRequest): Promise<UnitResponse<Account>> {
13-
return this.httpPost<UnitResponse<Account>>("", { data: request })
21+
return this.httpPost<UnitResponse<Account>>("", {data: request})
1422
}
1523

1624
public async closeAccount(request: CloseAccountRequest): Promise<UnitResponse<Account>> {
@@ -21,29 +29,37 @@ export class Accounts extends BaseResource {
2129
return this.httpPost<UnitResponse<Account>>(`/${accountId}/reopen`)
2230
}
2331

32+
public async freezeAccount(request: FreezeAccountRequest): Promise<UnitResponse<Account>> {
33+
return this.httpPost<UnitResponse<Account>>(`/${request.accountId}/freeze`, {data: request.data})
34+
}
35+
36+
public async unfreezeAccount(accountId: string): Promise<UnitResponse<Account>> {
37+
return this.httpPost<UnitResponse<Account>>(`/${accountId}/unfreeze`)
38+
}
39+
2440
/**
2541
* Include is Optional. Related resource available to include: customer. See [Getting Related Resources](https://developers.unit.co/#intro-getting-related-resources)
2642
* @param id
2743
* @param include
2844
*/
2945
public async get(id: string, include = ""): Promise<UnitResponse<Account> & Include<Customer>> {
30-
return this.httpGet<UnitResponse<Account> & Include<Customer>>(`/${id}`, { params: { include } })
46+
return this.httpGet<UnitResponse<Account> & Include<Customer>>(`/${id}`, {params: {include}})
3147
}
3248

3349
public async list(params?: AccountListParams): Promise<UnitResponse<Account[]> & Include<Customer[]>> {
3450
const parameters = {
3551
"page[limit]": (params?.limit ? params?.limit : 100),
3652
"page[offset]": (params?.offset ? params?.offset : 0),
37-
...(params?.customerId && { "filter[customerId]": params?.customerId }),
38-
...(params?.tags && { "filter[tags]": params?.tags }),
39-
...(params?.include && { "include": params?.include }),
53+
...(params?.customerId && {"filter[customerId]": params?.customerId}),
54+
...(params?.tags && {"filter[tags]": params?.tags}),
55+
...(params?.include && {"include": params?.include}),
4056
}
4157

42-
return this.httpGet<UnitResponse<Account[]> & Include<Customer[]>>("", { params: parameters })
58+
return this.httpGet<UnitResponse<Account[]> & Include<Customer[]>>("", {params: parameters})
4359
}
4460

4561
public async update(request: PatchAccountRequest): Promise<UnitResponse<Account>> {
46-
return this.httpPatch<UnitResponse<Account>>(`/${request.accountId}`, { data: request.data })
62+
return this.httpPatch<UnitResponse<Account>>(`/${request.accountId}`, {data: request.data})
4763
}
4864

4965
public async limits(accountId: string): Promise<UnitResponse<AccountLimits>> {

types/account.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,20 @@ export interface CreateBatchAccountRequest {
184184
}
185185
}
186186

187+
export type FreezeAccountRequest = FreezeDepositAccountRequest
188+
189+
export interface FreezeDepositAccountRequest {
190+
accountId: string
191+
192+
data: {
193+
type: "accountFreeze"
194+
attributes: {
195+
reason: "Fraud" | "Other"
196+
reasonText?: string
197+
}
198+
}
199+
}
200+
187201
export interface AccountLimits {
188202
type: "limits"
189203
attributes: {

0 commit comments

Comments
 (0)