Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regular transaction detect route #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions examples/regular-transactions/detect-regular-transactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const commandLineArgs = require("command-line-args")
const commandLineUsage = require("command-line-usage")
const {Moneyhub} = require("../../src/index")
const config = require("../config")

const optionDefinitions = [
{name: "userId", alias: "u", type: String, description: "required"},
{name: "accountId", alias: "a", type: String, description: "required"},
]

const usage = commandLineUsage(
{
header: "Options",
optionList: optionDefinitions,
}
)
console.log(usage)

const options = commandLineArgs(optionDefinitions)

const start = async () => {
try {
const moneyhub = await Moneyhub(config)

const result = await moneyhub.detectRegularTransactions({
userId: options.userId,
accountId: options.accountId,
})
console.log(JSON.stringify(result, null, 2))
} catch (e) {
console.log(e)
}
}

start()
1 change: 1 addition & 0 deletions src/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ describe("API client", () => {
"getStandingOrder",
"getStandingOrders",
"getRegularTransactions",
"detectRegularTransactions",
"getRentalRecords",
"createRentalRecord",
"deleteRentalRecord",
Expand Down
8 changes: 8 additions & 0 deletions src/__tests__/regular-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {expectTypeOf} from "expect-type"

import {Moneyhub, MoneyhubInstance, RegularTransactions} from ".."

const accountId = "accountId"

describe.skip("Regular transactions", () => {
let moneyhub: MoneyhubInstance
let userId: string
Expand All @@ -20,4 +22,10 @@ describe.skip("Regular transactions", () => {
expectTypeOf<RegularTransactions.RegularTransaction[]>(data)
})

it("detect regular transactions", async () => {
const {data} = await moneyhub.detectRegularTransactions({userId, accountId})
expect(data.length).to.be.above(0)
expect(data[0]).to.have.property("seriesId")
expectTypeOf<RegularTransactions.RegularTransaction[]>(data)
})
})
25 changes: 21 additions & 4 deletions src/requests/regular-transactions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import {RequestsParams} from "src/request"
import {RegularTransactionsRequests} from "./types/regular-transactions"
import {ApiResponse, RequestsParams} from "src/request"
import {RegularTransaction, RegularTransactionSearchParams} from "src/schema/regular-transaction"

export default ({config, request}: RequestsParams): RegularTransactionsRequests => {
export default ({config, request}: RequestsParams) => {
const {resourceServerUrl} = config

return {
getRegularTransactions: async ({userId, params}) =>
getRegularTransactions: async ({userId, params}: {
userId: string
params?: RegularTransactionSearchParams
}): Promise<ApiResponse<RegularTransaction[]>> =>
request(
`${resourceServerUrl}/regular-transactions`,
{
Expand All @@ -16,5 +19,19 @@ export default ({config, request}: RequestsParams): RegularTransactionsRequests
},
},
),
detectRegularTransactions: async ({userId, accountId}: {
userId: string
accountId: string
}): Promise<ApiResponse<RegularTransaction[]>> =>
request(
`${resourceServerUrl}/regular-transactions/${accountId}/detect`,
{
cc: {
scope: "accounts:read regular_transactions:read regular_transactions:write transactions:read:all",
sub: userId,
},
method: "POST",
},
),
}
}
12 changes: 0 additions & 12 deletions src/requests/types/regular-transactions.ts

This file was deleted.