forked from RiseUP/riseup-squad21
Compare commits
5 Commits
accb64ca5e
...
8bb2c4997b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8bb2c4997b | ||
| c4ae9c6789 | |||
| 0d2116815d | |||
| fa175d4555 | |||
|
|
b2eea0de6a |
6
package-lock.json
generated
6
package-lock.json
generated
@ -46,11 +46,11 @@
|
||||
"geist": "^1.3.1",
|
||||
"input-otp": "1.4.1",
|
||||
"lucide-react": "^0.454.0",
|
||||
"next": "14.2.16",
|
||||
"next": "^14.2.16",
|
||||
"next-themes": "^0.4.6",
|
||||
"react": "^18",
|
||||
"react": "^18.3.1",
|
||||
"react-day-picker": "9.8.0",
|
||||
"react-dom": "^18",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-hook-form": "^7.60.0",
|
||||
"react-resizable-panels": "^2.1.7",
|
||||
"recharts": "2.15.4",
|
||||
|
||||
@ -47,11 +47,11 @@
|
||||
"geist": "^1.3.1",
|
||||
"input-otp": "1.4.1",
|
||||
"lucide-react": "^0.454.0",
|
||||
"next": "14.2.16",
|
||||
"next": "^14.2.16",
|
||||
"next-themes": "^0.4.6",
|
||||
"react": "^18",
|
||||
"react": "^18.3.1",
|
||||
"react-day-picker": "9.8.0",
|
||||
"react-dom": "^18",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-hook-form": "^7.60.0",
|
||||
"react-resizable-panels": "^2.1.7",
|
||||
"recharts": "2.15.4",
|
||||
|
||||
64
services/api.mjs
Normal file
64
services/api.mjs
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
// váriaveis básicas
|
||||
const BASE_URL = "https://yuanqfswhberkoevtmfr.supabase.co";
|
||||
const API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inl1YW5xZnN3aGJlcmtvZXZ0bWZyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTQ5NTQzNjksImV4cCI6MjA3MDUzMDM2OX0.g8Fm4XAvtX46zifBZnYVH4tVuQkqUH6Ia9CXQj4DztQ";
|
||||
var tempToken;
|
||||
|
||||
async function login() {
|
||||
const response = await fetch("https://yuanqfswhberkoevtmfr.supabase.co/auth/v1/token?grant_type=password", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"apikey": API_KEY, // valor fixo
|
||||
},
|
||||
body: JSON.stringify({ email: "hugo@popcode.com.br", password: "hdoria" }),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
console.log("Resposta da API:", data);
|
||||
console.log("Token:", data.access_token);
|
||||
// salvar o token do usuário
|
||||
//localStorage.setItem("token", data.access_token);
|
||||
tempToken = data.access_token
|
||||
|
||||
return data;
|
||||
}
|
||||
await login()
|
||||
|
||||
async function request(endpoint, options = {}) {
|
||||
//const token = localStorage.getItem("token"); // token do usuário, salvo no login
|
||||
const token = tempToken;
|
||||
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
"apikey": API_KEY, // obrigatório sempre
|
||||
...(token ? { Authorization: `Bearer ${token}` } : {}), // obrigatório em todas EXCETO login
|
||||
...options.headers,
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch(`${BASE_URL}${endpoint}`, {
|
||||
...options,
|
||||
headers,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Erro HTTP: ${response.status}`);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error("Erro na requisição:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export const api = {
|
||||
get: (endpoint) => request(endpoint, { method: "GET" }),
|
||||
post: (endpoint, body) =>
|
||||
request(endpoint, { method: "POST", body: JSON.stringify(body) }),
|
||||
patch: (endpoint, body) =>
|
||||
request(endpoint, { method: "PATCH", body: JSON.stringify(body) }),
|
||||
delete: (endpoint) => request(endpoint, { method: "DELETE" }),
|
||||
};
|
||||
0
services/doctorsApi.mjs
Normal file
0
services/doctorsApi.mjs
Normal file
9
services/patientsApi.mjs
Normal file
9
services/patientsApi.mjs
Normal file
@ -0,0 +1,9 @@
|
||||
import { api } from "./api.mjs";
|
||||
|
||||
export const patientsService = {
|
||||
list: () => api.get("/rest/v1/patients"),
|
||||
getById: (id) => api.get(`/rest/v1/patients/${id}`),
|
||||
create: (data) => api.post("/rest/v1/patients", data),
|
||||
update: (id, data) => api.patch(`/rest/v1/patients/${id}`, data),
|
||||
delete: (id) => api.delete(`/rest/v1/patients/${id}`),
|
||||
};
|
||||
@ -1,25 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"target": "ES6",
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./*"]
|
||||
"plugins": [{ "name": "next" }],
|
||||
"baseUrl": ".", // adiciona esta linha
|
||||
"paths": { // adiciona esta linha
|
||||
"@/*": ["./*"] // e esta linha
|
||||
}
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user