diff --git a/examples/regular-transactions/detect-regular-transactions.js b/examples/regular-transactions/detect-regular-transactions.js new file mode 100644 index 0000000..0041a16 --- /dev/null +++ b/examples/regular-transactions/detect-regular-transactions.js @@ -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() diff --git a/src/__tests__/index.ts b/src/__tests__/index.ts index b62604f..0b2efa8 100644 --- a/src/__tests__/index.ts +++ b/src/__tests__/index.ts @@ -98,6 +98,7 @@ describe("API client", () => { "getStandingOrder", "getStandingOrders", "getRegularTransactions", + "detectRegularTransactions", "getRentalRecords", "createRentalRecord", "deleteRentalRecord", diff --git a/src/__tests__/regular-transactions.ts b/src/__tests__/regular-transactions.ts index 639e25f..0725a3a 100644 --- a/src/__tests__/regular-transactions.ts +++ b/src/__tests__/regular-transactions.ts @@ -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 @@ -20,4 +22,10 @@ describe.skip("Regular transactions", () => { expectTypeOf(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(data) + }) }) diff --git a/src/requests/regular-transactions.ts b/src/requests/regular-transactions.ts index c980848..73da069 100644 --- a/src/requests/regular-transactions.ts +++ b/src/requests/regular-transactions.ts @@ -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> => request( `${resourceServerUrl}/regular-transactions`, { @@ -16,5 +19,19 @@ export default ({config, request}: RequestsParams): RegularTransactionsRequests }, }, ), + detectRegularTransactions: async ({userId, accountId}: { + userId: string + accountId: string + }): Promise> => + request( + `${resourceServerUrl}/regular-transactions/${accountId}/detect`, + { + cc: { + scope: "accounts:read regular_transactions:read regular_transactions:write transactions:read:all", + sub: userId, + }, + method: "POST", + }, + ), } } diff --git a/src/requests/types/regular-transactions.ts b/src/requests/types/regular-transactions.ts deleted file mode 100644 index b4816b6..0000000 --- a/src/requests/types/regular-transactions.ts +++ /dev/null @@ -1,12 +0,0 @@ -import {ApiResponse} from "src/request" -import {RegularTransaction, RegularTransactionSearchParams} from "src/schema/regular-transaction" - -export interface RegularTransactionsRequests { - getRegularTransactions: ({ - userId, - params, - }: { - userId: string - params?: RegularTransactionSearchParams - }) => Promise> -}