Skip to content
Merged
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
8 changes: 8 additions & 0 deletions pages/containers/Authenticated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import SignIn from './SignIn';
import { AuthenticatedData } from '../utils';
import GetCompanyProfile from '../features/GetCompanyProfile';
import GetBankAccounts from '../features/GetBankAccounts';
import GetBankAccountById from '../features/GetBankAccountById';
import GetTransactions from '../features/GetTransactions';
import GetTransactionById from '../features/GetTransactionById';
import GetReceiptForTransaction from '../features/GetReceiptForTransaction';
Expand Down Expand Up @@ -97,6 +98,13 @@ function Authenticated({ authenticatedData }: { authenticatedData: Authenticated
authenticatedData={authenticatedData}
/>
</Menu>
<Menu>
<GetBankAccountById
setOperationOutput={setOperationOutput}
setError={setError}
authenticatedData={authenticatedData}
/>
</Menu>

<StyledSidebarHeader>Transactions </StyledSidebarHeader>
<Menu>
Expand Down
37 changes: 37 additions & 0 deletions pages/features/GetBankAccountById.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { useCallback, useState } from 'react';
import Button from '../components/Button';
import axios, { AxiosError } from 'axios';
import { FeatureParams, SContainer, SInput, stringifyResponse } from '../utils';

function GetBankAccountById({ authenticatedData, setOperationOutput, setError }: FeatureParams) {
const [bankAccountId, setBankAccountId] = useState('');

const getBankAccountById = useCallback(() => {
setError(null);
axios
.get('/bank-account-by-id', {
params: {
bankAccountId,
access_token: authenticatedData.access_token, // in real world scenario, this should be stored in a your backend
},
})
.then((result) => setOperationOutput(stringifyResponse(result.data)))
.catch((err: AxiosError) => setError(stringifyResponse(err.response.data)));
}, [setError, setOperationOutput, authenticatedData, bankAccountId]);

return (
<SContainer>
<SInput
value={bankAccountId}
onChange={(e) => setBankAccountId(e.target.value)}
type="text"
placeholder="Bank account id"
size={40}
/>

<Button key="bank-account-by-id" text="Get bank account by Id " onClick={getBankAccountById} />
</SContainer>
);
}

export default GetBankAccountById;
2 changes: 2 additions & 0 deletions server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import callback from './callback';
import getUserProfile from './routes/userProfile';
import getCompanyProfile from './routes/companyProfile';
import getBankAccounts from './routes/bankAccounts';
import getBankAccountById from './routes/bankAccountById';
import getTransactions from './routes/transactions';
import getTransactionById from './routes/transactionById';
import getReceiptForTransaction from './routes/receiptForTransaction';
Expand Down Expand Up @@ -46,6 +47,7 @@ app.prepare().then(() => {
server.get('/user-profile', getUserProfile);
server.get('/company-profile', getCompanyProfile);
server.get('/bank-accounts', getBankAccounts);
server.get('/bank-account-by-id', getBankAccountById);
server.get('/bank-transfers', getBankTransfers);
server.get('/bank-transfer-by-id', getBankTransferById);
server.get('/transactions', getTransactions);
Expand Down
22 changes: 22 additions & 0 deletions server/routes/bankAccountById.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Request, Response } from 'express';
import { shineRequest } from '../request';

const getBankAccountById = async (req: Request, res: Response) => {
const { access_token, bankAccountId } = req.query;

try {
const data = await shineRequest({
method: 'GET',
path: `/bank/accounts/${bankAccountId}`,
authorization: access_token as string,
});
res.status(200).send(data);
} catch (error) {
res.status(error.status).send({
status: error.status,
message: error.body.message,
});
}
};

export default getBankAccountById;