Skip to content

Commit

Permalink
Removed simple data / loading from useMethod and added useSimpleMetho…
Browse files Browse the repository at this point in the history
…d hook
  • Loading branch information
hide-on-bush-x committed May 13, 2022
1 parent 9f65b38 commit ead5cd4
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@masa-finance/tools",
"version": "0.1.17",
"version": "0.1.20",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
44 changes: 30 additions & 14 deletions src/common/helpers/rest-calls/index.ts
Expand Up @@ -39,11 +39,34 @@ export const useRestCall = ({
data: body,
});

const {
data: simpleData,
error: simpleError,
loading: simpleLoading,
} = useAxios({
return {
data,
error,
loading: loading || isLoading,
getData,
};
};

export const useSimpleRestCall = ({
pathParameters,
metadata,
headers,
body,
}: RestCallProps) => {
const fullPath = useMemo(() => {
let newPath = metadata.name;
if (pathParameters) {
Object.keys(pathParameters).forEach((key) => {
//@ts-ignore
newPath = newPath.replace(':' + key, [pathParameters[key]]);
});
}
return newPath;
}, [pathParameters]);

const { token, isLoading } = useToken();

const axiosData = useAxios({
url: token ? `${URL}${fullPath}` : undefined,
headers: {
...headers,
Expand All @@ -52,13 +75,6 @@ export const useRestCall = ({
method: metadata.method,
data: body,
});
return {
data,
error,
loading: loading || isLoading,
getData,
simpleData,
simpleLoading,
simpleError,
};

return { ...axiosData, loading: axiosData.loading || isLoading};
};
29 changes: 20 additions & 9 deletions src/common/rest/plaid/list-plaid-accounts/index.ts
@@ -1,18 +1,29 @@
import { MethodMetadata, Parameter } from '../..';
import { useRestCall } from '../../../helpers/rest-calls';
import { useRestCall, useSimpleRestCall } from '../../../helpers/rest-calls';
import { Headers } from '../../../helpers/axios';

const path = 'plaid-accounts/:userId';

export function useMethod({ pathParameters, body }: any) {
const { data, error, loading, getData, simpleData, simpleLoading } =
useRestCall({
pathParameters,
headers: Headers,
body,
metadata,
});
return { data, error, loading, getData, simpleData, simpleLoading };
const { data, error, loading, getData } = useRestCall({
pathParameters,
headers: Headers,
body,
metadata,
});

return { data, error, loading, getData };
}

export function useSimpleMethod({ pathParameters, body }: any) {
const simpleCall = useSimpleRestCall({
pathParameters,
headers: Headers,
body,
metadata,
});

return simpleCall;
}

const parameters: Parameter[] = [
Expand Down
17 changes: 14 additions & 3 deletions src/common/rest/plaid/list-plaid-transactions/index.ts
@@ -1,18 +1,29 @@
import { MethodMetadata, Parameter } from '../..';
import { useRestCall } from '../../../helpers/rest-calls';
import { useRestCall, useSimpleRestCall } from '../../../helpers/rest-calls';
import { Headers } from '../../../helpers/axios';

const path =
'plaid-transactions/:accountId/?pageNbr=:pageNbr&pageSize=:pageSize';

export function useMethod({ pathParameters, body }: any) {
const { data, error, loading, getData, simpleData, simpleLoading } = useRestCall({
const { data, error, loading, getData } = useRestCall({
pathParameters,
headers: Headers,
body,
metadata,
});
return { data, error, loading, getData, simpleLoading, simpleData };
return { data, error, loading, getData };
}

export function useSimpleMethod({ pathParameters, body }: any) {
const simpleCall = useSimpleRestCall({
pathParameters,
headers: Headers,
body,
metadata,
});

return simpleCall;
}

const parameters: Parameter[] = [
Expand Down
12 changes: 11 additions & 1 deletion src/common/rest/vezgo/list-accounts/index.ts
@@ -1,6 +1,6 @@
import { MethodMetadata, Parameter } from '../..';
import { Headers } from '../../../helpers/axios';
import { useRestCall } from '../../../helpers/rest-calls';
import { useRestCall, useSimpleRestCall } from '../../../helpers/rest-calls';

const path = 'vezgo-accounts/:userId';

Expand All @@ -14,6 +14,16 @@ export function useMethod({ pathParameters, body }: any) {
return { data, error, loading, getData };
}

export function useSimpleMethod({ pathParameters, body }: any) {
const simpleCall = useSimpleRestCall({
pathParameters,
headers: Headers,
body,
metadata,
});

return simpleCall;
}
const parameters: Parameter[] = [
{
key: 1,
Expand Down

0 comments on commit ead5cd4

Please sign in to comment.