Skip to content

Commit

Permalink
Merge pull request #11 from fga-eps-mds/integrations
Browse files Browse the repository at this point in the history
feat: create the integration with other services back-end
  • Loading branch information
mateusmaiamaia authored Feb 5, 2025
2 parents ef7e09c + db0c85e commit 85cc38a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VITE_API_BASE_URL=http://localhost:3000
VITE_API_BOOKS_URL=http://localhost:3001
VITE_API_RENTALS_URL=http://localhost:3003
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
VITE_API_BASE_URL=http://localhost:3000
VITE_API_BOOKS_URL=http://localhost:3001
VITE_API_RENTALS_URL=http://localhost:3003
2 changes: 2 additions & 0 deletions src/config/environment.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;
export const API_BOOKS_URL = import.meta.env.VITE_API_BOOKS_URL;
export const API_RENTALS_URL = import.meta.env.VITE_API_RENTALS_URL;
13 changes: 8 additions & 5 deletions src/hooks/useApi/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from "axios";
import { useMemo } from "react"
import { API_BASE_URL } from "../../config/environment";
import { API_BASE_URL, API_BOOKS_URL, API_RENTALS_URL } from "../../config/environment";
import { User } from "../../interfaces/user";

const createApiInstance = (url: string) => {
Expand All @@ -22,8 +22,11 @@ const getDefaultErrorUseAPIMessage = (err: any) => {

const useApi = () => {
const api = useMemo(
() =>
createApiInstance(API_BASE_URL),
() => ({
base: createApiInstance(API_BASE_URL),
books: createApiInstance(API_BOOKS_URL),
rentals: createApiInstance(API_RENTALS_URL),
}),
[],
);

Expand All @@ -36,7 +39,7 @@ const useApi = () => {
refreshToken: string;
} }> => {
return new Promise((resolve) => {
api
api.base
.post('/auth/signin', {
...data,
role: 'admin',
Expand All @@ -53,7 +56,7 @@ const useApi = () => {
total: number,
} }> => {
return new Promise((resolve) => {
api
api.base
.get('/users', {
params: {
perPage: data.perPage,
Expand Down

0 comments on commit 85cc38a

Please sign in to comment.