From 64a48484ade15fd9400f208e6ec80af9b8638a53 Mon Sep 17 00:00:00 2001 From: John Shields Date: Tue, 26 Mar 2024 11:57:09 +0000 Subject: [PATCH] PP-11681 Refactor 'axios-base-client' call following code review. --- app/services/clients/ledger.client.js | 47 ++++++++++++--------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/app/services/clients/ledger.client.js b/app/services/clients/ledger.client.js index 5607cebe36..a5605d556d 100644 --- a/app/services/clients/ledger.client.js +++ b/app/services/clients/ledger.client.js @@ -20,15 +20,16 @@ const defaultOptions = { limit_total: true } +const client = new Client(defaultOptions.service) + const transaction = async function transaction (id, gatewayAccountId, options = {}) { - this.client = new Client(defaultOptions.service) const baseUrl = options.baseUrl ? options.baseUrl : defaultOptions.baseUrl let url = `${baseUrl}/v1/transaction/${id}?account_id=${gatewayAccountId}` if ( options.transaction_type ) { url = `${url}&transaction_type=${options.transaction_type}` } - configureClient(this.client, url) - const response = await this.client.get(url, 'Get individual transaction details') + configureClient(client, url) + const response = await client.get(url, 'Get individual transaction details') const body = legacyConnectorTransactionParity(response.data) return body } @@ -36,30 +37,27 @@ const transaction = async function transaction (id, gatewayAccountId, options = const transactionWithAccountOverride = async function transactionWithAccountOverride (id, options = {}) { const baseUrl = options.baseUrl ? options.baseUrl : defaultOptions.baseUrl const url = urlJoin(baseUrl,'/v1/transaction', id) - this.client = new Client(defaultOptions.service) const fullUrl = `${url}?override_account_id_restriction=true` - configureClient(this.client, fullUrl) - const response = await this.client.get(fullUrl, 'Get individual transaction details with no accountId restriction') + configureClient(client, fullUrl) + const response = await client.get(fullUrl, 'Get individual transaction details with no accountId restriction') return response.data } async function getDisputesForTransaction (id, gatewayAccountId, options = {}) { const baseUrl = options.baseUrl ? options.baseUrl : defaultOptions.baseUrl const url = urlJoin(baseUrl,'/v1/transaction', id, 'transaction') - this.client = new Client(defaultOptions.service) const fullUrl = `${url}?gateway_account_id=${gatewayAccountId}&transaction_type=DISPUTE` - configureClient(this.client, fullUrl) - const response = await this.client.get(fullUrl, 'Get disputes for payment') + configureClient(client, fullUrl) + const response = await client.get(fullUrl, 'Get disputes for payment') return response.data } const events = async function events (transactionId, gatewayAccountId, options = {}) { const baseUrl = options.baseUrl ? options.baseUrl : defaultOptions.baseUrl const url = urlJoin(baseUrl,'/v1/transaction', transactionId, 'event') - this.client = new Client(defaultOptions.service) const fullUrl = `${url}?gateway_account_id=${gatewayAccountId}` - configureClient(this.client, fullUrl) - const response = await this.client.get(fullUrl, 'List events for a given transaction') + configureClient(client, fullUrl) + const response = await client.get(fullUrl, 'List events for a given transaction') const body = legacyConnectorEventsParity(response.data) return body } @@ -77,9 +75,8 @@ const transactions = async function transactions (gatewayAccountIds = [], filter const formattedFilterParams = getQueryStringForParams(filters, true, true) const baseUrl = options.baseUrl ? options.baseUrl : defaultOptions.baseUrl const url = `${baseUrl}${path}?${formattedParams}&${formattedFilterParams}` - this.client = new Client(defaultOptions.service) - configureClient(this.client, url) - const response = await this.client.get( + configureClient(client, url) + const response = await client.get( url, 'List transactions for a given gateway account ID', { @@ -98,9 +95,8 @@ const transactionSummary = async function transactionSummary (gatewayAccountId, const path = '/v1/report/transactions-summary' const baseUrl = options.baseUrl ? options.baseUrl : defaultOptions.baseUrl const url = `${baseUrl}${path}?account_id=${gatewayAccountId}&from_date=${fromDate}&to_date=${toDate}` - this.client = new Client(defaultOptions.service) - configureClient(this.client, url) - const response = await this.client.get(url,'Transaction summary statistics for a given gateway account ID') + configureClient(client, url) + const response = await client.get(url,'Transaction summary statistics for a given gateway account ID') const body = legacyConnectorTransactionSummaryParity(response.data) return body } @@ -111,9 +107,8 @@ const payouts = async function payouts (gatewayAccountIds = [], page = 1, displa if ( displaySize ) { url = `${url}&display_size=${displaySize}` } - this.client = new Client(defaultOptions.service) - configureClient(this.client, url) - const response = await this.client.get(url,'List payouts for a given gateway account ID') + configureClient(client, url) + const response = await client.get(url,'List payouts for a given gateway account ID') return response.data } @@ -130,18 +125,16 @@ const agreements = async function agreements (serviceId, live, accountId, page = const filterParams = new URLSearchParams(options.filters).toString() url = `${url}&${filterParams}` } - this.client = new Client(defaultOptions.service) - configureClient(this.client, url) - const response = await this.client.get(url,'List agreements for a given service and environment') + configureClient(client, url) + const response = await client.get(url,'List agreements for a given service and environment') return response.data } const agreement = async function agreement (id, serviceId, options = {}) { const baseUrl = options.baseUrl ? options.baseUrl : defaultOptions.baseUrl let url = `${baseUrl}/v1/agreement/${id}?service_id=${serviceId}` - this.client = new Client(defaultOptions.service) - configureClient(this.client, url) - const response = await this.client.get(url,'Get agreement by ID') + configureClient(client, url) + const response = await client.get(url,'Get agreement by ID') return response.data }