|
| 1 | +import { Account, Customer, Transaction } from "../types" |
| 2 | +import { CheckDeposit, CreateCheckDepositRequest, PatchCheckDepositRequest, UploadCheckDepositRequest } from "../types/checkDeposit" |
| 3 | +import { UnitResponse, Include, UnitConfig } from "../types/common" |
| 4 | +import { BaseResource } from "./baseResource" |
| 5 | + |
| 6 | +export class CheckDeposits extends BaseResource { |
| 7 | + |
| 8 | + constructor(token: string, basePath: string, config?: UnitConfig) { |
| 9 | + super(token, basePath + "/check-deposits", config) |
| 10 | + } |
| 11 | + |
| 12 | + public async list(params?: CheckDepositListParams): Promise<UnitResponse<CheckDeposit[]>> { |
| 13 | + const parameters = { |
| 14 | + "page[limit]": (params?.limit ? params.limit : 100), |
| 15 | + "page[offset]": (params?.offset ? params.offset : 0), |
| 16 | + ...(params?.accountId && { "filter[accountId]": params.accountId }), |
| 17 | + ...(params?.customerId && { "filter[customerId]": params.customerId }), |
| 18 | + ...(params?.tags && { "filter[tags]": params.tags }), |
| 19 | + "sort": params?.sort ? params.sort : "-createdAt", |
| 20 | + "include": params?.include ? params.include : "include" |
| 21 | + } |
| 22 | + |
| 23 | + return this.httpGet<UnitResponse<CheckDeposit[]>>("", { params: parameters }) |
| 24 | + } |
| 25 | + |
| 26 | + public async create(request: CreateCheckDepositRequest): Promise<UnitResponse<CheckDeposit>> { |
| 27 | + return this.httpPost<UnitResponse<CheckDeposit>>("", { data: request }) |
| 28 | + } |
| 29 | + |
| 30 | + public async get(id: string, include = ""): Promise<UnitResponse<CheckDeposit> & Include<(Customer | Account | Transaction)[]>> { |
| 31 | + return this.httpGet<UnitResponse<CheckDeposit> & Include<(Customer | Account | Transaction)[]>>(`/${id}`, { params: { include }}) |
| 32 | + } |
| 33 | + |
| 34 | + public async update(request: PatchCheckDepositRequest): Promise<UnitResponse<CheckDeposit>> { |
| 35 | + return this.httpPatch<UnitResponse<CheckDeposit>>(`/${request.checkDepositId}`, { data: request.data }) |
| 36 | + } |
| 37 | + |
| 38 | + public async upload(request: UploadCheckDepositRequest) : Promise<UnitResponse<CheckDeposit>> { |
| 39 | + |
| 40 | + let path = `/${request.checkDepositId}` |
| 41 | + if (request.isBackSide) |
| 42 | + path += "/back" |
| 43 | + |
| 44 | + const headers = { "Content-Type": "image/jpeg" } |
| 45 | + |
| 46 | + return this.httpPut<UnitResponse<CheckDeposit>>(path, request.file, {headers}) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +export interface CheckDepositListParams { |
| 51 | + /** |
| 52 | + * Maximum number of resources that will be returned. Maximum is 1000 resources. [See Pagination](https://developers.unit.co/#intro-pagination). |
| 53 | + * default: 100 |
| 54 | + */ |
| 55 | + limit?: number |
| 56 | + |
| 57 | + /** |
| 58 | + * Number of resources to skip. [See Pagination](https://developers.unit.co/#intro-pagination). |
| 59 | + * default: 0 |
| 60 | + */ |
| 61 | + offset?: number |
| 62 | + |
| 63 | + /** |
| 64 | + * Optional. Filters the results by the specified account id. |
| 65 | + * default: empty |
| 66 | + */ |
| 67 | + accountId?: string |
| 68 | + |
| 69 | + /** |
| 70 | + * Optional. Filters the results by the specified customer id. |
| 71 | + * default: empty |
| 72 | + */ |
| 73 | + customerId?: string |
| 74 | + |
| 75 | + /** |
| 76 | + * Optional. Filter Applications by [Tags](https://developers.unit.co/#tags). |
| 77 | + * default: empty |
| 78 | + */ |
| 79 | + tags?: object |
| 80 | + |
| 81 | + /** |
| 82 | + * Optional. Leave empty or provide sort=createdAt for ascending order. Provide sort=-createdAt (leading minus sign) for descending order. |
| 83 | + */ |
| 84 | + sort?: string |
| 85 | + |
| 86 | + /** |
| 87 | + * Optional. Related resource available to include: customer. See [Getting Related Resources](https://developers.unit.co/#intro-getting-related-resources). |
| 88 | + * default: empty |
| 89 | + */ |
| 90 | + include?: string |
| 91 | +} |
0 commit comments