modified: docs/repository-api-audit.md

modified:   src/repositories/authRepository.js
modified:   src/repositories/patientRepository.js
modified:   src/repositories/professionalRepository.js
modified:   src/repositories/profileRepository.js
modified:   src/repositories/userRepository.js
This commit is contained in:
2026-05-11 13:24:29 -03:00
parent fba021e048
commit 04a13c24d3
6 changed files with 152 additions and 38 deletions

View File

@@ -60,6 +60,20 @@ export const authRepository = {
return true
},
async sendMagicLink(email) {
const response = await fetch(`${apiConfig.supabaseUrl}/auth/v1/otp`, {
method: 'POST',
headers: getAnonHeaders(),
body: JSON.stringify({ email: email?.trim() }),
})
if (!response.ok) {
throw new Error(await getResponseError(response, 'Erro ao enviar Magic Link.'))
}
return true
},
async getUser() {
const apiResponse = await fetch(`${apiConfig.functionsUrl.replace(/\/+$/, '')}/user-info`, {
method: 'POST',

View File

@@ -1,4 +1,4 @@
import { apiConfig, getAuthenticatedHeaders } from '../config/api.js'
import { apiConfig, getAnonHeaders, getAuthenticatedHeaders } from '../config/api.js'
import { getResponseError } from './repositoryUtils.js'
export const patientRepository = {
@@ -83,6 +83,29 @@ export const patientRepository = {
return response.json()
},
async registerPublic(data) {
const body = cleanPayload({
full_name: data.name || data.full_name,
cpf: data.cpf,
email: data.email,
phone_mobile: data.phone || data.phone_mobile,
birth_date: data.birthDate || data.birth_date || null,
redirect_url: data.redirectUrl || data.redirect_url,
})
const response = await fetch(`${apiConfig.functionsUrl}/register-patient`, {
method: 'POST',
headers: getAnonHeaders(),
body: JSON.stringify(body),
})
if (!response.ok) {
throw new Error(await getResponseError(response, 'Erro ao realizar auto-cadastro de paciente.'))
}
return response.json()
},
// 4. Atualizar paciente
async update(patientId, data) {
const body = {
@@ -325,3 +348,9 @@ function calculateAge(birthDate) {
return age
}
function cleanPayload(payload) {
return Object.fromEntries(
Object.entries(payload).filter(([, value]) => value !== undefined && value !== null && value !== ''),
)
}

View File

@@ -1,4 +1,5 @@
import { apiConfig, getAuthenticatedHeaders } from '../config/api.js'
import { getResponseError, normalizeItem } from './repositoryUtils.js'
export const professionalRepository = {
async getAll() {
@@ -12,6 +13,29 @@ export const professionalRepository = {
return (Array.isArray(data) ? data : []).map(mapProfessional)
},
async create(data) {
const response = await fetch(`${apiConfig.functionsUrl}/create-doctor`, {
method: 'POST',
headers: getAuthenticatedHeaders(),
body: JSON.stringify(cleanPayload({
full_name: data.fullName || data.full_name || data.name,
email: data.email,
cpf: data.cpf,
crm: data.crm,
crm_uf: data.crmUf || data.crm_uf,
phone_mobile: data.phoneMobile || data.phone_mobile || data.phone,
specialty: data.specialty || data.specialidade,
birth_date: data.birthDate || data.birth_date,
})),
})
if (!response.ok) {
throw new Error(await getResponseError(response, 'Erro ao criar m?dico.'))
}
return mapProfessional(normalizeItem(await response.json(), ['doctor']))
},
getCoverageMap() {
return {
slots: ['08-12', '09-13', '10-15', '13-18', '08-14'],
@@ -52,3 +76,9 @@ function mapProfessional(doctor) {
function normalizeValue(value) {
return String(value || '').trim().toLowerCase()
}
function cleanPayload(payload) {
return Object.fromEntries(
Object.entries(payload).filter(([, value]) => value !== undefined && value !== null && value !== ''),
)
}

View File

@@ -84,6 +84,24 @@ export const profileRepository = {
path: objectPath,
}
},
async downloadAvatar(path) {
const objectPath = String(path || '').replace(/^\/+/, '')
const response = await fetch(`${apiConfig.storageUrl}/object/avatars/${objectPath}`, {
method: 'GET',
headers: getAuthenticatedHeaders({ 'Content-Type': undefined }),
})
if (!response.ok) {
throw new Error(await getResponseError(response, 'Falha ao baixar avatar.'))
}
return {
blob: await response.blob(),
contentType: response.headers.get('content-type') || 'application/octet-stream',
path: objectPath,
}
},
}
function normalizeAvatarResponse(data) {

View File

@@ -33,10 +33,9 @@ export const userRepository = {
},
async getById(userId) {
const response = await fetch(`${apiConfig.functionsUrl}/user-info-by-id`, {
const response = await fetch(`${apiConfig.functionsUrl}/user-info-by-id/${encodeURIComponent(userId)}`, {
method: 'POST',
headers: getAuthenticatedHeaders(),
body: JSON.stringify({ user_id: userId }),
})
if (!response.ok) {
@@ -83,7 +82,7 @@ export const userRepository = {
const response = await fetch(`${apiConfig.functionsUrl}/delete-user`, {
method: 'POST',
headers: getAuthenticatedHeaders(),
body: JSON.stringify({ user_id: userId }),
body: JSON.stringify({ userId, user_id: userId }),
})
if (!response.ok) {