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

@@ -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 !== ''),
)
}